Search Unity

Grass Geometry Shader Not Writing to Camera Depth Texture in URP

Discussion in 'Shaders' started by cajphrase, Jul 27, 2021.

  1. cajphrase

    cajphrase

    Joined:
    Apr 24, 2021
    Posts:
    12
    I'm trying to implement a grass shader into my URP project.

    My atmosphere is implemented as a post-processing effect, sampling the camera's depth texture. However, my grass does not appear to be getting written into the camera's depth texture, causing the atmosphere to appear on top of the grass.

    I've enabled a shadow pass on the grass shader and ensured it is being rendered in the Opaque queue (2000).

    I've tried a number of approaches based on a few tutorials, the below images show an implementation of Daniel Ilett's excellent stylised grass tutorial on youtube.


    Image of the grass showing the atmosphere being drawn over the top:
    upload_2021-7-27_11-12-27.png

    The depth texture from the same view showing the object is not rendering to it:
    upload_2021-7-27_11-14-24.png

    Any help would be appreciated, I feel like I've tried everything.
    If it helps, the geometry shader code is here: https://pastebin.com/x9f0e7Cp
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    daniel_ilett likes this.
  3. cajphrase

    cajphrase

    Joined:
    Apr 24, 2021
    Posts:
    12
    bgolus - you're a genius. I had found and tried the Depth Only pass, but it was the Depth Normals pass that did the trick.

    Thanks!