Search Unity

Adding additional textures to StandardSpecular.shader results in missing Normal Map, others (iOS)

Discussion in 'Shaders' started by subatomic, Feb 12, 2016.

  1. subatomic

    subatomic

    Joined:
    Nov 13, 2014
    Posts:
    24
    Hi everyone,

    When I add 6 additional texture tex2D() samplers to Unity's standard shader, the Normal Map (and detail) I have on the Mesh's material visually disappears.

    My BuildTarget == iOS and editor Graphics Emulation == OpenGL ES 2.0, viewing in Editor and GamePlayer windows. I'm only using 3 of the 6 tex2D results, and my modified code lives in UnityStandardInput.cginc under Albedo() function. I'm using a modified StandardSpecular.shader. It's a skinned mesh, with my modified standard shader, with material slots set: Albedo, Specular, NormalMap, HeightMap, and my 6 custom ones.

    If I switch to Graphics Emulation == No Emulation, then I see the Normal Map (and others) again... No problems running on iPhone Device either, I see my NormalMap there no problem (player settings are OpenGL ES 3 first, then OpenGL ES 2)

    Any ideas?

    (as an aside, why isn't there an OpenGL ES 3.0 option under Edit/Graphics Emulation? for BuildTarget == iOS .... seems missing on Android also )


    StandardSpecular.shader changes:

    _F("F", 2D) = "zeroRGBA" {}
    _CustomColor("CustomColor", Color) = (0.68627451,0.090196078,0.0,1.0)
    _A("A", 2D) = "white" {}
    _B("B", 2D) = "bump" {}
    _ABScale("ABScale", Float) = 1.0
    _C("C", 2D) = "white" {}
    _D("D", 2D) = "bump" {}
    _CDScale("CDScale", Float) = 1.0
    _EScale("E", 2D) = "bump" {}
    _EScale("EScale", Float) = 1.0


    UnityStandardInput.cginc changes:

    sampler2D _F;
    half4 _CustomColor;

    sampler2D _A;
    sampler2D _B;
    float _ABScale;

    sampler2D _C;
    sampler2D _D;
    float _CDScale;

    sampler2D _E;
    float _EScale;


    half3 Albedo( float4 texcoords )
    {
    half3 albedo = _Color.rgb * tex2D (_MainTex, texcoords.xy).rgb;
    half3 aa = tex2D (_A, texcoords.xy * _ABScale).rgb;
    half3 bb = tex2D (_B, texcoords.xy * _ABScale).rgb;
    half3 cc = tex2D (_C, texcoords.xy * _CDScale).rgb;
    half3 dd = tex2D (_D, texcoords.xy * _CDScale).rgb;
    half3 ee = tex2D (_E, texcoords.xy * _EScale).rgb;
    half4 ff = tex2D (_F, texcoords.xy).rgba;


    #if _DETAIL
    #if (SHADER_TARGET < 30)
    //SM20:instructioncount limitation
    //SM20:nodetail mask
    half mask = 1;
    #else
    half mask = DetailMask(texcoords.xy);
    #endif
    half3 detailAlbedo = tex2D (_DetailAlbedoMap, texcoords.zw).rgb;
    #if _DETAIL_MULX2
    albedo *= LerpWhiteTo (detailAlbedo * unity_ColorSpaceDouble.rgb, mask);
    #elif _DETAIL_MUL
    albedo *= LerpWhiteTo (detailAlbedo, mask);
    #elif _DETAIL_ADD
    albedo += detailAlbedo * mask;
    #elif _DETAIL_LERP
    albedo = lerp (albedo, detailAlbedo, mask);
    #endif
    #endif

    float rAmt = 1.0f - clamp( ff.r, 0.0f, 1.0f );
    rAmt = 1.0f - rAmt * rAmt * rAmt * rAmt * rAmt * rAmt;
    float gAmt = 1.0f - clamp( ff.g, 0.0f, 1.0f );
    gAmt = 1.0f - gAmt * gAmt * gAmt;
    float bAmt = 1.0f - clamp( ff.b, 0.0f, 1.0f );
    bAmt = 1.0f - bAmt * bAmt * bAmt;
    float aAmt = 1.0f - clamp( ff.a, 0.0f, 1.0f );
    aAmt = 1.0f - aAmt * aAmt * aAmt;
    albedo = lerp(albedo, aa, gAmt);
    albedo = lerp(albedo, cc, bAmt);
    albedo = lerp(albedo, _CustomColor, rAmt);
    albedo = lerp(albedo, ee, aAmt);


    return albedo;
    }
     
    Last edited: Feb 12, 2016
  2. subatomic

    subatomic

    Joined:
    Nov 13, 2014
    Posts:
    24
    Unity keeps setting OpenGL ES 2.0 Emulation when in iOS or Android BuildType, even though I manually set Unity to "No Emulation", (under Edit / Graphics Emulation), Unity forgets this and resets back to OpenGL ES 2.0. Infuriating!

    Well, to deal with this, I implemented this editor script, which sets Unity editor back to No Emulation. If you're frustrated by this as much as I was, You're welcome. :) Now, the above problem I illustrate, never happens. And old ES 2.0 devices fall back to no normal map (which is crazy), but I dont care because those devices are old and going away...
     

    Attached Files: