Procedural Stochastic Terrain Shader for Unity Terrain [Free on GitHub]

Update: I made a better and more simpler terrain shader here: GitHub - MichaelEGA/SuperSimpleTerrainShader: A super simple terrain shadergraph for unity's terrain system

Procedural Stochastic Terrain Shader

A simple procedural terrain shadergraph for Unity’s inbuilt terrain system

Get it here: GitHub - MichaelEGA/Procedural-Stochastic-Terrain-Shader: A simple procedural terrain shader for unity's inbuilt terrain system

Tested In: Unity URP 2022.2.2f1, Unity URP 2022.2.9f1

Version History

  • 01/02/2023 - Stochastic now seemlessly textures across neighbour terrains
  • 31/01/2023 - Added stochastic node option
  • 25/01/2023 - Initial commit

Features

  • Detail and Distance textures
  • Five detail textures (shore/sea, ground, mountain, peak, cliff)
  • Five distance textures (shore/sea, ground, mountain, peak, cliff)
  • Automatically transitions between textures according to height (shore/sea, ground, mountain, peak) and angle (cliff)
  • Tri-Planar for cliffs (to prevent texture warping)
  • Two different blend modes between detail and distance textures:
  1. Overlay blend (combines distance and detail textures together)
  2. Transition (seemlessly transitions between distance and detail textures according to camera distance)
  • Automatic generation of normal maps (it’s a bit hacky but it works)
  • Smoothness, Metallic, Normal and Color settings for each individual texture
  • Seemlessly transitions between normal, smoothness, and metallic settings based on camera distance
  • Use noise to variegate ground layer between ground texture and mountain texture
  • Doesn’t need splatmaps, great for procedural terrain
  • Optional stochastic (antitiling) node implemented







How To Use

  1. Add the shader and sub-shaders to your project
  2. Create a new terrain
  3. Create a material
  4. Set material shader to Terrain Shadergraph (Shader Graphs → Terrrain Shadergraph)
  5. Add the material to the terrain settings in the inspector
  6. Add your textures in the material inspector

Some Hints and Tips

  • The texture height is set relative the terrain texture height i.e. if your terrain is set 600 height all your texture heights will be lower than this.
  • Normals for distance textures need to be A LOT HIGHER than detail textures, a detail texture normal will normal be between 1-5 but distance texture will be between 2000-3000
  • For height textures (shore/sea, ground, mountain, peak) the scaling is as you would expect. For detail textures 2000 means that the texture will be tiled 2000 times across the terrain, whereas 1 for distance textures means that the texture will stretch to cover the whole terrain, BUT because of Tri-Planar cliff scaling is inverted so you will be typing in values like 0.005 or 0.1.
    I have included a bunch of examples in the ‘Examples’ folder. This folder is not essential and can be deleted.

Credits

Licensed under Apache 2.0

6 Likes

Just added a stochastic option (anti-tiling) using Junior_Djjr stochastic node.

Stochastic Off

Stochastic On

1 Like

Just updated the stochastic texturing so that it tiles over neighbour terrains and doesn’t leave a line.

Hi Michael, looks awesome. What would be the usage license on this?

Hello! Apologies, thought I had added that in: Apache License 2.0. Just added the LICENSE file to GitHub.

So go for broke basically… :slight_smile:

Honestly i don’t understand why but in this shader only work shore/sea and cliff the others seems to do absolutely nothing. I tried to manage some of distance parameter but it doesn’t change anything. What am i doing wrong or is this a bug?

Hey, thanks for trying. :slight_smile:

I’d need to see a picture of your set up to know if something is going wrong.

Have you tried using some of the sample materials the pack comes with?

I’ve made a new version that’s much more simpler. You could try that: GitHub - MichaelEGA/SuperSimpleTerrainShader: A super simple terrain shadergraph for unity's terrain system

1 Like

THis looks nice, thanks!!

1 Like

hey your graph is great but i didn’t find Stochastic option in your last verson. Did you remove it?9883890--1426086--upload_2024-6-11_14-10-34.png9883890--1426095--upload_2024-6-11_14-11-47.png

9883890--1426086--upload_2024-6-11_14-10-34.png
9883890--1426086--upload_2024-6-11_14-10-34.png

And I find the default paint texture doesn’t work anymore. which means can’t no more add detail manually.Is it posible to combine both procedual and manual both i wonder?

Hello, yes, the latest version has no stochastic shader. I wanted it to be very simple and barebones. You can still use the old version though with the stochastic though.

The main problems with the stochastic feature:

  • Couldn’t use real normal maps because I couldn’t get the stochastic texture to match the stochastic normal map… The normals were a cheap little trick at the end where I greyscaled the image and then read off that for the normal (so not a real normal map).
  • The workaround to get it to tile correctly across neighbour terrains was costly processing wise
  • Made the graph way to complex for people to edit and make their own changes

Unfortunately no. Currently there’s no way to blend the procedural shader graph and the painted texture. Or at least it’s beyond my skillset.

The main way to do this would be to write a function that measured the height of the terrain and then painted an alpha splat image with the correct colour, and then applied this back to the terrain. I’ve done this in the past, but it’s slow, so you wouldn’t do it for dynamic in game terrain. Better as an editor function to prepaint your terrain, before you touch it up with your own detailing.

It might also be possible to make the shader graph output colours to splatmap image and then apply this back to the terrains alpha map. Never tried it though.