How do I fade a material within WebGL?
Hi!
I'm trying to use a Color linear interpolation (LERP) to fade from a texture to a transparent version of itself within WebGL. I'm attempting this by switching from the Cutout Rendering Mode to Fade using the following switch statement and using the LERP to control the alpha.
case BlendMode.Fade:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
This worked with version 5.6.1 when exporting to WebGL, but doesn't work with my 2018.2.1 installation (it also still works within the Editor).
I'm looking for some help about things I might be doing wrong, or that may have changed in the intermediate versions.
Thanks in advance
Just thought I'd illustrate my problem a bit more clearly. Here is my fading script working within the Editor:
And here is what it looks like when in WebGL (when it should be faded a similar amount):
Any ideas or suggestions would be greatly appreciated. Cheers!
Answer by Fleer_CTC · Nov 04, 2018 at 09:50 PM
The issue was that I didn't have a 'Fade' version of the material being compiled with the build. The solution was to put a new, empty material (set to Fade) within the Resources folder, to make sure it was bundled with it everytime.
Your answer
Follow this Question
Related Questions
Does the Unity Scaling settings for a model impact the texture detail? 0 Answers
Is there any way to make a gradient within unity?,Is there any way to make a gradient? 1 Answer
Material property change not working in WebGL but working in Unity 0 Answers
About the temporary file save destination in webGL 0 Answers