Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Ray tracing project for 42 school, Codam.

License

NotificationsYou must be signed in to change notification settings

gmzorz/MiniRT

Repository files navigation

Graphics project for Codam / 42 school, my first ray tracer using MinilibX.

Project goal:

The goal of your program is to generate imagesusing the Raytracing protocol. Those computer generated images will each represent a scene, as seen from a specific angle and position, defined by simple geometric objects, and each with its own lighting system.

Project Grade: 115/100

About

The mandatory part of the project requires you to code a classic one-ray-per-pixel style ray tracer. However for the bonus part of MiniRT i implemented aBRDF rendering equation to render more realistic looking scenes. This includes Global illumination, roughness materials, soft shadows and depth of field sampling. Another neat little feature is the rendering of complex.obj triangle meshes, using a BVH acceleration structure. Other fun things include material loading on top of the standard 8bit color defines.

MiniRT uses MinilibX, a small graphics library that allows for simple window management and putting pixels to the screen.The program can render the following shapes and scene elements using their respective identifiers:

Mandatory:
  • R - Window resolution
  • A - Ambient lighting
  • l - Point light
  • c - Camera
  • pl - Plane
  • sp - Sphere
  • cy - Cylinder (non-capped)
  • sq - Square
  • tr - Triangle
Bonus:
  • SKY - Skybox loading
  • SUN - Sun rendering (emission BRDF only)
  • THREADS - Multithreaded rendering (BRDF only)
  • AA - Anti aliasing (Classic shading only), option to accelerate
  • VP - Viewport resolution (downscaling for faster debugging)
  • cb - Cube (6 squares)
  • py - Pyramid (One square, four triangles)
  • ds - Disk
  • cyc - Capped cylinders
  • obj - Triangle mesh
  • lp - Parallel light (fixed direction)

More about these identifiers can be found in thescenes directory

Bonuses handled (15):

  • Normal disruption using sine over UV coordinates
  • Color disruption: checkerboard pattern
  • Color disruption: rainbow effect using object's normal
  • Parallel light following a precise dirxection
  • Compound element: Cube (six squares)
  • Compound element: Pyramid (four triangles, one square)
  • Caps on cylinders (disks)
  • One color filter: Gamma correction & Sobel edge detection
  • Anti Aliasing
  • Multithreaded rendering
  • Sphere texturing: uv mapping (fixed to work with all shapes)
  • Handle bump map textures (Normal map)
  • A beautiful skybox
  • Keyboard interactivity (translation/rotation) with the camera
  • Keyboard interactivity (translation/rotation) with shapes

Compiling

runningmake will compile the mandatory part,make bonus will overwrite and add the bonus.make clean ormake fclean can be used to wipe binaries

Usage

Run using:./MiniRT path/to/file.rt or./MiniRT path/to/file.rt --save to render and save the image.MiniRT supports files suffixed with the.rt extension. All rules from the PDF apply.The two shell scripts in the root of this directory will run tests (using scenes/../error) to ensure these errors are handled properly.

Scenes

Shapes and elements can be defined in the scene (.rt) files. a simple scene with all elements may look like this:

IDOriginOrientationScaleRadiuswidthHeightColor
R640360
A0.25255,255,255
c0,0,-100,0,165.0
l0,10,100.75255,255,255
pl0,0,00,1,0129,22,255
sp0,1.25,02.5129,22,90
sq-1,4,21,1,-15129,255,90
cy1,2,-2-0.2,0.3,1310129,255,90
tr0,0,0 2,5,0 0,3,-5255,255,255
Bonus scene syntax

Anti aliasing:

IDSamples per pixelSobel accelerate (best on untextured shapes)
AA161

BRDF rendering:

IDSamples per pixel (times four)Scene bouncesSave after rendering (optional)
BRDF164--save

Viewport resolution:

IDValue (full, half, quarter
VPfull

Skybox:

IDPathEmission (brdf only)De-gamma
SKY"textures/sky.xpm"101

Sun (brdf only):

IDDirectionEmissionscale
SUN1,1,0270.4

Multi threading:

IDCount
THREADS4

Wavefront OBJ:

IDPathOriginColor
obj"wavefront/suzanne.obj"0,0,0255,255,255

Shapes & elements:

IDoriginorientationScaleHeightColorMaterial (optional)
ds0,1,00.577,0.577,0.5775.2255,255,255-mat "materials/specular.mat"
cb1,1,10.77,0.77,13255,255,255-mat "materials/cube.mat"
py0,0,0-1,1,-135127,128,127-mat "materials/pyramid.mat"
cyc0,0,00,1,025127,93,220-mat "materials/cylinder_cap.mat"
lp0,10,00,-1,00.3255,255,255

Bonus scenes

Keybinds

Keybinds can be found inkey.c for the mandatory part, orkey_bonus.c for the bonus part. The same goes formouse_bonus.c

key.c
  • Escape - Exit program
  • Enter - Render scene
  • 1 - Render image using flat shading
  • 2 - Render image using unlit colors
  • 3 - Debug bounding volumes
  • Comma - Previous camera
  • Dot - Next camera
key_bonus.c
  • Escape - Exit program
  • Enter - Render scene
  • Space - Render BRDF
  • 1 - Render image using flat shading
  • 2 - Render image using unlit colors
  • 3 - Debug bounding volumes
  • 4 - Debug Normals (Rainbow color bonus)
  • 5 - Debug Units (Checkerboard pattern bonus)
  • 6 - Debug UVs
  • 7 - Debug DOF
  • Comma - Previous camera
  • Dot - Next camera
  • W - Move forward
  • A - Move left
  • S - Move back
  • D - Move right
  • Q - Move down
  • E - Move up
  • J - Pan left
  • K - Pan down
  • I - Pan up
  • L - Pan right
  • U - Roll left
  • O - Roll right
  • T - Translation mode: edit position (if shape is selected)
  • R - Translation mode: edit rotation (if shape is selected)
  • X - Translation axis: X
  • Y - Translation axis: Y
  • Z - Translation axis: Z
  • Up - Translate in the positive direction (if translation axis is set)
  • Down - Translate in the negative direction (if translation axis is set)
  • Plus - Increase FOV
  • Minus - Decrease FOV
  • Shift - Take screenshot
mouse_bonus.c
  • Mouse1 - Select shape
  • Mouse2 - Deselect shape
  • Mouse4 - move the depth of field focal plane forward (BRDF only)
  • Mouse5 - move the depth of field focal plane back (BRDF only)

Debug modes

Left to right: Flat, unlit, normals, units and UVs

Mesh loading

Mesh loading is simple and limited, MiniRT will only parse vertices and triangulated faces. Vertex normals are computed by the program itself.an example of a working .obj file would be:

# www.blender.orgo dragonv -0.090499 -0.115513 -0.093754v -0.090303 -0.116237 -0.093008v -0.090556 -0.115490 -0.093008......f 1 2 3f 4 1 3f 5 1 4

In blender, the export settings can include modifiers but the outputhas to be triangulated.

The model above consists of over 1.000.000 triangles, rendering these triangles is done through a Bounding Volume Hierarchy octree structure, which means the intersection tests are narrowed down and allows for faster rendering. I have attempted to make a comparison, but as it turns out.. rendering 1M triangles without a BVH structure is just not really what you want to be waiting on.

Materials

Materials can be applied to any shape using the-mat flag, followed by a file path"dir/file.mat" written directly behind the color input. Materials allow for the customization of reflections, specularity, gloss, emission, normal transformation and emission. We can also specify custom textures to map these values according to their respective UV coordinates.

The following table shows an example of a valid.mat syntax, and which materials can be used on what render mode (checkmark indicators are excluded from the actual .mat file (EOL = End Of Line), see:Materials). For clarification,Gloss androughness are almost the same, however gloss affects the specular exponent used to generate ashine effect in the classic ray tracer. the input is linear, and is computed to match the exponent value. The roughness BRDF value determines the mix between diffuse and reflection, which results in the shape's gloss level (0.0 being fully reflective & glossy, whereas gloss in classic tracing has a maximum value of 1.0 being the gloss amount.Specularity is the blending value between diffuse and gloss, andreflection is the blending value between diffuse and reflected rays.emmission allows for the shape to emit light instead of absorb it. Color blend for emission is not capped to any value

IDflagsAmountColor blendClassicBRDF
diffuse255,128,128EOL
specular255,255,255EOL
reflection255,255,255EOL
gloss0.5EOL
roughness0.5EOL
emission100,100,100EOL

We can map these values according to UV coordinates by loading image textures. This is also wherenormal maps come in, they are however only "valid" on classic ray tracing. A BRDF uses a randomization monte carlo algorithm, so in certain cases this will invalidate the use of normal maps because rays can end up facing in directions that point inwards of a shape. This issue is not being dealt with, some normal maps can apply to a BRDF mixed with the right roughness values. Gloss values can be mapped as well, but in most cases i invert the roughness channel in order to get a valid gloss map, the same can be done the opposite way.

IDPath to texture file
diffuse_map"textures/stained_dif.xpm"
normal_map"textures/stained_nml.xpm"
roughness_map"textures/stained_rgh.xpm"
reflection_map"textures/stained_rfl.xpm"
specular_map"textures/stained_spc.xpm"
emission_map"textures/stained_ems.xpm"

Other material properties include the sine wave bonus, and the option to scale textures' width and height:

IDflag (u/v/uv)AmplitudeFrequency
waveuv0.5100
IDScale
scale_x0.5
scale_y1.2

Depth of field

One of the things i personally enjoy is a goodBokeh, this describes the circular shape of the depth of field in cameras, as well as anamorphic ellipse-type shapes. Both of these have been implemented using the appropriate sampling methods, as well as a rejection method for custom lens shapes

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp