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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Normal Strength Node not giving the same result as an equivalent value in the default Lit material

Discussion in 'Shader Graph' started by XANTOMEN, Sep 2, 2022.

  1. XANTOMEN

    XANTOMEN

    Joined:
    Dec 18, 2012
    Posts:
    41
    [EDIT: Not as bad as I thought but still a problem]

    My build: Unity 2021.3.6f1
    Shadergraph: 12.1.7

    Hi, I've tried to replicate the normal Lit material in URP with Shadergraph with the same properties and I've hit a standstill when getting to the Normal Strength, as to my surprise the Normal Strength Node function produces a different result to the same variable on the default Lit material, all else being equal.

    For reference, I'm exposing a NormalTexture variable (set to Mode Normal Map) and a Float1 variable BumpScale in the material, then following all the steps in the answer by @bgolus in this thread:
    https://forum.unity.com/threads/whe...t-normal-map-displacement-and-amount.1187551/

    (except setting the default texture to bump, as I don't find it anywhere, but I've tested the normals per se with and without texture and I have no differences when BumpScale/NormalStrength of both materials is 0 or 1). I have set the Sampler Texture node to Normal instead of Default and the Fragment Normal Space to Tangent.

    As far as I understand, I don't need to link anything to the Normal slot on the master's Vertex stack.

    Every other variable make no difference in between materials. Here are the results of changing the BumpScale/NormalStrength in both my material and a default Lit material, both using the same Base and Normal textures:

    URPShadergraphNormalBumpValueDifferences.png

    As we can see, 0 and 1 produce the same results, and interestingly also 10 (and the rest of values above 1, I've checked some). However in between 0 and 1 there are very noticeable differences.

    How come? Can someone confirm it isn't just me? Does anybody know a workaround or the exact function that default Lit is using, so I can replicate that instead of using the Normal Strength node?

    This should be enough to reproduce it if someone wants to (changed the smoothness to 0.5 on both materials to have some reflection and make it an easier comparison):

    URPShadergraphLit.jpg

    Thank you!
     
    Last edited: Sep 3, 2022
  2. XANTOMEN

    XANTOMEN

    Joined:
    Dec 18, 2012
    Posts:
    41
    [FALSE ALARM (Sort of) EDIT: Apparently not a false alarm. See bgolus' post]

    Okaaay, so it turns out that discrepancy is NOT PRESENT if instead of using a random texture as a Normal Map for both (setting it to be considered a Normal Map texture in Import Settings), I take an actual Normal Map texture that I had laying around and use that for both.

    While I would understand a bad normal map texture giving bad results, I had expected it would give the same bad results in both, but apparently it is not the case, and this is my error.

    I repeat to be extra clear: The "Bug" is not present if the Normal Texture in question is a correctly generated Normal Map texture.

    I do not know what a correct Normal Map texture is and what an incorrect one is for the purposes of this discrepancy, but my problem seems solved for now.
     
    Last edited: Sep 3, 2022
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,256
    The Normal Strength node and the Lit shader's normal strength are not calculated the same way. It might be more obvious with incorrect content, but it is still there with correctly setup normal maps too.

    This will match the way the URP Lit shader does normal strength.
    upload_2022-9-2_16-58-50.png
     
  4. XANTOMEN

    XANTOMEN

    Joined:
    Dec 18, 2012
    Posts:
    41
    Thank you @bgolus! Big fan, almost every single time I have a shader problem I find an answer already made by you. Will try this out for sure :) (Would do right now but my brain is crumbling from tiredness)

    EDIT: Works perfectly :)
     
    Last edited: Sep 3, 2022