Entering a world of primitives...
We saw in Chapter 7 that compute shaders are an excellent way to process large data quickly – which is typically what we need for ray marching, since in every frame, we have to step through many rays (one per pixel) to render the scene!
Our ray marching logic will therefore be written in a compute shader file, and then called from a C# script at the time of the render as a full-screen effect. So, the process will reuse the custom scriptable render feature (URPComputeFeature
) we prepared in Chapter 7, and we will go through the same steps as in the Applying a compute shader-based screen effect in URP section of Chapter 7.
In the upcoming sections, we will therefore start by preparing a basic compute shader to render a single sphere using ray marching, and then improve it to handle multiple shapes of different types.
Rendering a sphere with ray marching
To begin with, let’s set up a first basic ray marching compute shader to...