- Home /
How to put opacity in mobile/diffuse
Please someone give me an idea .
You might want to review this thread
http://forum.unity3d.com/threads/133188-Why-is-there-no-built-in-alpha-shader-for-Unity-mobile
FWIW, from that: "But there is a reason why there is no AlphaTest shader for mobile included. On mobile devices it is absurdly heavy and will kill your framerate very fast. So you should always try to avoid alpha testing as much as possible. "
I think CORE Framework has some mobile optimized shaders, all vert/frag shaders so they don't do the unnecessary calculations of a surface shader. This comes with a $50 price tag I think, but you would be helping out the developer who is a one man show and he is super helpful if you ever have questions about his package
Answer by SeveneduS · Oct 11, 2017 at 09:06 AM
I have find a bit ugly (in hard code meaning) solution but in my case it was fastest solution.
public float fadeoutSpeed = 0.1F;
bool fadeOutDone = false;
Shader transparentShader, diffuseShader;
void Start()
{
fadeOutDone = false;
transparentShader = Shader.Find("Legacy Shaders/Transparent/Diffuse");
diffuseShader = Shader.Find("Mobile/Diffuse");
StartCoroutine(FadeOut());
}
IEnumerator FadeOut()
{
float a = 0F;
var allChildren = GetComponentsInChildren<Transform>();
List<SkinnedMeshRenderer> mRenderList = new List<SkinnedMeshRenderer>();
int mLen = allChildren.Length;
for (int mr = 0; mr < mLen; ++mr)
{
if (allChildren[mr].gameObject.GetComponent<SkinnedMeshRenderer>())
{
var m = allChildren[mr].gameObject.GetComponent<SkinnedMeshRenderer>();
m.material.shader = transparentShader;
m.material.color = new Color(1, 1, 1, 0);
mRenderList.Add(m);
}
}
while (!fadeOutDone)
{
if (a < 1.0F)
{
foreach (var child in mRenderList)
{
child.material.color = new Color(1, 1, 1, a);
}
}
else
{
fadeOutDone = true;
for (int mr = 0; mr < mLen; ++mr)
{
if (allChildren[mr].gameObject.GetComponent<SkinnedMeshRenderer>())
{
var m = allChildren[mr].gameObject.GetComponent<SkinnedMeshRenderer>();
m.material.shader = diffuseShader;
mRenderList.Add(m);
}
}
}
a += Time.deltaTime * fadeoutSpeed;
yield return new WaitForSeconds(fadeoutDelay);
}
yield return null;
}
Your answer
Follow this Question
Related Questions
Png icon iphone render 1 Answer
Calling A Function When A Variable Changes? Help 1 Answer
is there a way to replace script-made object to a custom one? 1 Answer
Photon Errors? 1 Answer