Unity Shader System


Language: C# (Unity), Unity ShaderLab

Contributions
  • Programmed shader for albedo, detail, normal (detail normal), emission, occlusion, and detail mask maps
  • Programmed for multiple lighting and shadows
  • Built reflections into shaders using reflection probes


The Unity material system has been developed to allow artists, game designers and game programmers to easily create realistic looking artwork. I sought out to better understand the Unity material system by programming the vertex and fragment shaders from scratch.

The splat map on the left was during the beginning of development, I had created a basic vertex and fragment shader to take up to 5 textures to blend together by using the RGBA channels. The right picture is of 2 sepearate textures, a circuit and lava, which display albedo, normal, detail, detail normal, metallic/smoothness, and emission maps. The shader has a forward base and add passes and shadow casting to be able to handle the different types of lights. Within each pass there are multi compile and shader feature statements to allow for the different shader variants.



I also built in reflection into the shader, and by using Unity's reflection probes I was able to create mirrors. The maps of the materials can be changed with the reflection, for example by adding a normal map to the material, the mirror can be turned into a water-like surface.

So far, I have had the most trouble with programming for multiple lights because I hadn't delved into Unity's lighting and quality settings in that much depth previously. To understand how the lighting was being processed, I used the frame debugger to step through the rendering process and watched the draw calls of lighting change based on the number of lights to ensure the shader wasn't overworking.