2015 |
D-Ray |
What is it?D-Ray is a ray tracer I developed from scratch in Garry's Mod with Wiremod's Expression 2.
It took 5 hours to work out the theory and write up the first working version and another 2 days perfecting and optimizing. The image on the right shows an example of the realistic method of ray tracing and what it can achieve. The same method is used in many animated films like the ones Pixar makes. This realistic method I originally thought of myself from my knowledge from my physics subject in my final years at school. Where light only comes from an emissive source -> bounces around and is altered by the different suface types -> where eventually some of the photons reach the observer's eyes. D-Ray's Early TestsThe image on the right shows how the ray travels from the camera, bounces off the mirror shader or diffuse plane until it hits the sky's emission shader. After which, it pulls the colours back up the ray tree and blends them together at each step.
The image was also rendered at 64x64 resolution so it renders quickly. Notice how the blue and red tints in the mirror make the purple colour shown. The anti-aliasing is less prominent as it wasn't properly set up for this resolution. First Quality ImageThis image took about 30 minutes to render. Keep in mind that the rays only interact with the collision models on each prop and I can't access any smooth shading.
There was only 1 diffuse bounce as it exponentially increases the render time. There weren't many diffuse samples or random spread of diffuse samples causing those artifacts to appear on the diffuse surfaces. Besides that, the image is a big step towards realism for the ray tracer. |
In ray tracing this is worked out backwards, some people even call this "Backwards Ray Tracing".
This is when you shoot rays from the camera -> to bounce around the scene until -> it hits an emissive source or it reaches its limit on bounces to avoid recursion. Recursion is what happens when the ray continuously bounces and in some cases never reaches an emissive source. By limiting the amount of bounces, this issue can be solved easily. The image on the left shows the traditional shading techniques used with point lights. The world of ray tracing changed when Turner Whitted published a paper on recursive ray tracing in 1979. - If only I lived in the 70's! - Later I created G-Ray, which uses the old technique and does much faster renders! The early image produced was a big step however I had the code running every ray bounce at once without splitting it up into steps to take over a period of time.
The image on the left is a visual representation of how I changed the programming to fix this issue. Entry shader function - Starts more bounces or runs the parent ray's exit function. Exit shader function - Tints the color and continues exiting up the chain unless its a diffuse shader which checks if it needs to take more samples. |
Then What?
I stopped working on this because a high quality image would take many weeks to render when I can get the same result in blender in a matter of seconds. The main thing is that I was able to create an in-game ray tracer in a short amount of time and I have learn't plenty from this experience.