Volumetric Sphere Shader

This is my implementation of Alan Zucconi’s tutorial on Volumetric Rendering.

This is a vertex and fragment shader.

An important observation I made is the order of declaring functions is important. A function must be declared before it can be called by another function.

I expanded on the tutorial by declaring Properties, making the center of the sphere and its size available from Unity’s inspector. This way I could play with values without updating the shader each time.

In the vertex function I get the world position of the vertex for use in the fragment function.

The fragment function is where most of the work in this shader happens.

Full listing: