top of page
Search

Raytracing Engine

Chris Leu

I put together this simple raytracing engine a weekend by referencing various online tutorials and discussing the topic with another alumnus who expressed interest in the concept.


The basics of this method entails simulating a number of rays bouncing off of a surface. This would be relatively difficult to do this performantly on the CPU, let alone to fully map out sequential reflections, so using the GPU to exploit parallelism and resolve the lighting is the standard expectation.


This effect can be calculated from an camera-first or a light-first perspective, and I chose to use a camera-first approach as the documentation seems to be more prevalent. The difference being if lights emit the rays, which bounce to the camera, or if the camera emits rays, which then poll the scene lights to calculate illumination.

This is improved still by utilizing a concept called Signed Distance Functions, which are functions that resolve the dimensions of a primitive shape, and allow polling of positions against that shape very efficiently. I used these to store the data for each shape in an efficient and accessible manner, and offloaded them into a separate file so as to not clutter the shader itself.

Wikipedia graphic for Ray Tracing

I initially struggled with this project, as it has many, many points of failure. For example, if an object is being drawn in plain grey, is the color set in the camera's script not applied?

Is the camera inputting the value to the wrong shader property?

Is the shader reading the wrong value, or resetting it somewhere?

Is the color being calculated correctly, but not being used in the fragment function?

In addition this technique, while well documented, lacks a centralized or Unity-certified resource to work from, meaning I frequently has to review a tutorial, deduce what they were doing in each step, and compare that to my progress thus far.


All in all, it is quite functional, and both demo builds provided exploit modulus to get repeating geometry at very little cost.


One such repeating effect, using a red torus.

Another repeating effect, showing off large numbers of detailed reflections.

Shader



14 views0 comments

Recent Posts

See All

Comments


bottom of page