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 TabuuForteAkugun · Apr 09, 2019 at 11:37 PM · shadersoverlayalpha channel

2 albedo textures with alpha on overlay texture

Hi everyone!

I am making a shader for multi-layered eye models with 2 different UV channels: one for the eye white and the other for the eye irises.

I'm stuck at figuring out how to keep the iris' alpha without affecting the alpha of the white or the entire mesh.

Basically, what I'm trying to say is: how do I make the eye iris act as an "overlay" on the eye white without wrecking the alphas.

Code:

 Shader "Custom/Smash Bros. Feud - Fighter Eyes Shader"
 {
     Properties
     {
         _WhiteColor ("Eye White Color", Color) = (1,1,1,1)
         [NoScaleOffset]_WhiteMainTex ("Main Eye White texture", 2D) = "white" {}
         [NoScaleOffset]_WhiteNrm ("Eye White normal map", 2D) = "bump" {}
         [Toggle(USE_PRM_MAP)]_UsePrm("If eye uses a PRM map, tick this on", Float) = 0
         [NoScaleOffset]_WhitePrm ("Eye White PRM map", 2D) = "white" {}
         [HideInInspector]_Roughness("", Range(0.5,1)) = 1
 
         _IrisTex("Eye iris texture", 2D) = "white" {}
         [NoScaleOffset]_IrisNrm("Eye iris normal map", 2D) = "bump" {}
 
         [NoScaleOffset]_EyeBlend("Splat Map", 2D) = "white" {}
 
         [NoScaleOffset]_MetalDiffuse("Metal texture", 2D) = "white" {}
         [NoScaleOffset]_MetalReflection("Metal Reflection Cubemap", Cube) = "" {}
         [HideInInspector]_MetalSpecColor("Metal Brightness", Color) = (1,1,1,1)
 
         _MetalTrans("Metal Blend Factor", Range(0,1.2)) = 0
         _EmissionColor("Flash Color", Color) = (0,0,0,1)
     }
 
     CGINCLUDE
         #define UNITY_SETUP_BRDF_INPUT RoughnessSetup
     ENDCG
 
     SubShader
         {
             Tags { "Queue" = "AlphaTest" "RenderType" = "TransparentCutout" "IgnoreProjector" = "True"}
             LOD 200
 
             Pass
             {
                 ColorMask 0
                 ZWrite On
 
                 CGPROGRAM
                 #pragma vertex vert
                 #pragma fragment frag
                 #pragma multi_compile_shadowcaster
                 #include "UnityCG.cginc"
 
                 struct v2f
                 {
                     float4 vertex : SV_POSITION;
                     float2 texcoord : TEXCOORD0;
                 };
 
                 sampler2D _MainTex;
                 fixed _Cutoff;
 
                 v2f vert(appdata_img v)
                 {
                     v2f o;
                     o.vertex = UnityObjectToClipPos(v.vertex);
                     o.texcoord = v.texcoord;
                     return o;
                 }
 
                 fixed4 frag(v2f i) : SV_Target
                 {
                     fixed4 col = tex2D(_MainTex, i.texcoord);
                     clip(col.a - _Cutoff);
                     return 0;
                 }
                 ENDCG
             }
 
             Pass
             {
                 Tags {"LightMode" = "ShadowCaster"}
                 ZWrite On
                 Cull Off
 
                 CGPROGRAM
                 #pragma vertex vert
                 #pragma fragment frag
                 #pragma multi_compile_shadowcaster
                 #include "UnityCG.cginc"
 
                 struct v2f
                 {
                     V2F_SHADOW_CASTER;
                     float2 texcoord : TEXCOORD1;
                 };
 
                 v2f vert(appdata_base v)
                 {
                     v2f o;
                     TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
                     o.texcoord = v.texcoord;
                     return o;
                 }
 
                 sampler2D _MainTex;
                 fixed _Cutoff;
 
                 float4 frag(v2f i) : SV_Target
                 {
                     fixed4 col = tex2D(_MainTex, i.texcoord);
                     clip(col.a - _Cutoff);
                     SHADOW_CASTER_FRAGMENT(i)
                 }
                     ENDCG
             }
 
             Blend SrcAlpha OneMinusSrcAlpha
             LOD 200
             ZWrite On
             // paste in forward rendering passes from Transparent/Diffuse
             UsePass "Transparent/Diffuse/FORWARD"
 
             CGPROGRAM
             // Physically based Standard lighting model, and enable shadows on all light types
             #include "UnityCG.cginc"
             #pragma surface surf Standard fullforwardshadows alpha:fade
             #pragma shader_feature USE_PRM_MAP
             #pragma target 3.0
 
             float4 _WhiteColor;
             sampler2D _WhiteMainTex;
             sampler2D _WhiteNrm;
             sampler2D _WhitePrm;
             sampler2D _IrisTex;
             sampler2D _IrisNrm;
             sampler2D _MetalDiffuse;
             sampler2D _EyeBlend;
             samplerCUBE _MetalReflection;
             half _MetalTrans;
             fixed _Cutoff;
 
         struct Input
         {
             float2 uv_WhiteMainTex;
             float2 uv2_IrisTex;
             float3 worldNormal;
             float3 worldRefl;
             INTERNAL_DATA
         };
 
         float4 _EmissionColor;
         float4 _MetalSpecColor;
         half _Roughness;
 
         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
         // #pragma instancing_options assumeuniformscaling
         UNITY_INSTANCING_BUFFER_START(Props)
         // put more per-instance properties here
         UNITY_INSTANCING_BUFFER_END(Props)
 
         float GetTransitionBlend(float blendMap, float transitionFactor)
         {
             if (blendMap <= (1 - transitionFactor))
                 return 0.0;
             else
                 return 1.0;
         }
         void surf(Input IN, inout SurfaceOutputStandard o)
         {
             fixed4 whited = tex2D(_WhiteMainTex, IN.uv_WhiteMainTex);
             fixed4 whiten = tex2D(_WhiteNrm, IN.uv_WhiteMainTex);
             fixed4 whitep = tex2D(_WhitePrm, IN.uv_WhiteMainTex);
             fixed4 irisd = tex2D(_IrisTex, IN.uv2_IrisTex);
             fixed4 irisn = tex2D(_IrisNrm, IN.uv2_IrisTex);
             fixed4 mtl = tex2D(_MetalDiffuse, IN.uv_WhiteMainTex);
             fixed4 change = tex2D(_EyeBlend, IN.uv_WhiteMainTex);
             float blend = GetTransitionBlend(1 - change.rgb, _MetalTrans);
 
             if (_MetalTrans > 0)
             {
                 #ifdef USE_PRM_MAP
                     o.Albedo = lerp(whited.rgb * whitep.b * _WhiteColor * irisd.rgb * 4, mtl.rgb * _WhiteColor, blend);
                     o.Normal = UnpackNormal(whiten);
                     float3 worldRefl = WorldReflectionVector(IN, o.Normal);
                     fixed4 ref = texCUBE(_MetalReflection, IN.worldRefl * worldRefl);
                     ref.a = whited.a;
                     o.Metallic = lerp(whitep.a, 0.1, blend);
                     o.Smoothness = lerp(((_Roughness - whitep.g) + (whitep.a * whitep.r)), ref.rgb + _MetalSpecColor, blend);
                     o.Emission = lerp(_EmissionColor.rgb, (_EmissionColor.rgb + ref.rgb) * _WhiteColor * _MetalSpecColor / 1.5, blend);
                     o.Alpha = 1;
                 #else
                     o.Albedo = lerp(whited.rgb * _WhiteColor * irisd.rgb * 4, mtl.rgb * _WhiteColor, blend);
                     o.Normal = UnpackNormal(whiten);
                     float3 worldRefl = WorldReflectionVector(IN, o.Normal);
                     fixed4 ref = texCUBE(_MetalReflection, IN.worldRefl * worldRefl);
                     ref.a = whited.a;
                     o.Metallic = lerp(0, 0.1, blend);
                     o.Smoothness = lerp(0, ref.rgb + _MetalSpecColor, blend);
                     o.Emission = lerp(_EmissionColor.rgb, (_EmissionColor.rgb + ref.rgb) * _WhiteColor * _MetalSpecColor / 1.5, blend);
                     o.Alpha = 1;
                 #endif
             }
             else
             {
                 #ifdef USE_PRM_MAP
                     o.Albedo = whited.rgb * whitep.b * _WhiteColor * irisd.rgb * 4;
                     o.Normal = UnpackNormal(whiten);
                     o.Metallic = whitep.a;
                     o.Smoothness = (_Roughness - whitep.g) + (whitep .a * whitep.r);
                     o.Emission = _EmissionColor.rgb;
                     o.Alpha = 1;
                 #else
                     o.Albedo = whited.rgb * _WhiteColor * irisd.rgb * 4;
                     o.Normal = UnpackNormal(whiten);
                     o.Metallic = 0;
                     o.Smoothness = 0;
                     o.Emission = _EmissionColor.rgb;
                     o.Alpha = 1;
                 #endif
             }
         }
         ENDCG
     }
     FallBack "Diffuse"
 }

In the screenshot you see, the iris overlaps the entire white eye, but I want it to do so with the iris' alpha channel. In simpler terms, I want an overlay texture with alpha channel over another texture that doesn't have alpha.

Thanks!

Eye iris' alpha channel won't work

screenshot-468.png (131.4 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

0 Replies

· Add your reply
  • Sort: 

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

178 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 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 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

Why does my video alpha appear shiny with custom shader? 1 Answer

overlaying 0 Answers

Recieve shadows on transparent material 0 Answers

Standard Cutout Double Sided? 0 Answers

Shader displaying with weird colors 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