Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Resolved Vertex normal broken

Discussion in '2020.2 Beta' started by DekkerC, Oct 23, 2020.

  1. DekkerC

    DekkerC

    Joined:
    Oct 7, 2017
    Posts:
    17
    Hi,

    I'm using ShaderGraph 10.1.0 with the HDRP pipeline.
    I'm writing a terrain engine which works great except for it's vertex normals.
    It only shows primary and secondary full colors (green,red,yellow,green,blue,etc). In other words only the 6 perfect sides of a cube. The normal doesn't lerp between the colors (like a sphere does).

    In the end I tried breaking things up into basics and created a sine generator that continuously rotates the normal. The normal only 'clicks' between extremes.

    Also tried rotating on multple axis.Same result with different colors.

    Does any one have an idea why this happens?

    See my shader graph (no normal set for the fragment part)
    upload_2020-10-23_16-45-54.png
    upload_2020-10-23_16-51-53.png

    upload_2020-10-23_16-52-14.png
    upload_2020-10-23_16-53-12.png
     
  2. DekkerC

    DekkerC

    Joined:
    Oct 7, 2017
    Posts:
    17
    Testing further with a sphere and a cube that aren't instanced.
    Still same problem.
    All kinds of normal artifacts.

    Notice the line artifact on top of the sphere when I'm also using normal textures. It's almost never changes value!
    upload_2020-10-31_8-20-46.png
    Normal mapped it looks like:
    upload_2020-10-31_8-25-35.png

    Also it looks like the normals can only be rotated a few degrees instead of the full 360 you need.
    In the next image. The right side will never turn blue, so the normal never changes to that direction:
    upload_2020-10-31_8-39-56.png

    When I remove the normal map texture: The entire orb starts to dance with solid colors (like expected = good). But the plane still only does a few colors (only 90 degree increment angles? = wrong). They both have the SAME basic shader!
    The dark purple is the sphere, the lighter purple behind it is the plane. The cube on the right is without the shader and shows world normals.
    upload_2020-10-31_8-44-28.png
    The shader with texture normal.
    upload_2020-10-31_8-46-9.png
    Remove the normal & basecolor texture to get the effect without normal texture (can't post any more images).
     
  3. DekkerC

    DekkerC

    Joined:
    Oct 7, 2017
    Posts:
    17
    I can't replicate the problem on non-instanced meshes anymore. They all work fine now (tested a bunch of different shapes, including cube and sphere)

    But I solved it for instanced meshes.
    In the following thread there is a post about how to set unity_WorldToObject: https://forum.unity.com/threads/drawmeshinstancedindirect-example-comments-and-questions.446080/

    With HDRP unity_WorldToObject can't be set and used directly. Probably because it's no longer a value but now an algorithm.
    When you force setting it, it messes up shadergraph in some way. It breaks overriding the vertex normal. The normal will only show the normal like it's rounded by angles of 90 degrees.

    Lot's of examples force setting unity_WorldToObject by doing #undef unity_WorldToObject. But that is unwise.
    When I removed that line from the shader I got: Use_Macro_UNITY_MATRIX_I_M_instead_of_unity_WorldToObject error instead. You know what, it's right;).

    The solution however looks to be simple.
    DONT #undef NOR SET unity_WorldToObject.

    Then unity_WorldToObject and all related macro's: https://github.com/Unity-Technologi...ary/ShaderVariablesMatrixDefsLegacyUnity.hlsl will work like magic.

    Setting unity_ObjectToWorld = _TRS[id] looks to work fine though.

    Edit: To clarify. As far as I know this is only a problem for HDRP. Maybe also URP.