Custom Shaders

Environment Shaders

Experimenting with environmental effects, I made a custom skybox shader with adjustable components for dynamic skies. Additionally, I made a gradient fog shader that adds depth and atmosphere, utilizing the camera's depth texture for a fullscreen shader.

Gradient Fog

To make the fog shader work, I used custom renderer feature with a full screen shader render pass. Unity already has a built-in full screen pass renderer but in my version 2022.3.12f1, the built in full screen pass does not have the "Before Skybox" injection point , which sets the order of the shader in the render queue. And I didn't want this fog shader to effect the skybox so I used a custom full screen pass. You can find it here


After setting the render pass, we need to set the pass material with a full screen shader graph in which we will use the depth texture to position the gradient. We split the alpha value of the gradient to set its intensity as desired, and we lerp the blit source and the gradient which is the final albedo.

Custom Shaders

Here are some combinations:

Custom Shaders


Custom Shaders

Skybox

For skybox I made 5 components. Main gradient , sun, sun halo, horizon halo and stars. All have their relative values to play around with.

The main gradient is easy as it's used alot. 3 colors with their blend multipliers.

Custom Shaders


The sun and sun halo use the main light direction node to match the directional lights angle. Sun can be changed to the moon with setting the correct values.

Custom Shaders


The horizon halo can help add the additional horizon feeling that the main gradient sometimes lack.

Custom Shaders


The stars use powered voronoi noise get random white dots, with an additional noise to give more detail. Also towards the top of the skybox the UV's get stretched and that makes the stars look stretched. To fix that we do some tiling in the top side of the skybox.

Custom Shaders


Here are some combinations:

Custom Shaders


The values I used for the sunset preset:

Custom Shaders


Combined together you can get a lot of different visuals. This could be turned into a dynamic day/night cycle system with setting/lerping the values in whichever way you want.

Sources I used;

https://grrava.blogspot.com/2018/08/stylistic-fog-from-firewatch-with.html https://blog.camposanto.com/post/112703721804/this-blog-post-is-an-in-detail-explanation-of-a

Back to Logs