Search Unity

How to stop shader compiler applying Normalize to normals

Discussion in 'Editor & General Support' started by xiotex, Jun 20, 2012.

  1. xiotex

    xiotex

    Joined:
    Sep 26, 2010
    Posts:
    37
    I'm trying to use the normals part of the vertex stream for something else other than normals for some procedural animation. It all works fine on the PC version but the iOS version has completely different results and when I opened up the compiled shader I found this line:

    tmpvar_1 = normalize (_glesNormal);

    Is there some kind of command I can put into the Unity shader to stop the compiler from generating this line?
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    In CGPROGRAM block:
    Code (csharp):
    1. #pragma glsl_no_auto_normalization
    This will stop normalizing normals and tangents.
     
  3. xiotex

    xiotex

    Joined:
    Sep 26, 2010
    Posts:
    37
    Thanks!

    That worked a treat. Is this kind of thing documented anywhere? My searching skills failed me :(
     
  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Hmm good point; it was only mentioned in the realease notes of Unity 3.2.
     
  5. Lex-DRL

    Lex-DRL

    Joined:
    Oct 10, 2011
    Posts:
    140
    @Aras
    Bump.
    This compile directive was removed in the latest Unity versions. Is there any other way to stop Unity from normalizing mesh vectors?

    Since normal and tangent are the only vectors correctly transformed by Unity during batching, we literally have no other way to pass some arbitrary vectors to the shader other than sending them as normal/tangent.

    Also:
    Similarily, is there a way to stop Unity from normalizing these vectors when importing them from an FBX?

    Also #2:
    Is there a way to tell Unity to transform normal as a regular vector (non-uniform scale) when batching meshes for a specific shader?
    All three questions are actually about the same thing: how to pass multiple vectors to the shader and keep them properly transformed when batching is performed. So I guess it's OK to add the last two here, too.
     
    Last edited: Feb 13, 2018