Search Unity

Question ShaderNode: Tangent Vector normalized?

Discussion in 'Shader Graph' started by Julian_Nementic, Dec 10, 2019.

  1. Julian_Nementic

    Julian_Nementic

    Joined:
    Jan 10, 2014
    Posts:
    9
    Hey all.

    i want to store some data in the tangents of a mesh. But it seems, that the TangentVector-node outputs the normalized Tangent value and not the value by itself. Can somebody explain me if this is intended and why?

    I think it would be much better to have the control over the tangents by myself and normalize it with a Node after I use the Tangent Vector node. Like it is now i do not have the option to get the raw data that is actually in the tangents of the mesh.

    Although I think it doesnt matter for this topic, here is which data we store in the tangents: A programmer of our team generates the smoothed normals of a mesh, so we cant use it for a outline (extrude the mesh position alonge the smoothed normals). The normals of our mesh have hard edges, so we cant just use them for the outlines. Image of my problemis attached.

    We are using Version 2019.2.6f1, with LightweightRenderPipeline.

    EDIT: Using lwrp Version 6.9.1 and also Shadergraph Version 6.9.1

    Thanks for any help!

    Cheers

    Julian
     

    Attached Files:

    Last edited: Dec 10, 2019
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    Looking at the shader code that's generated it would seem it was done to make the Node's own code (not the shader code it generates) simpler. The vertex shader always calculates the world space tangent (which is normalized), then the node converts that back into object space. This is convienient because it means the same code can be used in both the vertex and fragment shader since they both have the world space tangent.

    Curiously this is only in the LWRP & URP. The HDRP doesn't do this and the tangent node in object space mode is directly outputting the unmodified float3 from the tangent data. It also doesn't needlessly calculate and pass the world space tangent in the vertex shader and to the fragment shader when it's not needed which the LWRP does even if you don't need the tangent space.

    The only solution I can think of is to not use Shader Graph at all for this. The LWRP isn't going to get any more work done on it since it's been deprecated in favor of the Universal RP. If the outline shader is unlit, then there's nothing special you need to do to make a vertex fragment shader work perfectly well in the LWRP.
     
    Julian_Nementic likes this.
  3. Julian_Nementic

    Julian_Nementic

    Joined:
    Jan 10, 2014
    Posts:
    9
    Thank you very much for the explanation! I will write the shader by myself than. I hope shader graph is evolving fast in all pipelines. I love working with it just because its faster, but half of my shaders need features that are not yet implemented in Shader Graph. That makes using it sometimes very frustrating.