Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Unity 2022.2 is now available as the latest Tech release.
    Dismiss Notice
  3. We are making some changes to the DOTS forums.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

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:
    9
    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:
    11,840
    daniel_ilett likes this.
  3. cajphrase

    cajphrase

    Joined:
    Apr 24, 2021
    Posts:
    9
    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!