Search Unity

Unity Terrain Billboard Shader 2019.3.7 (Standard)

Discussion in 'General Graphics' started by rotxyz, Nov 29, 2020.

  1. rotxyz

    rotxyz

    Joined:
    Mar 26, 2018
    Posts:
    7
    Hello,
    I'm making some small modifications to the Unity Terrain shaders to be able to use stencil buffers.
    I've downloaded the terrain shaders from the Unity archive and have started to turn them into custom shaders by changing the names (i.e. Custom/TerrainEngine/Splatmap/Diffuse-Base).
    I created a new material and used one of my custom terrain shaders for the landscape (as shown in blue), but I cannot figure out how to customize the shader for the billboarded trees/plants/grass that the 3D artist has drawn in.

    In the package I downloaded, I spotted 2 billboard shaders: BillboardTree & CameraFacingBillboardTree.
    I also updated the code at the bottom of FirstPass.shader to point to my updated billboard shaders
    Code (CSharp):
    1. Dependency "AddPassShader"    = "Custom/TerrainEngine/Splatmap/Diffuse-AddPass"
    2. Dependency "BaseMapShader"    = "Custom/TerrainEngine/Splatmap/Diffuse-Base"
    3. Dependency "BaseMapGenShader" = "Custom/TerrainEngine/Splatmap/Diffuse-BaseGen"
    4. Dependency "Details0"         = "Custom/TerrainEngine/Details/Vertexlit"
    5. Dependency "Details1"         = "Custom/TerrainEngine/Details/WavingDoublePass"
    6. Dependency "Details2"         = "Custom/TerrainEngine/Details/BillboardWavingDoublePass"
    7. Dependency "Tree0"            = "Custom/TerrainEngine/BillboardTree"
    Is there something that I'm missing?
    Thanks++ for any tips
     
  2. rotxyz

    rotxyz

    Joined:
    Mar 26, 2018
    Posts:
    7
    On further investigation, it looks like the trees in this scene were created with Unity's tree creator tool & I can simply make a copy of the tree creator shaders.
    I still have 1 unresolved issue tho: when the trees are very far away, they are drawn as a billboard that doesn't use the albedo color values (red & blue in this case) that are set in the shader. Does anybody know which shader is rendering this billboard?

    Thank you!
     
  3. rotxyz

    rotxyz

    Joined:
    Mar 26, 2018
    Posts:
    7
    On even further investigation, it looks like I also need to update terrain "details" shader to enable stencil testing. It's not clear to me how to make sure this shader is used when drawing terrain.
     
  4. c_james

    c_james

    Joined:
    Jun 23, 2016
    Posts:
    8
    Did you ever figure out how to apply the stencil to trees? I have it working for the high LOD trees but not the low LOD billboard trees despite the code being almost identical in the two shaders.