- Yet another ray tracer.
- A simple ray tracer based on Blinn-Phong reflection model.
- Code is written in
C++. include/&src/contains all the src code.examples/contains some example scene files.textures/contains texture files.assignments/contains problem statements from which this raytracer was created.
- The documentation for the code is itself.
- Compile the raytracer using
maketo create an executableraytracer. - The executable reads a scene file (and possibly some texture files) and generates a
ppmimage. - Create the image of a scene using
./raytracer <path-to-scene-file>. It will be in the same directory as the scene file.- For example,
./raytracer examples/scene.txtcreatesexamples/scene.ppm.
- For example,
- The format is similar to .obj file format.
- Each line a the scene file defines something. Each line starts with a keyword and varying number of space separated parameters can follow.
- All colors are in normalized scale (0 - 1).
- The recognized keywords are as follows.
# ...: Comment. Will be ignored.eye x y z: Camera position.viewdir x y z: Camera viewing direction. Must be a unit vector.updir x y z: Up direction. Must be a unit vector.vfov angle: Vertical field of view in degrees.imsize width height: Output image dimensions in pixels.bkgcolor r g b: Background color.light x y z w r g b: A light source.x y zis position.wcan be 0 (directional source) or 1 (point source).r g bis color.
mtlcolor Odr Odg Odb Osr Osg Osb ka kd ks n a h: Material color.Odr Odg Odbis diffusion color.Osr Osg Osbis specular color.ka kd ksare ambient, diffusion and specular co-efficients respectively in the Blinn-Phong model.nis the power in Blinn-Phong model.ais opacity level (0 - 1).his refractive index.
texture <path-to-texture-file>: Path is assumed to start from raytracer executable directory. Has to be a validppmfile.sphere x y z radius: A spherical object.v x y z: Vertex position.vt u v: A texture coordinate.u&vmust be in [0, 1].vn x y z: A vertex normal definition. Must be a unit vector.f ...: A face of a triangle.- All following arguments are indices of previously defined entities. The entities are counted from starting from 1 (and not 0).
f v1 v2 v3:v1 v2 v3: Vertex indices.f v1/vt1 v2/vt2 v3/vt2: Vertex indices annotated with texture coordinate indices.f v1//vn1 v2//vn2 v3//vn3: Vertex indices annotated with vertex normal indices.f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3: Vertex indices annotated with texture coordinate indices & vertex normal indices.
parallel: Presence indicates that parallel projection is to be used. Default isperspective.viewdist distance: Viewing distance for depth of field effect.
- Once a material color or texture is defined, it will be used for all the following objects in the scene until another is defined.
- For integer parameters, don't add a succeding decimal part.
1is ok.1.is not okay.1.0is not okay.- This is caused merely because of the
cinconstruct behaviour and has nothing to do with the ray tracer.
- Ray tracer has some configurable parameters, as listed with the defaults below.
| name | description | default |
|---|---|---|
| CAMERA_MEDIUM_REFRACTIVE_INDEX | Refractive index of medium camera is placed in. | 1 |
| CAMERA_MEDIUM_OPACITY | Opacity of medium camera is placed in. | 0 |
| RECURSIVE_DEPTH | Number of times a ray reflects/refracts. Higher value produces more realistic effects. | 6 |
| SOFT_SHADOW_JITTER | Measure of dispersion of shadow rays. Higher value produces softer shadows. | 0 |
| NUM_SHADOW_RAYS_PER_POI | Number of shadow rays. Higher value produces softer shadows. | 1 |
| NUM_DISTRIBUTED_RAYS | Number of rays traced per pixel. Higher value produces more diffused image. | 10 |
| DISTRIBUTED_RAYS_JITTER | Measure of dispersion of rays traced per pixel. Higher value produces more diffused image. | 5e-2 |
- To change config, directly edit these values in
src/main.cppand recompile.
- Ray sphere intersection.
- Ray triangle intersection (barycentric coordinates).
- Blinn-Phong reflection model.
- Point and directional source of light.
- Shadows.
- Smooth shadows.
- Subtractive shadows.
- Spheres.
- Triangules.
- Vertex normals, and their interpolation.
- Textures for spheres and triangles, Texture coordinates and their interpolation.
- Recursive ray tracing (using schlick’s approximation of the Fresnel reflectance).
- Refraction.
- Total internal reflection.
- Depth of field effect using distributed ray tracing.
- Parallel projection (not done properly, pulls the camera extremely far back).
- Spotlights.
- Attenuation.
- Parser. Recognized keywords, Input validation, Good error messages.
- PPM writer.
- PPM reader for textures.
- To string for all types.
- Vec3d structure.
- Invalid number of args fix.
- Output file name fix.
- Accept empty lines.
- Ignore unknown keywords.
- Sometimes your rays go through triangles without detecting the intersection.
- Your texture parser doesnt always work, there might be newlines or whitespace at the end of a line.
- Your shadows aren't correct sometimes.
- texture paths.
- 1c testcases.
- 1d testcases.