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
1
Question by Ony · Feb 03, 2012 at 06:52 PM · shadermaterialdecal

Help with this shader please?

I am using the following skin shader in my game. It's the regular Unity skin shader from the wiki that I've modified a bit, and I also added two decal layers to it. Everything works great so far, but...

In my game the user can change the main color of the shader to tint the skin different shades. That also works fine, but what I would like to do is make sure the final decal layer stays the color that it is in its texture, rather than be tinted with the rest of the shader.

In other words, the second decal layer in my game is generally white, but when I use the _Color channel to tint the object, the second decal layer turns that color as well, and I'd like for it to remain white.

Can anyone tell me how to do that with this shader? I've tried several things but none work yet.

 Shader "Skin for Unity 3/Bumped w- Spec+Decal" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
     _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
     _BumpMap ("Bump (RGB)", 2D) = "bump" {}
     _RimTex ("Rim ramp (RGB) Fresnel ramp (A)", 2D) = " grey" {}
     _WrapTex ("Wrap ramp (RGBA)", 2D) = "black" {}
     _SpecMap ("Spec map (RGB)", 2D) = "white" {}
     _DecalTex ("Decal (RGBA)", 2D) = "black" {}
     _DecalTex2 ("Decal_2 (RGBA)", 2D) = "black" {}
 }
  
 SubShader {
     Tags { "RenderType" = "Opaque" }
     LOD 400
     
 CGPROGRAM
 #pragma surface surf BumpSpecSkin
 
 uniform float4 _Color;
 uniform float _Shininess;
 uniform sampler2D _MainTex;
 uniform sampler2D _WrapTex;
 uniform sampler2D _RimTex;
 uniform sampler2D _BumpMap;
 uniform sampler2D _SpecMap;
 uniform sampler2D _DecalTex;
 uniform sampler2D _DecalTex2;
 
 struct MySurfaceOutput {
     half3 Albedo;
     half3 Normal;
     half3 Emission;
     half Specular;
     half Gloss;
     half3 GlossColor;
     half Alpha;
 };
 
 half4 LightingBumpSpecSkin (MySurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
     // rim factor
     float rimf = dot(s.Normal, viewDir);
     half4 rim = tex2D (_RimTex, rimf.xx);
     
     half3 h = normalize( lightDir + viewDir );
     
     // This is "wrap diffuse" lighting.
     // What we do here is to calculate the color, then look up the wrap coloring ramp so you can tint things properly
     half diffusePos = dot(s.Normal, lightDir) * 0.5 + 0.5;
     half4 diffuse = tex2D (_WrapTex, diffusePos.xx);
     diffuse.rgb *= rim.rgb * 4;
     
     float nh = saturate( dot( h, s.Normal ) );
     half spec = pow( nh, s.Specular ) * s.Gloss;
 
     half4 c;
     c.rgb = (s.Albedo + s.GlossColor * spec * rim.a) * diffuse.rgb * (atten * 2) * _LightColor0.rgb;
     // specular passes by default put highlights to overbright
     c.a = _LightColor0.a * spec * atten;
     
     return c * _Color;
 }
 
 struct Input {
     float2 uv_MainTex;
     float2 uv_BumpMap;
     float2 uv_SpecMap;
     float2 uv_DecalTex;
     float2 uv_DecalTex2;
 };
 
 void surf (Input IN, inout MySurfaceOutput o) {
     half4 texcol = tex2D( _MainTex, IN.uv_MainTex);
     half4 speccol = tex2D( _SpecMap, IN.uv_SpecMap );
     
     half4 decal = tex2D(_DecalTex, IN.uv_DecalTex);
     half4 decal2 = tex2D(_DecalTex2, IN.uv_DecalTex2);
         
     texcol.rgb = lerp (texcol.rgb, decal.rgb, decal.a);
     texcol.rgb = lerp (texcol.rgb, decal2.rgb, decal2.a);
     
     o.Albedo = texcol.rgb;
     o.Gloss = texcol.a;
     o.Specular = _Shininess * 128;
     o.GlossColor = speccol.rgb;
     o.Normal = (half3) UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
 }
 
 ENDCG
 
 }
 
 
 Fallback " Glossy", 0
  
 }




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

Answer by NomadArtisan · Mar 04, 2013 at 08:27 PM

We figured something out. You don't need to modify anything form Unity's basic shader. Under the object's skinned mesh renderer in the Materials drop down menu you can change its size. This adds more textures to the object's material. Texture's lower in the array list take precedence so if you put a texture with an alpha layer in one of those slots, it will work similarly to a decal and have it's own rgb options. Is this effectively what you're trying to accomplish?

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 Ony · Oct 09, 2014 at 06:33 AM 0
Share

Late reply, but for anyone reading this... I eventually figured out how to do what I needed, and although NomadArtisan's answer would work in some cases, in my case I had more than one material on the mesh, which means it wouldn't work, because it only adds a layer over the last material in the chain.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Adding Decal to Tessellated Material 0 Answers

Does Unity 5 still have Decal Shaders? 1 Answer

Material doesn't have a color property '_Color' 4 Answers

Standard Shader Decals? 1 Answer

One outline material for multiple objects? 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