Specular Map only works after expanding Shader in Editor

Hi,

In code i’m creating a Material with ‘Standard (Specular setup)’ shader.
I’m setting mainTexture, normalmap and specularmap and assign the material to a skinned mesh renderer.

Material combinedMat = new Material(Shader.Find("Standard (Specular setup)"));
            Texture2D myTexture = (Texture2D)Resources.Load(String.Format("Textures/Characters/{0}", texName));
            Texture2D myTextureNorm = (Texture2D)Resources.Load(String.Format("Textures/Characters/{0}", texNormName));
            Texture2D myTextureSpec = (Texture2D)Resources.Load(String.Format("Textures/Characters/{0}", texNormName.Replace("_normal", "_specular")));

            combinedMat.mainTexture = myTexture;
            combinedMat.SetTexture("_BumpMap", myTextureNorm);
            combinedMat.SetTexture("_SpecGlossMap", myTextureSpec);
           
            smr.sharedMaterial = combinedMat;

But specular map does not work after execution of code.
But if i expand the shader panel - while game is running in unity editor - the specular map suddenly is working correct.

Any suggestions ?

Thanks and greeting
Dinin

Hi @Dinin ,

You must enable the Standard Shader variant by using the EnableKeyword function. A different variant would be required if you start using a shader feature that was not initially in use by the material. For example assigning a Normal Map to a Material that did not have one, or setting the Emissive level to a value greater than zero, when it was previously zero.

The specific Keywords required to enable the Standard Shader features are as follows:
_NORMALMAP (Normal Mapping)
_ALPHATEST_ON (“Cut out” Transparency Rendering Mode)
_ALPHABLEND_ON (“Fade” Transparency Rendering Mode)
_ALPHAPREMULTIPLY_ON (“Transparent” Transparency Rendering Mode)
_EMISSION (Emission Colour or Emission Mapping)
_PARALLAXMAP (Height Mapping)
_DETAIL_MULX2 (Secondary “Detail” Maps (Albedo & Normal Map)
_METALLICGLOSSMAP (Metallic/Smoothness Mapping in Metallic Workflow)
_SPECCGLOSSMAP (Specular/Smoothness Mapping in Specular Workflow)

More info here: Unity - Manual: Using materials with C# scripts

Hi Jordi Bonastre,

Thanks - it worked.
But the enable keyword is ‘_SPECGLOSSMAP’ - without double C
Is also wrong in docs!

Thanks @Dinin ! I will create a bug for this issue.

Bug case 734660