A minimal GPU ray tracer built in Unity using a fragment shader.
This project demonstrates real-time ray tracing in Unity using the standard vertex and fragment pipeline. It renders reflective and emissive spheres entirely on the GPU.
-
Shader (
myShader.shader)
Performs ray sphere intersections and lighting directly in the fragment shader using basic vector mathematics. Sphere data is passed as aStructuredBufferin the shader. -
Sphere Class (
RayTracingSphere.cs)
Defines per sphere properties such as color, reflectivity, luminosity, and emission color. -
Camera Class (
CameraScript.cs)
Populates a C# array of Sphere structs, uploads it to the GPU using aComputeBuffer, and draws the scene withGraphics.Blitwhen ray tracing is enabled.
- GPU based ray tracing using a fragment shader
- Supports multiple reflective and emissive spheres
- Adjustable bounce limit and accumulation for progressive blending
- Uses a C# array uploaded to the GPU via
ComputeBuffer