Uploaded June 2020 | Updated September 2026, 2 hours ago
The entire set of ray tracing calculations occur in the Fragment shader (OpenGL GLSL code) - therefore using the GPU.
I've designed the code to, per fragment / pixel:
- determine the correct ray for each pixel
- accept triangles (by model) to test against by using ray-triangle intersection testing
- determine whether rays hit objects, and if so, what colour should be displayed due to lighting
- but only add said colour based on the lack of any shadows that may be generated by objects obstructing those lights
- those shadows are generated taking into account the radius of the light source - producing nice looking soft shadows where applicable
- and casting ambient rays or reflection rays, to determine any 2nd / 3rd / 4th etc order shading effects for each pixel
Find the shader code (GLSL) here: github.com/s0lly/RayTracingInTheFragmentShaderGLSL - feel free to use to your heart's content.
Happy to answer any questions in the comments below!
Other Social Media stuffs:
twitch.tv/s0llygaming
twitter.com/s0lly
instagram.com/s0lly.gaming
github.com/s0lly
patreon.com/s0lly
The entire set of ray tracing calculations occur in the Fragment shader (OpenGL GLSL code) - therefore using the GPU.
I've designed the code to, per fragment / pixel:
- determine the correct ray for each pixel
- accept triangles (by model) to test against by using ray-triangle intersection testing
- determine whether rays hit objects, and if so, what colour should be displayed due to lighting
- but only add said colour based on the lack of any shadows that may be generated by objects obstructing those lights
- those shadows are generated taking into account the radius of the light source - producing nice looking soft shadows where applicable
- and casting ambient rays or reflection rays, to determine any 2nd / 3rd / 4th etc order shading effects for each pixel
Find the shader code (GLSL) here: github.com/s0lly/RayTracingInTheFragmentShaderGLSL - feel free to use to your heart's content.
Happy to answer any questions in the comments below!
Other Social Media stuffs:
twitch.tv/s0llygaming
twitter.com/s0lly
instagram.com/s0lly.gaming
github.com/s0lly
patreon.com/s0lly










