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

Resolved Vertex normal broken

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

  1. DekkerC


    Oct 7, 2017

    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)

  2. DekkerC


    Oct 7, 2017
    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!
    Normal mapped it looks like:

    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:

    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.
    The shader with texture normal.
    Remove the normal & basecolor texture to get the effect without normal texture (can't post any more images).
  3. DekkerC


    Oct 7, 2017
    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:

    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: 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.