Unity Ray Tracing Gpu Shader by langep - 1

Shaders & Effects

Project to learn about Compute Shaders and Ray Tracing in Unity

Unity 2019.2.10f1Unknown LicenseUpdated 19 days agoCreated on October 27th, 2019
Go to source

Unity - GPU Ray Tracing in Unity


This is a project to learn about Compute Shaders and Ray Tracing in Unity. I am following the great article by David Kuri on the topic.

Project Organization

Each stage of the project will be available as individual tag.

Tag Description
01-setup-raytracing-master Create the controller script which invokes the compute shader.
02-sample-from-texture Create rays and sample from Skybox texture.
03-trace-ground-and-sphere Trace rays and intersect with ground plane and sphere.
04-progressive-sampling Progressive sampling to remove aliasing when camera doesn’t move.
05-mirror-reflection Mirror-like reflection for metallic objects by bouncing rays.
06-diffuse-reflection Add diffuse reflection for non-metallic objects.
07-lambert-diffuse-phong-specular Use Lambert Diffuse and Phong Specular via importance sampling.


This is the output after setting up the RayTracingMaster.cs script to invoke Unity’s default compute shader.

Unity Default Compute Shader


The output after creating rays and sampling from a Skybox texture:

Skybox Texture


The output after adding a ground plane and sphere. Nasty aliasing!

Sphere with Aliasing


After progressive sampling, the sphere looks much better.

Sphere with Progressive Sampling


After adding bouncing rays for mirror-like reflections for metalic materials, we can see relections in reflections in relections in …



After adding additional diffuse reflections, everything is made of plastic.



After adding Lambert Diffuse and Phong Specular reflections and combining them based on importance sampling, we start to look a lot nicer. We also added randomized spheres and a slider for global illumination.


Show all projects by langep