Search Unity

is standard shader secondary map works for android?

Discussion in 'General Graphics' started by mangax, Apr 25, 2015.

  1. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    hello , i tried looking and googling for this but no answers.. :(

    am trying to use two normal maps on material and animate them with simple script..

    in editor, it works fine as expected, both normals showing up..

    but on android.. only the main normal is visible, while the secondary one is missing!

    is this a bug? or it is intended behavior for mobiles?
     
  2. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    hmmm... so only me having this issue?
     
  3. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    There are no detail normal maps on mobile with the Unity standard shader. It's an instruction limit issue so it's specifically excluded in the shader.

    From UnityStandardInput.cginc:
    Code (csharp):
    1.  
    2. #ifdef _NORMALMAP
    3. half3 NormalInTangentSpace(float4 texcoords)
    4. {
    5.     half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, texcoords.xy), _BumpScale);
    6.     // SM20: instruction count limitation
    7.     // SM20: no detail normalmaps
    8. #if _DETAIL && !defined(SHADER_API_MOBILE) && (SHADER_TARGET >= 30)
    9.     half mask = DetailMask(texcoords.xy);
    10.     half3 detailNormalTangent = UnpackScaleNormal(tex2D (_DetailNormalMap, texcoords.zw), _DetailNormalMapScale);
    11.     #if _DETAIL_LERP
    12.         normalTangent = lerp(
    13.             normalTangent,
    14.             detailNormalTangent,
    15.             mask);
    16.     #else              
    17.         normalTangent = lerp(
    18.             normalTangent,
    19.             BlendNormals(normalTangent, detailNormalTangent),
    20.             mask);
    21.     #endif
    22. #endif
    23.     return normalTangent;
    24. }
    25. #endif
     
  4. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    thanks alot for the answer!
    is it possible to actually override this? i need two normals for some "specific" scenarios
    i tried removing "!defined(SHADER_API_MOBILE)" and still it doesn't seem to work when built to android.
     
  5. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    It should work, but you might need to change the "SHADER_TARGET" check as well. Of course, there is a reason they are excluding it for mobile so you may run into the same instruction limit if you try to turn too many other features on as well.

    I did a quick and dirty test simply commenting out the conditional, and I didn't get any normals showing up at all. So it will take a bit more finesse than that; it's probably failing to compile and simply falling back to VertexLit. You could add your own define "FORCE_DETAIL_NORMALS" so you can force the detail normals on on and turn enough other features off so it still compiles. Shouldn't be too hard if you've done any shaders writing. Should just need to add a few conditionals in the right places, but you'll need to dig through the standard shaders a bit to figure out what features you can live without.
     
  6. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    thanks for the effort :)
    i tried commenting out shader_target .. but no success.. i think it is as you said, failing to compile..

    i think maybe its a good time to start making little shader for this..