Giter VIP home page Giter VIP logo

raytracer's Introduction

Raytracer

Raytracer for CSCI 4471 Computer Graphics class project

See Features section below for a complete feature list.

Author

Downloads

Pre-Built Binary for Mac (188 KB) zip of in/ directory (32.6 MB) zip of out/ directory (4.22 MB) zip of img/ directory (2.79 MB)

Note: Some of the required files are ignored by Git to keep the repository's size at a minimum. The complete in/ directory can be downloaded and swapped in place after downloading this repository. This will allow you to test all of the files, including those with large .obj and texture files.

The out/ directory contains all of the rendered images as .bmp. The img/ directory contains all of the images converted into .png. You may prefer to download the resulting images in out/ and img/, and skip compiling and running the Raytracer entirely.

Compiling

Build the executable in bin/ directory.

make

Cleaning

make clean

Usage

After compiling (see above):

./bin/raytracer.o

Testing

Unit Testing

make test

Rendering Sample Scenes

make render

Then look into the out/ for all of the rendered images.

You can also copy and paste the commands that are printed out for each file render.

For instance, you may see:

cd in/ ; ../bin/raytracer.o -input test_noise_1.txt -size 200 200 -bounces 4 -output ../out/test_noise_1-no_back.bmp -normals ../out/test_noise_1_normals.bmp ; cd ../

You can easily copy and paste this command to re-render this case for input test_noise_1.txt with those arguments.

Rendering Arguments

You can change the default arguments for render task.

  • PATTERN - Defaults to *.txt - Globbing pattern to select input files from in/ directory
  • SIZE - Defaults to 200 - Size of rendered images
  • EXT - Defaults to bmp (bmp or tga supported) - File extension of rendered images
  • BOUNCES - Defaults to 4 - # of recursive bounces of a ray, used for reflections
  • SPECIALS - Defaults to on (on or off) - Render special cases of the input files, such as with depth mapping

Cleaning Rendered Images

After running make render and populating your out/ directory with images you may wish to clean / delete all of those images.

make clean-render

Rendering with a clean build

By default, make render will only compile any new / changed files. To force a make clean before building the binary and running the render task you can use the render-clean task.

# Exactly like using just `render` task
# Except it runs `clean` task before building
make render-clean
Examples

To render a single file, use full filename and force the pattern to only match one:

make render PATTERN=test_bunny_1k.txt

You can use Globbing / patterns to select input files:

make render PATTERN=test_colored_reflective_sphere_shadows_2*

You can also change the rendered image size:

# Render all images with output size of 1000
make render SIZE=1000
# Render specific pattern of images with output size of 1000
make render PATTERN=test_texture_mapping_sphere.txt SIZE=1000

You can also disable the special custom rendered images:

make render SPECIAL=off

Convert .bmp to .png images

First, install imagemagick:

brew install imagemagick

The following will convert the .bmp images to .png images and move them into the img/ directory.

make convert-render

You should run this after you're satisfied with your .bmp renders. It will render all of the .bmp images it can find in out/, and will take some time. Be patient and run only when you're ready.

make render # Render `.bmp` images to `out/`
make convert-render # Convert `.bmp` to `.png` and move to `img/`

Documentation

Source Code

Using Doxygen.

make docs

Features

Here is the complete feature list. Bolded list items are require features. Features marked with ✓ are implemented, while those without are not.

In addition to the 103 required marks there were 26 elective marks implemented, totalling to 129 marks out of the 125 marks for 100%.

Below is the complete list of features and details about each where applicable.

Electives (22 required marks)

Your choice of additional features beyond the specific required ones.

Implemented 26 elective marks:

  • Multiple light sources (4 marks)
  • Other debugging tools (2 marks)
  • Environment Mapping (5 marks)
  • Octree (6 marks)
  • Antialiasing (5 marks)
  • Source Control (4 marks)

Starting Out (5 required marks)

Implemented 5 out of 5 required marks.

Primitives and Modeling (29 required marks)

Implemented 29 out of 29 required marks.

image

image

render

scene2_09_bunny_200-shadows_shade_back

scene2_10_bunny_1k_normals scene2_10_bunny_1k-shadows_shade_back

scene12_vase_normals scene12_vase-shadows_shade_back

scene13_diamond_normals scene13_diamond-shadows_shade_back

test_bunny_1k_normals test_bunny_1k-shadows_shade_back

scene2_11_squashed_sphere_normals scene2_11_squashed_sphere-shadows_shade_back

scene2_13_rotated_squashed_sphere_normals scene2_13_rotated_squashed_sphere-shadows_shade_back

scene2_14_axes_cube_normals scene2_14_axes_cube-shadows_shade_back

scene2_15_crazy_transforms_normals scene2_15_crazy_transforms-shadows_shade_back

  • Constructive Solid Geometry (10 marks)

  • Additional Primitives (3 or more marks)

  • 3-D Iterated Function System (8 marks)

Light Simulation and Illumination (36 required marks)

Implemented 36 out of 36 required marks and 4 elective marks.

image

scene_shininess_variations-shadows_shade_back

scene4_03_mirrored_floor_normals scene4_03_mirrored_floor-shadows_shade_back

scene4_04_reflective_sphere_normals scene4_04_reflective_sphere-shadows_shade_back

scene_reflective_sphere_normals scene_reflective_sphere_bounces_0 scene_reflective_sphere_bounces_1 scene_reflective_sphere_bounces_2 scene_reflective_sphere_bounces_3 scene_reflective_sphere-shadows_shade_back

scene_reflective_shininess_variations_normals scene_reflective_shininess_variations-shade_back scene_reflective_shininess_variations-shadows_shade_back

  • [✓] Basic Shadows (6 marks)

    image image

  • [✓] Refraction (10 marks)

    • See RayTracer.cpp

      scene4_06_transparent_bars.txt | scene4_07_transparent_sphere_1.txt --- | --- | --- | --- scene4_06_transparent_bars-shadows_shade_back | scene4_07_transparent_sphere_1-shadows_shade_back scene4_06_transparent_bars-shadows_shade_back.bmp | scene4_07_transparent_sphere_1-shadows_shade_back

      scene4_08_transparent_sphere_1.txt | scene4_09_transparent_sphere_2.txt --- | --- | --- | --- scene4_08_transparent_sphere_1-shadows_shade_back | scene4_09_transparent_sphere_2-shadows_shade_back scene4_08_transparent_sphere_1-shadows_shade_back.bmp | scene4_09_transparent_sphere_2-shadows_shade_back.bmp

  • Soft Shadows (6 marks)

  • [✓] Multiple light sources (4 marks)

scene2_03_colored_lights-shadows_shade_back scene4_02_colored_shadows-shadows_shade_back

  • Spotlights (4 marks)

  • Glossy reflections (7 marks)

  • Simple Fog (4 marks)

  • Volumetric fog (8 marks)

  • Photon Mapping (15 marks)

Camera and Lens Model (11 required marks)

Implemented 11 out of 11 required marks.

  • [✓] Camera (2 marks)

  • [✓] Orthographic Camera (4 marks)

  • [✓] Perspective Camera (5 marks)

  • Bloom (4 marks)

  • Depth-of-field (8 marks)

  • Fisheye appearance (2 marks)

  • Oblique Cameras (2 marks)

  • Other Non-Linear Cameras (4+ marks)

Debugging Tools (12 required marks)

Implemented 12 out of 12 required marks and 2 elective marks.

  • [✓] Depth Visualization (4 marks)

scene1_01_depth scene1_02_depth scene1_03_depth scene1_04_depth scene1_05_depth scene1_06_depth scene1_07_depth scene2_04_perspective_depth scene2_05_depth scene2_06_depth scene2_07_depth

  • [✓] Back face shading / no shading (4 marks)

scene2_07_depth scene2_07_sphere_triangles_normals scene2_07_sphere_triangles-no_back scene2_07_sphere_triangles-shade_back

scene2_05_depth scene2_05_inside_sphere_normals scene2_05_inside_sphere-no_back scene2_05_inside_sphere-shade_back

  • [✓] Normal Visualization (4 marks)

octahedron_2_normals octahedron_normals scene_reflective_shininess_variations_normals scene_reflective_sphere_normals scene_shininess_variations_normals scene1_01_normals scene1_02_normals scene1_03_normals scene1_04_normals scene1_05_normals scene1_06_normals scene1_07_normals scene1_08_normals scene01_plane_normals scene2_01_diffuse_normals scene2_02_ambient_normals scene2_03_colored_lights_normals scene2_04_perspective_normals scene2_05_inside_sphere_normals scene2_06_plane_normals scene2_07_sphere_triangles_normals scene2_08_cube_normals scene2_09_bunny_200_normals scene2_10_bunny_1k_normals scene2_11_squashed_sphere_normals scene2_12_rotated_sphere_normals scene2_13_rotated_squashed_sphere_normals scene2_14_axes_cube_normals scene2_15_crazy_transforms_normals scene2_16_t_scale_normals scene02_cube_normals scene4_01_sphere_shadow_normals scene4_02_colored_shadows_normals scene4_03_mirrored_floor_normals scene4_04_reflective_sphere_normals scene4_05_transparent_bar_angle_view_normals scene4_05_transparent_bar_normals scene4_06_transparent_bars_normals scene4_07_transparent_sphere_1_normals scene4_08_transparent_sphere_1_normals scene4_09_transparent_sphere_2_normals scene4_10_point_light_distance_normals scene4_11_point_light_circle_normals scene4_12_point_light_circle_d_attenuation_normals scene4_13_point_light_circle_d2_attenuation_normals scene4_14_faceted_gem_normals scene05_bunny_200_normals scene06_bunny_1k_normals scene10_sphere_normals scene11_cube_normals scene12_vase_normals scene13_diamond_normals test_bunny_1k_normals test_colored_reflective_sphere_shadows_2_normals test_colored_reflective_sphere_shadows_3_normals test_colored_reflective_sphere_shadows_4_normals test_colored_reflective_sphere_shadows_normals test_noise_1_normals test_ortho_cube_normals test_ortho_cube_refraction_normals test_perspective_1_normals test_plane_1_normals test_refraction_inside_sphere_normals test_texture_mapping_sphere_normals test_transparent_sphere_normals test_wine_glasses_normals tetrahedron_normals

  • OpenGL Previsualization Tool (6 marks)

  • [✓] Other Tools (2+ marks)

  • [✓] I developed RayCapture for the purpose of assisting me with quicker debugging and generating sample input scenes.

  • [✓] I have used Unit Testing to help me with my debugging. You can run make test to see the results. This has helped me in the initial development of this Raytracer for testing Camera's generateRay return values in comparison to the right values calculated "by hand". See test/unit/ directory for source code of the unit tests.

  • [✓] I developed a render.sh script that allows me to pass arguments in to customize which input files are rendered and how they are rendered, size of image, number of ray bounces, etc. See Rendering Arguments section above for more details.

Textures (10 required marks)

Implemented 10 out of 10 required marks and 5 elective marks.

  • [✓] Simple Procedural (4 marks)

  • [✓] Texture Mapping I (6 marks)

  • Texture Mapping II (up to 6 marks)

  • [✓] Environment Mapping (5 marks)

This could be sphere maps or cube maps. - [✓] Cube Map support - See CubeMap.h and CubeMap.cpp

	`scene10_sphere.txt` | `scene12_vase.txt`

--- | --- scene10_sphere-shadows_shade_back | scene12_vase-shadows_shade_back scene10_sphere-shadows_shade_back.bmp | scene12_vase-shadows_shade_back.bmp

  • Additional texture model loading (4 marks)

  • Bump mapping (6 marks)

Acceleration Techniques (0 required marks)

Implemented 6 elective marks.

  • Adaptive Ray Depth (5 marks)

  • Intersection Methods (4 marks)

  • BSP tree (6 marks)

  • Grid (6 marks)

  • Adaptive bounding boxes or bounding spheres (6 marks)

  • [✓] Octree (6 marks)

  • Some other technique of your choice (6 marks)

Distributed Raytracing (0 required marks)

Implemented 5 elective marks.

  • [✓] Antialiasing (5)

    • [✓] Jittering method for antialiasing

    Normal | Antialiasing with n=2 | Antialiasing with n=4 --- | --- | --- scene_reflective_shininess_variations-shadows_shade_back | scene_reflective_shininess_variations-jitter_2 | scene_reflective_shininess_variations-jitter_4

  • Adaptive Antialiasing (4 marks)

  • Motion Blur (4 marks)

Software Engineering (0 required marks)

Implement 4 elective marks.

  • [✓] Source Code Control (4 marks)

  • Parallelizing the Raytracer (5 marks)

raytracer's People

Contributors

glavin001 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

raytracer's Issues

Normal Visualization

Display the absolute value of the coordinates of the normal vector as an (r, g, b) color. For example, a normal pointing in the positive or negative z direction will be displayed as pure blue (0, 0, 1). You should use black as the color for the background (undefined normal).

  • Add code to parse an additional command line option -normals <normal_file.tga> to specify the output file for this visualization.

Constructive Solid Geometry

For constructive solid geometry (CSG), you need to implement a new intersectAll method for your Object3D classes. This function returns all of the intersections of the ray with the object, not just the closest one.

Adaptive Ray Depth

If surfaces are only partially reflective, not as many bounces are needed.

.obj importer

Write a parser that will read obj files, consisting of a list of triangle vertices, into your triangle structure. You may use on-line source code for parsing the actual file format, so this should be a fairly simple task that will then let you import very high-resolution models into your raytracer.

Perspective Camera

Add a PerspectiveCamera class that derives from Camera. Choose your favorite internal camera representation. Similar to an orthographic camera, the scene parser provides you with the center, direction, and up vectors. But for a perspective camera, the field of view is specified with an angle (as shown in the diagram).

   PerspectiveCamera(Vec3f &center, Vec3f &direction, Vec3f &up, float angle);

We might talk about a "virtual screen" in space. You can calculate the location and extents of this virtual screen using some simple trigonometry. You can then interpolate over points on the virtual screen in the same way you interpolated over points on the screen for the orthographic camera. Direction vectors can then be calculated by subtracting the camera center point from the screen point. Don't forget to normalize!

Note: the distance to the image plane and the size of the image plane are unnecessary. Why?

Fisheye appearance

When computing direction rays, if you interpolate over the camera angle, your scene will look distorted-- especially for wide camera angles, which will give the appearance of a fisheye lens.

Implement CLI Parsing

Parsing command line arguments & input files

See the section on parsing
If using Linux, use the provided code as a starter for command line arguments to specify input file, output image size and output file.
If using Windows, read in a secondary file that achieves achieves the same thing (i.e. specifying the input file etc).
Testing examples are provided below.
Use the input file parsing code provided to load the camera, background color and objects of the scene.
A simple scene file parser for this assignment is provided. The OrthographicCamera, Group and Sphere constructors and the Group::addObject method you will write are called from the parser. Look in the scene_parser.cpp file for details.

Oblique Cameras

The projection window can be off-center relative to the z-axis of the camera.

Simple Procedural

Implement a simple procedural texture, e.g. a simple polynomial or trigonometric function of the input coordinates.

Adaptive bounding boxes or bounding spheres

Object3D

class Object3D
    virtual bool hit()
    virtual box bounding-box()

Bounding box for Sphere

box sphere::bounding-box ()
    vector3f min = center - vec3(radius, radius, radius);
    vector3f max = center + vec3(radius, radius, radius);
    return box(min, max);

Bounding box for Triangle

  • Look into “Clipping”

Bloom

Render multiple passes and blur appropriately.

Simple Fog

Rays attenuate according to their length. Allow colour of fog to be specified in the scene file.

Texture Mapping I

We provide to load the texture and coordinates for you along with a texture class to facilitate look-up. You must interpolate texture coordinates in Triangle's intersect function, and look up texture coordinates in Material's shading function. If the material has valid texture indicated by t.Valid(), then simply use the texture colour instead of k_d. The texture colour can be retrieved by
Vector3f color = t(u,v)
where u,v is the texture coordinate.

Back face shading / no shading

Add a -shade_back option to your raytracer. When this option is specified, treat both sides (i.e. front and back) of your object surfaces in the same manner. This means you'll need to flip the normal when the eye is on the "wrong" side of the surface (when the dot product of the ray direction & the normal is positive). Do this normal flip just before you shade a pixel, not within the object intersection code. If the -shade_back flag is not specified, you should shade back-facing surfaces differently, to aid in debugging. Back-facing surfaces must be detected to implement refraction through translucent objects, and are often not rendered at all for efficiency in real-time applications. Demonstrate the flag being on and off with a triangle and a sphere primitive.

Additional Primitives

Implement one or more additional primitive(s) of your choice, e.g. torus, cone, cylinder, or other. Note that if you implement transformations, then you only need to implement the simple axis-aligned case for any additional primitives. Note that some primitives, e.g. a torus or higher order implicit surfaces, can be implemented by solving for t with a numerical root finder. If you do this, make sure to indicate this in your final report, so that you get appropriate credit for doing so.

Texture Mapping II

Automatically generate texture coordinates for primitives in addition to triangles (e.g. torus, sphere, etc).

Spotlights

Similar to point lights, but brightness is attenuated as a function of distance from their direction.

Intersection Methods

Implement different ray-object intersection methods (e.g. 2 different ray-triangle intersection calculations; 2 different ray-sphere calculations) and compare. Compare with analytical estimate for additional credit.

Other Tools

Suggest ideas for other debugging tools as you progress on your project and discuss with me.

Additional texture model loading

Note that the starter code only loads limited type of image file, and the provided Mesh code only loads .obj with a single texture map.

Transformations

Derive a subclass Transform from Object3D. Similar to a Group, a Transform will store a pointer to an Object3D (but only one, not an array). The constructor of a Transform takes a 4x4 matrix as input and a pointer to the Object3D modified by the transformation:

   Transform(Matrix &m, Object3D *o);

The intersect routine will first transform the ray, then delegate to the intersect routine of the contained object. Make sure to correctly transform the resulting normal according to the rule. You may choose to normalize the direction of the transformed ray or leave it un-normalized. If you decide not to normalize the direction, you might need to update some of your intersection code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.