selected work

ray tracer

OpenGL real-time ray tracer using Compute Shaders, touching post-processing.

client
Self-initiated
role
Creative developer
timeline
2022 · 4 weeks

About

OpenGL real-time ray tracer using Compute Shaders. Based on the "Ray Tracing in One Weekend series".

Process

1. Matte Materials

The process is simple: normalizing the y coordinate and interpolating between two colors. Checking if the rays hit the sphere and displaying the color. The resulting color is computed by picking a random point inside a unit radius sphere, whose normal starts from the initial ray hit point. This is done recursively until a ray doesn't hit anything or a maximum depth is reached.

2. Metallic Surfaces

For metallic surfaces, rays aren't randomly scattered. Luckily, GLSL has the reflect() function, which returns the reflected ray. Randomizing the reflected ray by choosing a random endpoint, as we did for the matte surface, gives rough (fuzzy) surfaces.

3. Dielectric Surfaces

A ray is split into both a reflected one and a refracted one. Assuming that all rays are only refracted results in one outcome. Using Schlick's polynomial approximation, we can determine if rays must be reflected instead of refracted, producing the final result.

4. Cornell Box

Adding a Cornell Box introduces more complexity into the scene. To make things more realistic, emissive materials are added for ceiling lights and spheres. Rays hitting an emissive surface won't scatter, so they retain their true albedo color output.

5. Post-Processing

On the post-processing layer, HDR is applied, making the emissive material stand out more. Bloom is also added, which renders lights as blurred (using Gaussian Blur) and adds the result on top of the base color.