- Home /
Why is color multiplied with 2 in "Particles/Alpha Blended" shader?
This is how the fragment shader looks in the default Unity shader "Particles/Alpha Blended"(file name "Particle Alpha Blended.shader" in downloadable default shader zip):
Blend SrcAlpha OneMinusSrcAlpha
fixed4 frag (v2f i) : COLOR
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))));
float partZ = i.projPos.z;
float fade = saturate (_InvFade * (sceneZ-partZ));
i.color.a *= fade;
#endif
return 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord);
}
Why is final color multiplied with 2?
Colors are always multiplied by 2 in all the shaders. I asked this question myself a while ago and pretty much got the answer - that's what you do! However, somewhere, and I can't find where, I read an explanation a month or so ago. Wish I could fully remember what it was.
Anyhoo - multiply * 2 to look like any normal Unity shader
I can't really find any other default Unity shader which multiplies with 2? An example? I you somehow remember where you read that explanation, please share it.
Really- well they all do it internally if it's not a vertex/fragment program. I pretty much don't use the default shaders any more - so all $$anonymous$$e * 2.
Here's my forum question: http://forum.unity3d.com/threads/155099-Vertex-lit-shader-lighting-is-too-dark
Here's my answers question:
http://answers.unity3d.com/questions/333699/shader-lighting-is-too-dark.html
Answer by voldemarz · Mar 31, 2013 at 11:31 PM
Here's the answer by Aras on why everything is multiplied with 2:
Short answer to "why multiply by two?" - because in the EarlyDays, it was a cheap way to "fake" somewhat overbright light in fixed function shaders. And then it stuck, and it kind of dragged along.
The link in the second post by Jessy in that topic is broken, here's a working one http://www.quaddicted.com/engines/software_vs_glquake#overbright_lighting
I can't find a non-Particles built-in Alpha-Blend shader, will it be strange if using this shader for non-particle objects?
The categorization of these shaders under "Particle(s)" is just a compromise to simplify searching. The only "extra" thing differs these shaders from the others is multiplying the vertex color of the mesh to the final result (i.color in the frag shader passed down from vert shader, otherwise from semantic "COLOR"). Particle system changes vertex colors of its particle meshes which is the way you change particle color via any Particle shader, but this isn't exclusive to particle system. Trail and Line renderers do this as well so it makes sense to use Particle shader for these components as well. You can also use a script to change vertex color (c.f. API about $$anonymous$$esh.colors) in a game object with mesh filter+mesh renderer, for instance.
Yeah, I know it can be used for non-particle objects, but there's a *2, will this *2 be strange for non-particle objects?
I guess most of the other shaders with lighting already have the *2 killed.
Your answer
Follow this Question
Related Questions
Shader Doesn't Work On Android 1 Answer
Blending 3d planes with shader 0 Answers
Alpha Blending for projectors on transparent/cutout materials 0 Answers
Is it possible to change blend mode in shader at runtime? 1 Answer
Alpha Blending Problem 0 Answers