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

Question Transform Object -> Tangent Direction not working correctly

Discussion in 'Shader Graph' started by AlanRStagner, Dec 3, 2019.

  1. AlanRStagner

    AlanRStagner

    Joined:
    Jan 9, 2018
    Posts:
    11
    I'm trying to work on procedural planet rendering. My heightmaps are generated as a cubemap to eliminate pole distortion among other things, and I generate a planet-space normal map from that as well (the final heightmap is stored as RGB normal, A height).

    In a shadergraph, I then use the surface normal to sample from this cubemap and retrieve the normals, ensure they are normalized, and then convert them to tangent space so I can plug it into a PBR Master node.

    This works perfectly fine when my sphere is at unit scale. However, if I scale the object, the normals get distorted. This is on the latest ShaderGraph at the time of writing (7.1.5), the latest Universal Render Pipeline (7.1.5), and Unity 2019.3.0b12.

    Here's what the unit sphere looks like:

    planet_lit.png

    And then if I make the sphere smaller (normals increase in intensity):

    planet_lit2.png

    And if I make the sphere larger (normals decrease in intensity):

    planet_lit3.png

    For reference, here's the result of just plugging the sampled normals directly into the Color input of an Unlit Master node (this doesn't visually change regardless of the sphere's scale, which is as I would expect):

    planet_normals.png
     
  2. AlanRStagner

    AlanRStagner

    Joined:
    Jan 9, 2018
    Posts:
    11
    For reference, the part of my graph which samples the normal cubemap and extracts the normals from the RGB channels (it is an ARGBFloat RenderTexture):

    planet_normalsampler.png

    And the part of my graph that normalizes it and transforms it into tangent space and plugs it into the PBR Master node (also the other Unlit node which directly displays the sampled normals, which I used to switch back and forth for testing):

    planet_normalsampler_2.png