Search Unity

Question Getting normal vector in decal graph

Discussion in 'Shader Graph' started by TerabyteTim, Jun 6, 2019.

  1. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    115
    I am attempting to create a decal shader that can project a caustic effect onto my scene.
    I want this caustic effect to disappear at steep angles, so that the sides and undersides of objects do not show the projection

    However, it appears the "Normal Vector" node in a decal shadergraph does not give the normal vector of the vertex hit by the decal projector.
    I have tested both the normal vector and vertex positions nodes, and they both appear to give results other than the vertex hit (I am unsure what normal/position they are returning)

    Does anybody know of a way to get the normal or position of the vertex hit by a decal projector? Either via creating my own master node, HLSL custom node, or in shadergraph itself.
     
  2. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    115
    Anybody know about this? I'm still having trouble creating decal projector effects in the HDRP because of not being able to get the vertex normals
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    You’re trying to use the Shader Graph to make decal shaders? Yeah, that won’t work. Shader Graph explicitly doesn’t support making decal shaders, or really anything but shaders for basic geometry. The Normal Vector node is the projector’s own mesh’s geometry normal, which is kind of useless since you need the gbuffer normal. I don’t know how you’d access that from a Shader Graph.

    Here’s what the HDRP shaders look like.
    https://github.com/Unity-Technologi...elines.high-definition/Runtime/Material/Decal
     
  4. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    115
    Why does ShaderGraph provide a Decal master node if it is not meant to be used?

    Thank you for the link though, I'll look at editing those shaders to create me own decal effect.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    I guess I'm wrong, they did add an official decal master node. I can't see any way to get access to the gbuffer normals though, so it might not be implemented yet.
     
  6. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    115
    Yeah the decal master node acts very strangely, hopefully they get it working before the full release. Projectors are a pretty common function that I'm sure many people will need.

    For now I'll just accomplish the effect with a shader on the objects themselves. Thank you for the help!
     
  7. skilfuldriver

    skilfuldriver

    Joined:
    May 20, 2015
    Posts:
    19
    There's some useful information about the decal system hidden away in this post

    https://forum.unity.com/threads/deferred-decals-built-in-with-new-srp.514296/#post-3382777

    I've had some limited success using a decal shader graph for footprints. I can make them behave and look as I want but the main problem is not having unique per projector material properties without instantiating the material and breaking the batching. It becomes very slow very quickly.