Standard Shader Emissive Warning?
tl;dr -- Why do I get the warning in the picture below?
===================================================
I'm following was marked as answered here: http://answers.unity3d.com/questions/914923/standard-shader-emission-control-via-script.html
However, there is one unspoken caveat. Apparently GI doesn't update on it's own, as observed here: http://answers.unity3d.com/questions/920023/change-materials-emission-scale-at-runtime.html
It turns out, that setting the "_EmissionColor" on the Standard Shader is not enough, we must also set the emissivity via DynamicGI.SetEmissive (although I see other posts using DynamicGI.UpdateMaterials: http://answers.unity3d.com/questions/919499/dynamicgisetemissive-not-working.html)
I have an empty room, with a cube that has a magenta emissive light. Technically, everything is visually correct (the surroundings receive emitted light), so I have nothing to worry about, except that I have the following warning on my editor, which is bugging me:
Searching for this specific error only yield one result in my Google searching: http://forum.unity3d.com/threads/unity-5-0-shader-assigning-movietexture-in-emission-map-slot-problem.309680/
I can only guess that this is due to not properly activating the shader variant related to Emissive lighting? I read about this here: http://docs.unity3d.com/Manual/MaterialsAccessingViaScript.html Granted, I'm not satisfying requirement #2, but as per the doc, I did enable the keywords and it should be enough:
Using the keywords above is enough to get your scripted Material modifications working while running in the editor.
My code below:
public class IlluminatingWall : MonoBehaviour
{
[SerializeField]
private Color wallColor;
private Material wallMaterial;
private readonly string shaderEmissiveName = "_EmissionColor";
private readonly string shaderKeywordFeatureEmission = "_EMISSION";
private const float enabledIntensity = 1.0f;
private const float disabledIntensity = 0.0f;
MeshRenderer myrend;
// Use this for initialization
void Start()
{
Shader.EnableKeyword(shaderKeywordFeatureEmission);
wallMaterial = GetComponent<MeshRenderer>().sharedMaterial;
wallMaterial.EnableKeyword(shaderKeywordFeatureEmission);
myrend = GetComponent<MeshRenderer>();
}
// Update is called once per frame
void Update()
{
if (Input.GetButton("Fire1"))
{
Illuminate();
}
else
{
Dim();
}
}
public void Illuminate()
{
wallMaterial.SetColor(shaderEmissiveName, wallColor * enabledIntensity);
DynamicGI.SetEmissive(myrend, wallColor * enabledIntensity);
}
public void Dim()
{
wallMaterial.SetColor(shaderEmissiveName, wallColor * disabledIntensity);
DynamicGI.SetEmissive(myrend, wallColor * disabledIntensity);
}
}
I even saw someone doing the same on a youtube tutorial here: https://youtu.be/h5GFoI38DOg?t=1136
I don't think I'm doing anything different from everyone else, so I'm guessing this has to do with some Material configuration?
Answer by kilogold · Jan 22, 2016 at 01:23 PM
Found the answer!
Turns out that aside from Unity's documentation telling you that you can indeed manually activate the Standard Shader variants, the warning will still occur on the editor because it seems to deactivate the variant the moment the Emissive value is set to (or hits) zero.
I tried my same algorithms without ever setting to zero, and everything worked.
I need to figure out a more appropriate way to deal with disabling emissive, but the core of this mystery is solved!
Answer by Grisnak · Feb 05, 2016 at 07:33 PM
Can confirm, this worked for me! I was trying to manipulate the emission value on the shared material as well so I'd only have to do it once for multiple game objects. Initializing it as close to 0 fixed the issue. Really ridiculous