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 · Dec 05, 2013 at 06:47 AM · shadertexturematerialmultipleoverlay

How can I add another "layer" to my shader?

I am developing a multiple diffuse texture shader where multiple textures are overlayed over the top of one another. I've studied the builtin decal shader to see how to overlay one texture over the top of another, but now I can't work out how to overlay a third, fourth etc over the top of that. Here is my shader code:

 Shader "Player/Human Skin 2" {
 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
     _SkinTex ("Skin Texture (RGB)", 2D) = "white" {}
     _TattooTex ("Tattoo Texture (RGBA)", 2D) = "white" {}
     _BeardTex ("Beard Texture (RGBA)", 2D) = "white" {}
     _AlphaMap ("Transparency", 2D) = "white" {}
     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.1
     _BumpMap ("First Normal Map", 2D) = "bump" {}
     // Slider to control fading between normalmaps
     _BumpMapSlider ("Normal Slider", Range (0, 1)) = 0
     // Second normal map
     _BumpMap2 ("Second Normal Map", 2D) = "bump" {}
 }
 
 SubShader {
     Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
     LOD 400
     
 CGPROGRAM
 #pragma surface surf BlinnPhong alphatest:_Cutoff
 #pragma exclude_renderers flash
 #pragma target 3.0
 
 sampler2D _SkinTex;
 sampler2D _TattooTex;
 sampler2D _BeardTex;
 sampler2D _AlphaMap;
 sampler2D _BumpMap;
 fixed4 _Color;
 half _Shininess;
 // Remember to add your properties in here also. Check ShaderLab References from manual for more info
 float _BumpMapSlider;
 sampler2D _BumpMap2;
 
 struct Input {
     float2 uv_SkinTex;
     float2 uv_TattooTex;
     float2 uv_BeardTex;
     float2 uv_BumpMap;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     half4 c = tex2D(_SkinTex, IN.uv_SkinTex) * _Color;
     half4 tattoo = tex2D(_TattooTex, IN.uv_TattooTex);
     half4 beard = tex2D(_BeardTex, IN.uv_BeardTex);
     c.rgb = lerp (c.rgb, beard.rgb, beard.a);
     o.Albedo = c.rgb * _Color.rgb;
     o.Gloss = c.a;
     o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_SkinTex).r;
     o.Specular = _Shininess;
     // Read values from _BumpMap and _BumpMap2
     fixed3 normal1 = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
     fixed3 normal2 = UnpackNormal(tex2D(_BumpMap2, IN.uv_BumpMap));
     // Interpolater between them and set the result to the o.Normal
     o.Normal = lerp(normal1, normal2, _BumpMapSlider);
     
 }
 ENDCG
 }
 
 FallBack "Transparent/Cutout/Bumped Specular"
 FallBack "Transparent/Cutout/VertexLit"
 }

I cannot get the third texture to show and I suspect it may be something to do the the combining of the alpha channels for each texture. I have considered doing a new pass but I'm trying to make the shader work all in one pass to limit drawcalls. Any suggestions as to how I could add the next layers?

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
1
Best Answer

Answer by tanoshimi · Dec 05, 2013 at 07:15 AM

Are you trying to add _TattooTex over the top of _BeardTex? If so, try simply adding the following line at line 49:

 half4 beard = tex2D(_BeardTex, IN.uv_BeardTex);
 c.rgb = lerp (c.rgb, beard.rgb, beard.a);

 // Add this line
 c.rgb = lerp (c.rgb, tattoo.rgb, tattoo.a);

 o.Albedo = c.rgb * _Color.rgb;
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 Hamesh81 · Dec 05, 2013 at 09:35 AM 0
Share

Champ, that was it! Thanks

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

17 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

Related Questions

Texture Layer help. 0 Answers

Multiple materials on same object 0 Answers

Overlay texture on sprite 0 Answers

How can i get mixed texture from one shader and set it for another object with another shader? 0 Answers

Materials are colored differently on rotated objects 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