Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by fra3point · Mar 05, 2016 at 10:33 PM · shadershadersblendingalpha-channelblend

Alpha blended shader - Show only the first alpha

Hi! :)

I'm working with Render Textures and I'm stuck with the following problem: I have several overlapped transparent objects and my camera renders them on a texture...

alt text

...But what I want is to render only the alpha of the closest object (in this case, the white one).

I'm currently using this simple shader, and I'd like to modify it for doing what I wrote.

 Shader "Custom/TranspUnlit" {
      Properties {
          _Color("Color & Transparency", Color) = (0, 0, 0, 0.5)
          _MainTex ("Texture", 2D) = "white" {} 
      }
      SubShader {
          Lighting Off
          ZWrite Off
          Cull Back
          Blend SrcAlpha OneMinusSrcAlpha, One One
          Tags {"Queue" = "Transparent"}
          Color[_Color]
          Pass {
              SetTexture [_MainTex]{
                  combine texture * primary
              }
          }
      } 
      FallBack "Unlit/Transparent"
  }

Can someone help me? Thank you, all!

immy1.png (49.8 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fra3point · Mar 06, 2016 at 05:41 PM

Hello! I'm still trying doing this thing completely strange for me (I'm noob with shaders). I found that the problem could be the Blend SrcAlpha OneMinusSrcAlpha, One One line. That blend directive is for the normal additive alpha blending.

So, I changed that line with:

 ...
 BlendOp LogicalCopy
 AlphaToMask On
 ...

I don't know what LogicalCopy means, but the result is pretty good... At least for high alpha values. If alpha>128 everything is fine, else the alpha is not rendered at all. My shader looks like this, now:

 Shader "Custom/TranspUnlit/Closest Alpha Blend" {
      Properties {
          _Color("Color & Transparency", Color) = (0, 0, 0, 0.5)
          _MainTex ("Texture", 2D) = "white" {} 
      }
      SubShader {
          Lighting Off
          ZWrite Off
          Cull Back
          //Blend SrcAlpha OneMinusSrcAlpha, One One
          BlendOp LogicalCopy
          AlphaToMask On
          Tags {"Queue" = "Transparent"}
          Color[_Color]
          Pass {
              SetTexture [_MainTex]{
                  combine texture * primary
              }
          }
      } 
      FallBack "Unlit/Transparent"
  }

Any suggestions? :)

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 MTDues · Feb 03, 2018 at 11:29 AM

im having the same proplem too :/

have you found a way to solve this proplem ?

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 fra3point · Feb 05, 2018 at 08:06 AM 1
Share

@$$anonymous$$TDues I've never found a solution for the "show only closest alpha" problem, but I'll give this a new try in few days. I think I can do it. :)

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

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

Related Questions

Lerping normal maps in shadergraph 0 Answers

A Blend Shader That Uses Vertex Information 0 Answers

(using shader blending to) remove white background from an image at runtime 3 Answers

How to make a shader with multiple textures, one color for each texture? 0 Answers

How to modify depth blended shader for second camera/reflection projection? 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