Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug World Space Decal Depth Issue

Discussion in 'Shader Graph' started by OliverVSmith, Jun 18, 2020.

  1. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    Hello,
    We're trying to make a Decal Shader in HDRP 7.4.1 (Unity 2019.3.8) that can be projected onto terrain and the UV's be in worldspace (so we can seemlessly merge dirt splats underneath spawned objects).
    However it appears that there is something wrong with the Depth.

    We're unsure if this is a bug, or a flaw in our Shadergraph? Any help much appreciated.

    Shadergraph
    upload_2020-6-18_1-3-47.png

    Example
     

    Attached Files:

  2. Shaunyowns

    Shaunyowns

    Joined:
    Nov 4, 2019
    Posts:
    328
    Hey there, I'll see if I can get this post looked at so you can get a response!
     
    OliverVSmith likes this.
  3. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    Thanks Shaun.
    Like I said, not totally sure it's a bug... but we think we're doing everything correctly.
     
  4. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    Bumping, not heard anything for a month.. really hoping someone can give us some help here.
    Running out of time
     
  5. ben-spencer

    ben-spencer

    Unity Technologies

    Joined:
    Dec 2, 2019
    Posts:
    7
    Hi Oliver. Sorry about the delay.

    Just a quick sanity check: what's the expected outcome when you overlap two decals like this? Are you expecting the depth impostor to behave more consistently regardless of the viewing angle?
     
  6. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    Hi Ben, thanks for getting back.

    The expected outcome here is for the projector, or two projectors, to seamlessly tile across eachothers space, over the top of the meshes they are projected onto (worldspace UV'ing essentially).

    There should not to be what effectively looks like a cube the size of the projector cut into a mesh it is projected onto. They do merge together fine, but they also "cut" into meshes and do not project simply onto the top of them
     
  7. ben-spencer

    ben-spencer

    Unity Technologies

    Joined:
    Dec 2, 2019
    Posts:
    7
    The projectors only "cut" into the geometry when you increase the Z size parameter though, right? What ought to be happening when that parameter is increased?
     
  8. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    Correct but in line with how the projectors work by default, this shouldn’t happen at all. We don’t want any “cutting” effect, and instead for the projector decal to projector onto a surface.

    We can’t find a way to get a world-uv effect whilst projecting just onto a surface.
     
  9. ben-spencer

    ben-spencer

    Unity Technologies

    Joined:
    Dec 2, 2019
    Posts:
    7
    Hi Oliver,

    I managed to reproduce the issue that you've been having. You're correct: this isn't the expected behaviour. The bug has actually already been flagged, so the good news it will be fixed in HDRP version 9.0.

    If you're unable to upgrade your project to Unity 2020.x, there might be a workaround that will get you most of the way there. With a bit of shader graph hacking, it's possible to reconstruct the world space coordinates using the view direction, scene depth and camera position nodes. This solution depends on the depth buffer so it isn't as reliable as the native position node, but it could be worth a try. Let me know if you need any help setting this up.
     
  10. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    Hi Ben,

    We're a little hesitant to upgrade from 19.4 as we're approaching launch.
    If you could give us some pointers/sample node/code for the shadergraph world space co-ordinates that would be really appreciated!

    Oliver
     
  11. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    Made some progress in two directions, but it's still not quite working
    1.
    upload_2020-10-13_10-33-13.png
    2.
    upload_2020-10-13_10-33-43.png
     
  12. ben-spencer

    ben-spencer

    Unity Technologies

    Joined:
    Dec 2, 2019
    Posts:
    7
    Try using the Screen Position node to drive the Scene Depth node. Does that fix it for you?
     
  13. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    Unfortunately no real change. I've uploaded the a video to show you the results.


    upload_2020-10-14_10-28-1.png
     
  14. ben-spencer

    ben-spencer

    Unity Technologies

    Joined:
    Dec 2, 2019
    Posts:
    7
    I'm sorry that this didn't work for you.

    The encoding used by the depth buffer varies depending on the render pipeline, so it's likely that your shader node isn't receiving the linear (true) depth value but rather a remapped version of it. I'll try and find out what this mapping is likely to be, but in the meantime it might be worth verifying that your graph inputs are consistent with what you would expect.