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 Hamesh81 · Jan 29, 2014 at 12:38 PM · shaderalphainvisiblequeuecolormask

How can I control a shader's colormask with a texture?

I have a skinned clothing mesh parented to a character. Based on the alpha channel of the texture certain parts of the clothing mesh get hidden. I'm creating a shader for making the clothing "invisible". The shader is queued to geometry but renders transparent and with a colormask A; which means that when the transparency of the clothing mesh is lowered it also hides the character geometry underneath it, preventing the invisible clothing from making the character nude!

The problem is that at the moment the entire clothing mesh is made invisible not just the clothing rendered by the diffuse map. This makes parts of the characters body geometry which should be poking through, strangely hidden. What I need is to have the invisible parts controlled by the alpha channel of the texture i.e. all the parts that are black in the alpha channel should not be invisible, and the rest should. I'm not sure if that means controlling the render queue or the value of the colormask? My only guess is that 2 separate passes would be needed, so that the invisible and visible parts of the same geometry could be rendered differently.

Here is the shader code:

 Shader "Player/Invisible" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
     _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
     _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
     _BumpMap ("Normal Map", 2D) = "bump" {}
 }
  
 SubShader {
     Tags { "Queue"="Geometry" "IgnoreProjector"="False" "RenderType"="Transparent" }
     LOD 400
  
 //For getting rid of Z-fighting
 Pass {
         //ZWrite On
         ColorMask A
         //AlphaTest GEqual 0.01
     }
  
 CGPROGRAM
 #pragma surface surf BlinnPhong alpha
 #pragma exclude_renderers flash
  
 sampler2D _MainTex;
 sampler2D _BumpMap;
 fixed4 _Color;
 half _Shininess;
  
 struct Input {
     float2 uv_MainTex;
     float2 uv_BumpMap;
 };
  
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
     o.Albedo = tex.rgb * _Color.rgb;
     o.Gloss = tex.a;
     o.Alpha = tex.a * _Color.a;
     o.Specular = _Shininess;
     o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
 } 
 ENDCG  
 }
  
 FallBack "Transparent/Bumped Diffuse"
 }
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
Best Answer

Answer by Hamesh81 · Jan 31, 2014 at 01:26 AM

As I'd suspected, the solution was to create a shader with two separate passes: one pass using an AlphaTest Greater and another pass with an AlphaTest Less. Only the pass with the AlphaTest Less had the colormask applied which made sure that anything the texture's alpha channel had as opaque was rendered with the colormask and made everything behind it invisible, while anything transparent showed objects behind it.

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 Coldcalifornian · Feb 12, 2014 at 12:42 PM 0
Share

I have been trying to do the same thing unsuccessfully for a couple of days. Can you post your final code? I would very much appreciate 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

19 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

Related Questions

Shader Graph Increment vector1 1 Answer

Alpha Shader not working with obj collision 1 Answer

Changing material color´s alpha in self iluminated shader 1 Answer

Scripting Shader: How to control Alpha with slider? 1 Answer

Objects Not Visible In Low End Computer. (Shader Error) 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