Unity - Shaders

Description

A compilation of shaders made in Unity 2018. Features a few a different types of effects achieved with a combination of surface, fragment and/or vertex shaders.

Project Details

  • Role: Solo developer

  • Duration: December 2018 – Present

  • Tools: Unity 2018, Visual Studio 2017, Git+Sourcetree

  • Language: C#, Cg/HLSL

  • Platform: PC

  • Team Size: 1


Stencil Box

Created with two surface shaders, which utilize the stencil buffer. Each object in the scene is assigned a stencil buffer reference, which correlates to a “window“. Comparison functions are used to check object and window references in the stencil buffer, if the object’s reference is equal to the reference in the stencil buffer (the window) we keep the object. This ensures that only objects with references correlating to the window(s) in view are drawn to the screen.


Water

There are a few things happening in this vertex/surface shader. First of all, it blends two textures, which are moving at different speeds. Properties include speed, frequency, and amplitude, which are used along with time to calculate the height of each vertex (Wave height). The vertex height is then used to calculate the final albedo colour, which gives the wave peaks a higher colour value, and the wave lows a lower colour value.

Water.gif

Plasma

Plasma

Surface shader that uses a series of sin and cos functions, the vertices’ world position, and a few properties to create an old-school plasma effect. Properties include a few float ranges to control the scale, shape, and speed of the plasma. A series of sin and cos functions are used to build up the final colour.


Glass

Vertex/fragment shader that creates a glass distortion effect using an albedo texture, normal map and a grab pass. In the vertex function, the vertices are converted from world to clip space, the grab texture UVs are calculated in screen space, albedo/normal texture UVs are calculated per usual, and Lambert lighting calculations are performed. Then in the fragment function, The normal map and a scale property are used to offset and distort the grab texture values. The resulting value is multiplied by the main texture’s colours.

Glass

Hologram.gif

Hologram

Surface shader that uses rim lighting to achieve a hologram effect. A rim light value is calculated based off the object’s normals and the camera view direction. The rim value is then used, along with a scaling property, to calculate the object’s emission and alpha values. Z writing is turned off to show the vehicles interior.