Search Unity

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

Discussion in 'Assets and Asset Store' started by MichaelEGA, Jan 25, 2023.

  1. MichaelEGA

    MichaelEGA

    Joined:
    Oct 11, 2019
    Posts:
    40
    Update: I made a better and more simpler terrain shader here: https://github.com/MichaelEGA/SuperSimpleTerrainShader

    Procedural Stochastic Terrain Shader


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

    Get it here: https://github.com/MichaelEGA/Procedural-Stochastic-Terrain-Shader

    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
    - I used some custom height blending code by GrrrimReapz on Reddit: https://www.reddit.com/r/Unity3D/comments/pr6sld/height_blending_materials_in_shadergraph/
    - I implemented some of Snubber's ideas from his video on youtube: https://www.youtube.com/@Snubber18
    - I implemented Junior_Djjr stochastic node, which can be found here: https://github.com/JuniorDjjr/UnityProceduralStochasticTexturingNode
    - Textures in example files from textures.com

    Licensed under Apache 2.0
     
    Last edited: Feb 7, 2024
    Invertex, Wneee, TiagoB66 and 2 others like this.
  2. MichaelEGA

    MichaelEGA

    Joined:
    Oct 11, 2019
    Posts:
    40
    Just added a stochastic option (anti-tiling) using Junior_Djjr stochastic node.

    Stochastic Off


    Stochastic On
     
    Last edited: Jan 31, 2023
    Babajan likes this.
  3. MichaelEGA

    MichaelEGA

    Joined:
    Oct 11, 2019
    Posts:
    40
    Just updated the stochastic texturing so that it tiles over neighbour terrains and doesn't leave a line.
     
  4. Freiheit314

    Freiheit314

    Joined:
    Sep 20, 2021
    Posts:
    2
    Hi Michael, looks awesome. What would be the usage license on this?
     
  5. MichaelEGA

    MichaelEGA

    Joined:
    Oct 11, 2019
    Posts:
    40
    Hello! Apologies, thought I had added that in: Apache License 2.0. Just added the LICENSE file to GitHub.

    So go for broke basically... :)
     
  6. mahito2932

    mahito2932

    Joined:
    Nov 15, 2020
    Posts:
    115
    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?
     
  7. MichaelEGA

    MichaelEGA

    Joined:
    Oct 11, 2019
    Posts:
    40
    Hey, thanks for trying. :)

    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?
     
  8. MichaelEGA

    MichaelEGA

    Joined:
    Oct 11, 2019
    Posts:
    40
    DrMeatball likes this.
  9. DrMeatball

    DrMeatball

    Joined:
    Nov 21, 2021
    Posts:
    109
    THis looks nice, thanks!!
     
    MichaelEGA likes this.