Search Unity

Question Getting colour of background at bottom of mesh in a performant way

Discussion in 'Shaders' started by soiledparsley, Jul 12, 2021.

  1. soiledparsley

    soiledparsley

    Joined:
    Jun 17, 2021
    Posts:
    2
    I'm working on a shader for grass that takes on the base colour of the terrain that it is sitting on. My grass is created using a bunch of 8x8 sprites instantiated on start. My terrain has a simple toon shader applied to it. I have it working without instancing/batching using a grabpass. This works but is very slow. I've been trying to work on instancing but I don't know how to get the bottom position of the grass when it is batched.

    It should look like this:


    But it looks like this:


    It's because I use:
    • positionBottomMiddle = UnityObjectToClipPos(float4(0.5,0,0,1)) to get bottom middle position of grass
    • then use ComputeScreenPos(positionBottomMiddle) to get that position on the screen
    but when batched this breaks because each blade of grass gets shaded with the same position (only the vertex position can be passed into UnityObjectToClipPos when batched and turn out the same way as un-batched from my experimentation)

    Is there another way I can get the bottom position? Maybe another way I can shade the grass entirely?

    Any help is appreciated