Search Unity

Normal Reconstruction and Triplanar Mapping - An Unhappy Combination?

Discussion in 'Shaders' started by amasinton, Apr 6, 2021.

  1. amasinton

    amasinton

    Joined:
    Aug 12, 2006
    Posts:
    138
    Is it possible to have normal reconstruction using partial derivatives (ddx/ddy) AND fully functioning Triplanar mapping of textures?

    Or am I just trying to be too clever?

    I can get the triplanar mapping to work in the X and Y axes but it just smears across the Z axis.

    Here is the look I'm going for (this example uses normal reconstruction and a texture with conventional UV mapping):


    And here is what happens with normal reconstruction and triplanar mapping:


    See how the texture smears across the end walls of the building (the Z axis)?

    The mesh has no normals or UVs - just verts, triangles, and vert colors.

    Am I expecting too much?

    I would appreciate any insight you might have. Thanks!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Yes, it is possible to use derivative based surface normals as the input for triplanar mapping. Can you show the code you're using? Or is this a Shader Graph?
     
  3. amasinton

    amasinton

    Joined:
    Aug 12, 2006
    Posts:
    138
    Thank you so much for the quick reply - it was just what I needed to encourage me to keep pushing on this! I think I solved it. (Amplify Shader Editor graph screenshot attached.)



    This is probably a hideously expensive shader?

    I worked through your excellent article on triplanar normal mapping - (I think I chose the least efficient option you provided). The missing piece, for me, was in my understanding of how to get the triplanar mapping to use the reconstructed normals. It took me all day to realize that the "World Normals" input on ASE's Cotangent Frame function would accept the reconstructed normals rather than the actual world normals. Figuring out what the triblend was and how to create it in the graph also took me some time (and is it even necessary?). But, my personal Eureka moment came when I finally understood that I could use the world space UVs as the actual UVs for the texture samplers. To anyone else, this would have been obvious - but it takes a while for me to figure these things out.

    Here it is working correctly on my test model (ignore the banded shading on the ends - that's poor shadow settings). The mesh has no normals, no tangents, no UVs; just verts, triangles, and vert colors. I'm pretty pleased. We'll see how it runs in-game applied to hundreds of meshes, of course ...


    Thank you again!
     
  4. amasinton

    amasinton

    Joined:
    Aug 12, 2006
    Posts:
    138
    So, it's been a while (3 years) aannndd ... the banding is back! (Which is not the desired effect.).

    The banding/smearing happens when an object gets batched. I'm still using the exact same shader as shown in the graph in the above post. That shader's world-space UVs seem to be working, but the dynamic batching seems to break that.

    Any ideas why dynamic batching would break world-space UVs and how to fix that?

    Thank you!
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Dynamic batching merges all batches meshes into world space. World space UVs will still work, but you’re more likely to have precision issues on batched meshes as you get further away from the world origin.