Search Unity

Geometry Grass Shader: Add a pass to draw the ground.

Discussion in 'Universal Render Pipeline' started by Felyana, Aug 25, 2021.

  1. Felyana

    Felyana

    Joined:
    Apr 30, 2020
    Posts:
    5
    Hello everyone,

    I am trying to make a geometry grass shader (using tesselation) to apply on a Unity Terrain. The grass part is working quite well, but I cannot manage to add a ground surface under it.

    Right now I was using a custom mesh for the terrain, so I added two different materials but that's not an optimum solution. And I also prefer to use the Unity Terrain.

    Is it possible to add this in one shader ? Because right now the material is only using the first Pass. Either the ground surface or the grass itself.

    I don't know if this helps but my shader has a structure like this for now: (I can provide further explanation later on)



    Code (CSharp):
    1.     SubShader
    2.     {
    3.         Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
    4.         LOD 100
    5.         Cull Off
    6.         Pass
    7.         {
    8.             HLSLPROGRAM
    9.             #pragma vertex vert
    10.             #pragma fragment frag
    11.             #pragma require geometry
    12.             #pragma geometry geo
    13.             #pragma require tessellation tessHW
    14.             #pragma hull hull
    15.             #pragma domain domain
    16.  
    17.             vertexInput vert(vertexInput v)
    18.             {
    19.                 return v;
    20.             }
    21.  
    22.  
    23.             float4 frag(geometryOutput i, real facing : VFACE) : SV_TARGET
    24.             {
    25.               return float4(1, 1, 1, 1); #to simplify
    26.             }
    27.          }
    28.  
    29. +Additionnal pass for shadows
    30.      }

    Geo_grass_terrain.PNG
     
  2. Felyana

    Felyana

    Joined:
    Apr 30, 2020
    Posts:
    5
    So I just learned that URP does not support multi pass shaders...

    I found an alternative solution to have 2 passes in URP shader, it might help someone:
    in the first pass I use the Tags {"LightMode" = "UniversalForward"}
    and in the 2nd one no tag so the two get rendered.

    I found this on a post from 1 or 2 years ago, so maybe there is a better alternative for this right now.