This week our guest writer is Justus, our code guru and shader wizard. Take it away Justus!

Why bother making cool shaders? Why don’t you just go crazy with post-processing like everyone else?

 

Because we can’t. With Cave Digger 2 our first target platform is Oculus Quest. Quest is a standalone mobile device, and as such, it uses a rendering type called Tiled Rendering, which is really efficient for most rendering, but causes full screen effects like post-processing to be really slow. These effects will add significant fill-rate overhead and should almost always be avoided. Find out more about how Quest does Tiled Rendering here.

 

So in order to make fancy looking effects like custom fog, color grading or bloom, while maintaining stable 72 fps on Oculus Quest, we have to make the effects with shaders and particle effects.

 

But shaders are hard to make 🙁

 

It’s true that writing shaders can be annoying even if you’re an experience programmer. Cg/HLSL syntax is different from most programming languages. However there is a easier way. The trick is to use a node based editor like Amplify Shader or Shader Graph. You can find plenty of helpful guides and tutorials online. Also Amplify Shader has lots of good example shaders for you to learn from. This allows you to make shaders much faster, however the catch is that the shaders might not be as optimized as they would be if programmed by an experienced graphics programmer

 

 

Amplify Shader view of CD2 Gem shader. Cel Shaded lighting and Custom Fog are is done in a custom functions, which makes them more easy to reuse.

So what does it do?

 

 

*Slaps the roof of Cave Digger 2 Lit shader*

This bad boy has a custom fog that uses a cubemap for color. It uses a cell shaded lighting that’s similar to Breath of the Wild. It can do triplanar texturing and stochastic texturing.

 

 

Also we have a custom Gem Shader for making those loots look shiny and tasty.

 

 

How to make it work

To handle controlling the shader settings I created a scriptable object called Atmosphere and also created Atmosphere Manager to manage them

 

 

A scriptable object helps to quickly make different atmospheres for different areas. It currently controls the ambient lighting color and fog density.

 

 

 

The Fog cubemap is just a color gradient texture that uses the Latitude-Longitude Layout. Colors of the cubemap get mapped around the player as the colors of the fog.

Future plans

There are plans to expand the Atmosphere manager to make it control more things in the enviroment. Some of the plans are:

  • Better control lighting
  • Weather effects
  • Clouds
  • Custom ambient sounds
  • Using custom skyboxes (now it’s tied to the fog cubemap)
  • Areas with custom fog

-Justus Pousi

 

 

 

Random development quote: “Kapitalismi kuuluu meidän sieluun. Meidän täytyy internoida kapitalismi.“