Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
2 captures
11 Jun 22 - 14 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 Raffin · Aug 12, 2015 at 08:37 AM · objectrendereralphatransparentopaque

Make an object transparent when below 1.0A, and completely opaque at 1.0A?

Hi, I didnt think this would be a difficult task or maybe I've just made myself confused but I am trying to fade an object and unless I'm misunderstanding I have to set the rendering mode to transparent. But I do not wish to see particles and other such things through the object when it is at 100% alpha. Is there a way where I can still lower the alpha and therefore make the object transparent but while at 100% the object is completely opaque?

Cheers.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by YoungDeveloper · Aug 12, 2015 at 08:39 AM

There's a actually a function which does exactly that in standart shader editor script. Download the source and look it up, I don't have the source on me right now.

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

Answer by Raffin · Aug 13, 2015 at 02:34 AM

Thanks for the help. I made it so that the shader is swapped whenever I need to drop the alpha below 1.0.

Also, when I built the game I needed to manually include the shader as I used Shader.Find() to replace the shader. Placing the downloaded shader from unity's download page inside "Assets/Resources" worked.

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

Answer by Eno-Khaon · Aug 13, 2015 at 02:44 AM

It sounds like you're looking for an attribute of a Transparent Cutout Shader. That said, if you're looking to make an alternative capable of doing both, the shader code could be approached with something like:

 tex.a = floor(tex.a);

This would take your texture's alpha value and reduce all fractions down to the nearest whole number, so anything less than 1 would instead be 0.

For any shader purely based around all-or-nothing transparency (i.e. cutout), however, you would be better off utilizing a proper transparent cutout shader instead. Those can instead be based instead around clipping pixels based on the alpha value.

 clip(tex.a - 1);
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 Raffin · Aug 14, 2015 at 04:31 AM 0
Share

Not quite, as I wanted the whole object to fade gradually from 100% opacity to 0%. But with the shader I needed; leaving the shader at 100% opacity would have a problem with the Z order of particle systems. So I made it that when the opacity drops below 100% the shader is swapped. Thanks for the help though.

avatar image saschandroid · Aug 14, 2015 at 06:48 AM 0
Share

I had a similar problem and didn't want to swap shaders, so I used this custom shader:

 Shader "Custom/diffuse_alpha" {
     Properties{
         _Color("$$anonymous$$ain Color", Color) = (1, 1, 1, 1)
         _$$anonymous$$ainTex("Base (RGB) Trans (A)", 2D) = "white" {}
     }
         SubShader{
         Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
         // Render into depth buffer only
         Pass{
             Color$$anonymous$$ask 0
         }
         // Render normally
         Pass{
                 ZWrite Off
                 Blend SrcAlpha One$$anonymous$$inusSrcAlpha
                 Color$$anonymous$$ask RGB
                 $$anonymous$$aterial{
                     Diffuse[_Color]
                     Ambient[_Color]
                 }
                 Lighting On
                 SetTexture[_$$anonymous$$ainTex] {
                         Combine texture * primary DOUBLE, texture * primary
                     }
             }
     }
     FallBack "Diffuse"
 }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Opaque to Transparent animation effect on a textured object (Lerpz)? 1 Answer

Blending and Decaying Alphas 0 Answers

How to make this image semi-transparent? 3 Answers

Strange alpha result 0 Answers

Transparent shader: final alpha value wrong 2 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