Hello everyone, this is my situation: I create a plane game object at runtime and then set up its material, something like this:
GameObject canvas = GameObject.CreatePrimitive(PrimitiveType.Plane);
...
Renderer renderer = canvas.GetComponent<Renderer>();
renderer.material.SetTexture("_MainTex", MyTexture);
renderer.material.EnableKeyword("_NORMALMAP");
renderer.material.SetTexture("_BumpMap", MyNormalMap);
renderer.material.EnableKeyword("_SPECULARHIGHLIGHTS_OFF");
This works when I debug my program in the editor, problem comes when I do the final build - I just can’t get “_SPECULARHIGHLIGHTS_OFF” to have an effect.
In the docs it says, “Use shader variant collections to prewarm shader variants, or to ensure that shader variants that are required at runtime but not referenced in a scene are not excluded (“stripped”) from your build.” So I created a shader variant collection and put it in my Resources folder. Then, in the inspector I added the Standard shader and clicked the “+” to open the “Add shader Standard variants to collection” menu. Here I selected my keywords “_NORMALMAP” and “_SPECULARHIGHLIGHTS_OFF” and clicked one of the shaders in the “Shader variants with these keywords (click to select):” list.
This way my normal map works in the final build, however specular highlights are still on.
Also: Is there a better way of creating the shader variant collection? In the docs it also says: “The Unity Editor can track which shader variants your application uses when it runs, and automatically create a shader variant collection asset that contains them.” However, when I export this shader variant collection and put it in my Resources folder, not even the normal maps work in the final build.
Help would be much appreciated