- Home /
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
}
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?
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
Follow this Question
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