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 Cal2 · Sep 11, 2014 at 03:06 AM · shaderalphasurface shader

Alpha Shader not working with obj collision

I've been trying to learn shader code, and am having trouble getting the alpha transparency to work correctly when the mesh is inside another one. In the picture below, the ball is completely inside the box and is being rendered like it is in front of the box when the alpha is off. When the alpha is on both are visible but it still looks like the ball is in front of the square. At some angles when the alpha is off the ball is not visible.

How can I stop this from happening?

![alt text][1]

 Properties {
         _MainColor ("Main Color", Color) = (1, 1, 1, 1)
         _RimColor ("Rim Color", Color) = (0, 0, 0, 1)
         _RimPower ("Rim Power", Range (-1, 10)) = 3.0
         _AlphaRange ("Alpha Range", Range (0, 1)) = 1
         _RimRange ("Rim Range", Range (.1, 2.5)) = 0
         
         
     }
     SubShader {
         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }  
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Lambert alpha
 
         struct Input {
             float4 color : Color;
             float3 viewDir;
         };
 
         float4 _MainColor;
         float4 _RimColor;
         float _RimPower;
         float _AlphaRange;
         float _RimRange;
         
         void surf (Input IN, inout SurfaceOutput o) { 
                                                     
             
             IN.color = _MainColor;
             half rim = _RimRange - saturate(dot(normalize(IN.viewDir), o.Normal));         
             o.Emission = _RimColor.rgb * pow(rim, _RimPower);                    
             o.Alpha = _AlphaRange; 
             o.Albedo =  _MainColor;
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }


shaderproblems.jpg (23.3 kB)
shaderproblems.jpg (23.3 kB)
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 RafalDorsz · Sep 11, 2014 at 11:15 AM

Have you tried playing with setting various blending types? I don't know what result exactly you want, but it seems like this is what you should look into.

http://docs.unity3d.com/Manual/SL-Blend.html

Here are some examples:

Transparency

Order-Independent Transparency

Comment
Add comment · Show 1 · 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 Cal2 · Sep 11, 2014 at 07:01 PM 0
Share

Thanks for the links, one of them had another link to a page on depth testing.

To be more clear, the problem that I was having was, if obj-1 was inside obj-2. obj-1 was being rendered as if it was in front of obj-2. even though the "Queue"="Transparent" fixed that for objs that are just infront/behind each other.

for anyone else who comes across this problem I inserted this code above the CGPROGRA$$anonymous$$

 Pass {
         ZTest LEqual 
         Color$$anonymous$$ask 0
         }

A $$anonymous$$or problem is that it doesn't work if the camera is too close on the objs, but that's not something I need.

Edit actually, when the alpha is on, the objs that are inside of it don't show (2nd edit I should clarify they don't show at certain angles but on some angles they do). I'll add an update if I figure out how to fix that.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Shader Help: Adding transparency to a shader. 2 Answers

Luminance to Alpha 0 Answers

Problem with alpha coloured shader 1 Answer

Fade-In/Out shadows for a specific object 0 Answers

transparent mode does not work at alpha=255 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