Stochastic Ray Tracing in Unity

Stochastic Ray Tracing in Unity

For my final year project I wanted to explore global illumination as I’m interested in graphics and especially lighting, so to explore this region of programming I set out to improve my knowledge and skills by creating a stochastic ray traced renderer in Unity.

Colour Bouncing and Bleeding:

One of the demonstration scenes I use is quite popular to show soft effects that can not be achieved with non-global illumination techniques such as standard rasterization. The soft shadow boundaries are achieved by the scattering of rays when hitting objects, but also the normally distributed rays through a pixel on our projection plane.

The colour bleeding is most noticeable between the red and white sphere, the rays that hit the red sphere and then bounce carrying the colour and intensity data to the white sphere that displays it easily.

Reflection:

This demo scene is an adaptation of the standard Cornell Box, adding a obscured emissive sphere behind a solid obstacle. This scene also shows different levels of smoothness on identical spheres, alongside their specular probability so that when it is completely smooth the reflections are perfect. These values are adjustable per object, and you can achieve specular highlights as you would see in the real world if the probability is reduced alongside smoothness. Calculating these world space reflections meant having apt ray bouncing calculations that transfer data correctly between objects.

Emission:

A basic emissive sphere was included to also display how the light looks like it is bending around the surface of the sphere due to the constant changing normals when traversing the sphere’s surface.

Complex Meshes:

A major drawback to my current implementation is that there are no acceleration structures in place such as bounding volume hierarchies or BVH. This means that the current architecture struggles with complex meshes, for example Suzanne has 968 triangles, and this is where the implementation is the least performant as like any other collision check which is naïve it checks every triangle against one hit by a ray, and when the meshes get denser and more complex, the check and computation time becomes much more cumbersome. In the future, BVH’s will be worked on and applied so that scenes with more complex meshes and multiple instances of them can be rendered in real time.

Back To Home