drop-in replacement shader to add triplanar cliff shading to the default Unity terrain system (no plugins, vanilla terrain system, built-in 3D pipeline)
- this shader adds a single albedo + bump map as a general "cliff" texture, to tile along the X and Z planes
- as an optimization, I didn't add Y plane sampling, so technically this is more biplanar than triplanar
- as an optimization, I didn't add smoothness / metalness / occlusion maps
- instead, I sample some approximate smoothness / occlusion from the cliff's albedo
- I recommend against adding extra texture map slots, because you have to sample each texture map twice (once for X plane, once for Z plane) so it's a bit expensive
- for built-in 3D pipeline only (maybe you can modify it for HDRP / URP? but I'm not going to port it, sorry)
- made for Unity 2021.2+ but probably mostly works for Unity 2019.3+ / 2020.x? but haven't tested it, sorry
- probably doesn't work for pre-Unity 2019.3 because that's when Unity added terrain holes
- breaks on instanced terrain though (idk why)... PRs welcome
- put
TerrainSplatmapTriplanar.cginc
andTerrain-TriplanarStandard-FirstPass.shader
somewhere in your Unity/Assets/
folder - create a new Material that uses the
/Nature/Terrain/StandardTriplanar
shader - in your Terrain object settings, assign the material from step 2
- KNOWN ISSUE: you must disable Draw Instanced on the Terrain...
- configure cliff albedo + normal map in the material (not as a terrain layer)
This tries to replace as little as possible in the built-in Unity shaders. It's 2 files:
TerrainSplatmapTriplanar.cginc
is just a copy ofTerrainSplatmapCommon.cginc
from Unity 2021.2.0f1 built-in shaders, except it addsworldPos
andworldNormal
to theInput
shader struct. Unity's shader magic automatically populates IN.worldPos and IN.worldNormal variables if they're defined, so there's nothing else to do there.Terrain-TriplanarStandard-FirstPass.shader
is a modded version ofTerrain-Standard-FirstPass.shader
etc etc... I added various cliff texture properties, hooks into TerrainSplatmapTriplanar instead of default TerrainSplatmapCommon, and then applies triplanar mapping to the terrain mesh in thesurf()
function. You should probably tweak some of the hardcoded values.
When this inevitably breaks in future Unity versions (or if you need to add this to a terrain shader for an older Unity version) then you can easily patch this shader yourself by following those steps above, and copy and pasting the relevant sections. You'll need to know a little about shaders to do that. I recommend Catlike Coding's shader tutorials for a good intro to Unity shaders.
MIT
I'm happy if this helps you and I'm happy to share, but I'm not really going to maintain this repo or update it frequently
textures (not included) are from ambientCG.com