Jump to content

Isaac
 Share

Recommended Posts

Hi Everyone!

In the past few months we have worked on optimising a scene for a VR game, which included needing a better running terrain shader than what Unity currently uses.

We first made a shader in URP that can handle 4 terrain layers, then moved onto making a version that can handle 8 terrain layers. What's unique about this shader is the fact that we were able to reduce the number of texture samples per terrain layer - going from Unity's default of 3 (BaseColor, Normal, MaskMap) down to 2 layers. So it's a third of the cost of what a typical Unity terrain shader would utilise. For example, a terrain with 8 layers using Unity's system would require 24 textures (that's 8 layers * 3 textures per layer), whilst our shader would only need 16 textures (that's 8 layers * 2 textures per layer).

Another area of improvement was reducing the amount of data tied to the terrain mesh required for the shader to sample. We were able to remove the need of vertex normals on the terrain mesh, as well as removing the need for UVs.

With some initial testing in RenderDoc, our new shader (with 8 terrain layers) was able to save 11 textures (Unity's had 32, ours had 21). We were also able to save 10 variables used in one of the constant buffers (Unity's had 50, ours had 40). Through testing this early development shader 3 times in Renderdoc I was able to infer that this current version of our optimised shader runs about +9.47% faster than Unity's. It will still need some more testing in different scenarios and devices to conclude any other differences. 

 

The aim of this shader is to have an indentical look with Unity's terrain shader, but just run a little faster:

Unity's Terrain Shader:

NewTerrain_A_Unity_Terrain.JPG.b43960ef331cc0ecf5a925ce5400cb90.JPG

Our Optimised Shader:

NewTerrain_A_NewShader.JPG.c578e80914cf5ddbaa049f4cf5f979f7.JPG

Unity's Terrain Shader:

NewTerrain_B_Unity_Terrain.JPG.fcd9af8bde1603da88989485013c2e7b.JPG

Our Optimised Shader (still needs some work on getting the normals correct!):

NewTerrain_B_NewShader.JPG.11d24707edcf5b86557f10a4a4ac429d.JPG

Let us know what you think about this approach!

 

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

I think this is really useful! Unity's terrain has always been known to be slightly "un-optimized", I think one of the biggest areas of improvement if you wanted to ever build your own terrain system would be easier access to modifying terrain details e.g trees and grass from within the game. Trying to use unity trees that are interactable can be a challenge as you don't want to permanently remove them from the terrain data so you usually either have to keep it memory or save it to a file and replace it later on.

Link to comment
Share on other sites

 Share

  • Tell a friend

    Love Unity 3D World & Game Creation Tools - Canopy - Procedural Worlds? Tell a friend!
  • Interesting Articles

    1. 42

      GeNa Pro City Generator

    2. 1

      World Creator + Gaia

    3. 1

      Gena decorator??

    4. 1

      Objects spawning at unexpected position in segmented scene.

    5. 1

      GeNa pro shows error while loading.

×
×
  • Create New...