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 fabbemannen · May 02, 2013 at 07:04 PM · shadertransparencyalphadefaultfading

Transparent/Diffuse-shader always transparent by default (alpha)?

I'm currently learning Unity and I've had some problems with the Transparent/Diffuse-shader. I made a script that, using iTween, fades objects when you go behind them and for that I needed a shader that supports transparency.

This one was recommended, but when I apply it to my test-objects they act like the alpha is set to a low amount, even though it isn't mentioned anywhere in the script or settings (most of the objects aren't even related to the script, they just share the same texture which is one of Unity's default ones). If I use the normal diffuse-shader there aren't any problems, but I can't use the script either (due to the lack of transparency).

How can I make the objects stay at 255 alpha by default, or alternatively, how can I change all the affected objects at startup? I've already tried with one and got it to work, but that would require scripts for all the similar objects which seems pretty unnecessary.

alt text

First question and post here btw, so hi me!

Comment
Add comment · Show 4
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 Loius · May 02, 2013 at 07:08 PM 1
Share

Your textures either have alpha information or you've got it created by default in the texture in Unity. Click the texture and check out its settings.

avatar image fabbemannen · May 02, 2013 at 07:27 PM 0
Share

After some random testing, it's on all the default textures and even without a texture it's still the same. I'm not sure how I can check if it gets created by default in the texture though

avatar image dorpeleg · May 02, 2013 at 11:47 PM 0
Share

Did you try clicking the color selector and make sure the alpha is at 255?

avatar image fabbemannen · May 03, 2013 at 10:10 AM 0
Share

If you mean the small color-selection above the texture (in the bottom-right corner of the pic), then yes. I can't find any other type of color-selector (like I said, I started using Unity just lately)

1 Reply

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

Answer by CHPedersen · May 03, 2013 at 11:17 AM

I downloaded the source for the built-in shaders some time ago, and can reveal that Transparent/Diffuse is implemented like so:

 Shader "Transparent/Diffuse" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
 }
 
 SubShader {
     Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
     LOD 200
 
 CGPROGRAM
 #pragma surface surf Lambert alpha
 
 sampler2D _MainTex;
 fixed4 _Color;
 
 struct Input {
     float2 uv_MainTex;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
     o.Albedo = c.rgb;
     o.Alpha = c.a;
 }
 ENDCG
 }
 
 Fallback "Transparent/VertexLit"
 }

As you can see, the color that ends up getting written is the product of the color you select in the editor, and the color that gets read from the texture. They get multiplied together:

 fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
 o.Albedo = c.rgb;
 o.Alpha = c.a;

I can see in your screenshot that your _Color variable is all white and alpha 1. (It would have a partially black bar underneath if you had its alpha lowered). So the texture color alone is actually displayed, because it gets multiplied with (1,1,1,1) in the shader. Therefore, the only other option, as @Loius suggested, is that your texture has alpha values below 1 in its pixels. It is the only other place an alpha value < 1 could possibly come from.

Open your texture in a bitmap editor (Photoshop, GIMP, Paint(dot)Net) and examine its alpha channel.

Comment
Add comment · Show 2 · 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 fabbemannen · May 03, 2013 at 11:44 AM 0
Share

I tried to make a new texture completely and it seems like it's solved now. I still don't get how I even had the problem when I didn't have a texture attached, but I can live with that.

Thanks for the answer and detailed explanation

avatar image CHPedersen · May 03, 2013 at 11:53 AM 0
Share

The Properties section in the shader is where the editor-accessible values are defined, i.e. the $$anonymous$$ain Color and the texture. The stuff to the right in each definition after the = is the default value. That is, the color is "born" as white until the user changes it, and if the user doesn't supply a texture, it uses some built-in standard one called "white". There are other built-in textures one can choose; they're defined on this page:

http://docs.unity3d.com/Documentation/Components/SL-Properties.html

When I test it, my objects become solidly colored if I don't supply a texture, and set the Color's alpha to 1. This indicates that Unity's builtin "white" texture has alpha = 1 written in all its pixels. Why it behaved differently on your machine shall remain a mystery, it seems. :)

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

Render transparent material without double occlusion 2 Answers

Cant get Alpha Channel to Work with Custom Shader 1 Answer

Add transparency to this shader? 0 Answers

Sorting issues within single transparent mesh 1 Answer

What does the "alpha is transparency" setting actually do? 1 Answer


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