Ray Tracer

Output Comparison

Run the program with the specified .ini file to compare your output (it should automatically save to the correct path).

If your program can’t find certain files or you aren’t seeing your output images appear, make sure to:

  1. Set your working directory to the project directory
  2. Set the command-line argument in Qt Creator to template_inis/illuminate/<ini_file_name>.ini
  3. Clone the scenefiles submodule. If you forgot to do this when initially cloning this repository, run git submodule update --init --recursive in the project directory

Note: once all images are filled in, the images will be the same size in the expected and student outputs.

File/Method To Produce OutputExpected OutputYour Output
point_light_1.ini
Place point_light_1.png in student_outputs/illuminate/required folder
point_light_2.ini
Place point_light_2.png in student_outputs/illuminate/required folder
spot_light_1.ini
Place spot_light_1.png in student_outputs/illuminate/required folder
spot_light_2.ini
Place spot_light_2.png in student_outputs/illuminate/required folder
simple_shadow.ini
Place simple_shadow.png in student_outputs/illuminate/required folder
shadow_test.ini
Place shadow_test.png in student_outputs/illuminate/required folder
shadow_special_case.ini
Place shadow_special_case.png in student_outputs/illuminate/required folder
reflections_basic.ini
Place reflections_basic.png in student_outputs/illuminate/required folder
reflections_complex.ini
Place reflections_complex.png in student_outputs/illuminate/required folder
texture_cone.ini
Place texture_cone.png in student_outputs/illuminate/required folder
texture_cone2.ini
Place texture_cone2.png in student_outputs/illuminate/required folder
texture_cube.ini
Place texture_cube.png in student_outputs/illuminate/required folder
texture_cube2.ini
Place texture_cube2.png in student_outputs/illuminate/required folder
texture_cyl.ini
Place texture_cyl.png in student_outputs/illuminate/required folder
texture_cyl2.ini
Place texture_cyl2.png in student_outputs/illuminate/required folder
texture_sphere.ini
Place texture_sphere.png in student_outputs/illuminate/required folder
texture_sphere2.ini
Place texture_sphere2.png in student_outputs/illuminate/required folder

Design Choices

Texture

Calculate the diffuse value using blending and pass it to the light to calculate the final effect.

Texture Bilinear Filtering

Find the four nearest pixels in the four corners around the intersected point and use the bilinear interpolation similar to lab7.

Refraction

Use the following formula to calculate the refracted direction and a similar code as reflection to recursively calculate the refraction effect.

$\vec{\omega_o} = \sqrt{1 - \frac{1}{\mu^2} [1 - (\vec{n} \cdot \vec{\omega_i})^2]} + \frac{1}{\mu}[-\vec{\omega_i} + (\vec{n} \cdot \vec{\omega_i})\vec{n}]$

Soft Shadow

Use a new type of light LightType::LIGHT_SOFT with a finite area length x length. Sample a random location on the light source for soft-samples times and use the average value to be the color of the shadow.

Collaboration/References

N/A

Known Bugs

  • Refraction does not achieve the expected result for refract2.png

  • When the sample number of the soft shadow is large (i.e. set a large soft-samples in the .ini file), the speed of the ray tracer is slow.

Extra Credit

Texture Bilinear Filtering

Set bi-filtering = true inside the .ini file.

Use the following two command line arguments to compare the output.

template_inis/illuminate/extra_credit/bilinear.ini

template_inis/illuminate/extra_credit/bilinear_off.ini

softshadow softshadow

Refraction

light.cpp -> refraction

Set refract = true inside the .ini file.

Use the following two command line arguments to see the output.

template_inis/illuminate/extra_credit/refract1.ini

template_inis/illuminate/extra_credit/refract2.ini

softshadow

The output for refract1 is similar to the expected output.

softshadow

but the output for refract2 does not achieve the expected results.

Soft Shadow

light.cpp and sceneparser.cpp

  • Add a new type of light LightType::LIGHT_SOFT with a new parameter length that specifies the side length for the light, and reuse other parameters and code for LightType::LIGHT_SPOT.

  • Example usage for .json file to create LightType::LIGHT_SOFT

"lights": [
        {
          "type": "soft",
          "color": [1.0, 1.0, 1.0],
          "direction": [0.0, -1.0, 0.0],
          "angle": 30.0,
          "penumbra": 20.0,
          "attenuationCoeff": [0.8, 0.05, 0.0],
	 	  "length": 0.3
        }
    ]
  • Set soft-samples = 50 inside the .ini file to specify sample points.

  • Use the following two command line arguments to compare the output.

    template_inis/illuminate/extra_credit/softshadow.ini

    template_inis/illuminate/extra_credit/softshadow_off.ini

    softshadow softshadow

  • Use the following two command line arguments to compare the output.

    template_inis/illuminate/extra_credit/softshadow2.ini

    template_inis/illuminate/extra_credit/softshadow2_off.ini

    softshadow softshadow

Output Comparison

Run the program with the specified .ini file to compare your output (it should automatically save to the correct path).

If your program can’t find certain files or you aren’t seeing your output images appear, make sure to:

  1. Set your working directory to the project directory
  2. Set the command-line argument in Qt Creator to template_inis/intersect/<ini_file_name>.ini
  3. Clone the scenefiles submodule. If you forgot to do this when initially cloning this repository, run git submodule update --init --recursive in the project directory

Note: once all images are filled in, the images will be the same size in the expected and student outputs.

File/Method To Produce OutputExpected OutputYour Output
unit_cone.ini
Place unit_cone.png in student_outputs/intersect/required folder
unit_cone_cap.ini
Place unit_cone_cap.png in student_outputs/intersect/required folder
unit_cube.ini
Place unit_cube.png in student_outputs/intersect/required folder
unit_cylinder.ini
Place unit_cylinder.png in student_outputs/intersect/required folder
unit_sphere.ini
Place unit_sphere.png in student_outputs/intersect/required folder
parse_matrix.ini
Place parse_matrix.png in student_outputs/intersect/required folder
ambient_total.ini
Place ambient_total.png in student_outputs/intersect/required folder
diffuse_total.ini
Place diffuse_total.png in student_outputs/intersect/required folder
specular_total.ini
Place specular_total.png in student_outputs/intersect/required folder
phong_total.ini
Place phong_total.png in student_outputs/intersect/required folder
directional_light_1.ini
Place directional_light_1.png in student_outputs/intersect/required folder
directional_light_2.ini
Place directional_light_2.png in student_outputs/intersect/required folder

Design Choices

KD-Tree

BoundingBox class, uses two vectors to measure the AABB.

KDNode class represents each node of the tree.

buildKDTree function constructs the tree. For choosing the split axis, I cycle through three axes instead of choosing the best axis because the latter approach is time consuming.

traverse_kd_tree function traverses the tree and if meets the leaf node, then calculate the intersected shape.

OpenMP

use #pragma omp parallel for collapse(2) before the main loop of pixels.

Anti-Aliasing Post-filter

Apply the blur filter from Project 2 with radius 5 as the post filter. The definition of the blur filter is in filterutils.cpp.

Super-Sampling

Apply traceRay function for the four corners of the aimed pixel and calculate the mean.

Collaboration/References

N/A

Known Bugs

There will be some black spots on the edges of objects due to inaccurate float comparisons.

Extra Credit

Acceleration data structure: KD-Tree

kdtree.cpp and boundingbox.cpp

Set acceleration = true inside the .ini file.

Use the following two command line arguments to compare the speed.

template_inis/intersect/extra_credit/kdtree_false.ini

template_inis/intersect/extra_credit/kdtree_true.ini

(use recursive_sphere_6.json)

recursive_sphere_6

Parallelization: Level1: OpenMP

Use #pragma omp parallel for collapse(2) before the main loop of pixels.

Set parallel = true inside the .ini file.

Use the following two command line arguments to compare the speed.

template_inis/intersect/extra_credit/parallel_false.ini

template_inis/intersect/extra_credit/parallel_true.ini

(use primitive_salad_2.json)

primitive_salad_2.png

Anti-Aliasing: Blurring Post-filter

filterutil.cpp

Set anti-aliasing = true inside the .ini file.

Use the following two command line arguments to compare the output.

template_inis/intersect/extra_credit/antialising_false.ini

template_inis/intersect/extra_credit/antialising_true.ini

(use directional_light_2.json)

original_directional_light_2 antialising_directional_light_2

Super-Sampling: Stochastic Super-Sampling

Set super-sample = true inside the .ini file and num-samples = 10 to specify sample points.

Use the following two command line arguments to compare the output.

template_inis/intersect/extra_credit/supersample_false.ini

template_inis/intersect/extra_credit/supersample_true.ini

(use primitive_salad_1.json)

original_primitive_salad_1 supersample_primitive_salad_1

Create your own scene file

Use the following command line argument.

template_inis/intersect/extra_credit/customize.ini

(use torii.json)torii

Chengfan Li
Chengfan Li

He once lost a diamond cuff-link in the wide blue sea.