Search Unity

Resolved Applying WorldSpace normal map properly

Discussion in 'Shaders' started by carcasanchez, Jun 3, 2020.

  1. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    Hello there,
    I am having trouble with world space normals. I am constructing and impostor system (simulating a 3d mesh onto a plane that billboards), and I am having cool results, but there's a thing that bugs me.

    Due to design aspects, I am capturing the normals in World Space. As far as I have checked, the capturing is correct, having an aspect like:
    upload_2020-6-3_13-51-38.png

    Applying the normal map gives cool results in general:
    upload_2020-6-3_13-53-14.png
    (yes, those are planes oriented to the camera)

    But there is a case that gives wrong results: when the light directions is exactly pointing from above, they get completely black.
    upload_2020-6-3_13-54-23.png


    This error is something I think I have seen before when working with World Space maps, but I cant lay my finger exactly on what operation I am missing here.
    As far as I know, the only thing required to use WS Normal Mapas are that vertex normals and tangent should be aligned to the object axis at all times (which in this case is normals should be pointing in the same direction of the characters)
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Looks like the bitangent isn't being calculated?
     
  3. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    Could be. I have been working on a non-instanced version of impostors, and I have managed to achieve good results just by flipping the normal z axis, and not applying any transforms to normal and tangent.
    upload_2020-6-5_10-56-38.png
    This confirm that the textures are properly generated, and that the general process is correct overall.
    I will compare both ways carefully (instanced and non-instanced) to see were it fails.
     
  4. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    Solved! It was, indeed, that the bitangent was not calculated properly.
    I didn't know the Tangent variable was storing the bitangent direction in its fourth component, and I was setting it to 0. That was causing strange behaviours in lighting.
    After calculating all elements for the tangent, I set the tangent.w manually to -1, and works nice.