Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by voldemarz · Mar 31, 2013 at 04:26 PM · shaderalphablending

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?

Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Mar 31, 2013 at 04:46 PM 0
Share

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

avatar image voldemarz · Mar 31, 2013 at 05:09 PM 0
Share

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.

avatar image whydoidoit · Mar 31, 2013 at 06:40 PM 0
Share

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.

avatar image whydoidoit · Mar 31, 2013 at 06:41 PM 0
Share

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

avatar image whydoidoit · Mar 31, 2013 at 06:42 PM 0
Share

No idea on that reference I'm afraid.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image macrod · Jul 28, 2017 at 07:59 AM 0
Share

I can't find a non-Particles built-in Alpha-Blend shader, will it be strange if using this shader for non-particle objects?

avatar image ifurkend macrod · Jul 28, 2017 at 08:35 AM 0
Share

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.

avatar image macrod ifurkend · Jul 28, 2017 at 09:29 AM 0
Share

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?

avatar image macrod · Jul 28, 2017 at 08:01 AM 0
Share

I guess most of the other shaders with lighting already have the *2 killed.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges