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
0
Question by Paulius-Liekis · Aug 14, 2013 at 10:49 PM · alphasurfaceshader

Changing alpha in Lighting Model has no effect

I have this line in my surface shader:

 #pragma surface surf MooBoo alpha

And then this lighting model:

 inline fixed4 LightingMooBoo (SurfaceOutput s, fixed3 lightDir, fixed atten)
 {
     fixed4 c;
     c.rgb = fixed3(1, 0, 0);
     // This has no effect whatsoever (1/0/0.5 - doesn't matter)
     c.a = 0;
     return c;
 }

The alpha returned from Lighting Model has no effect. It seems that the only thing affecting it is what I write into SurfaceOutput.Alpha in surface shader, but I can not modify that afterwards (based on lighting or something like that).

Anyone has an explanation?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Paulius-Liekis · Aug 18, 2013 at 03:15 PM

So far I figured out that yes, Unity ignores alpha from Lighting model if you use alpha blending. The way around it is to use regular vertex and pixel shaders. Something like this is sufficient in my case (you might need to calculate attenuation if you want shadows and lightmaps):

 half4 frag (v2f i) : COLOR
 {
     SurfaceOutput o;
     fixed4 tex = tex2D(_MainTex, i.uv);
     o.Albedo = tex.rgb * _Color.rgb;
     //o.Gloss = tex.a;
     o.Gloss = 1;
     o.Alpha = tex.a * _Color.a;
     o.Specular = _Shininess;
     o.Normal = i.normal;
     
     fixed4 col = LightingBlinnPhong (o, i.lightDir, i.viewDir, 1);
     return col;
 }
Comment
Add comment · 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

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

15 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 avatar image avatar image

Related Questions

Unlit Shader with alpha mask 2 Answers

Surface Shader - Emission 1 Answer

Shader with zwrite, shadows and alpha (special alpha) 2 Answers

Multiply Shader with Alpha 0 Answers

What happens when the alpha value is outside the 0..1 range in surface shader lighting models? 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