Skin shader and shadows

Hello!
I’m totally noob in shaders.
I have this skin shader (from wiki, or someting like that), and it’s working well.
But it NOT RECEIVE SHADOWS from POINT and SPOT light. This is nice shader, and I really don’t wanna something else, I just want it to receive shadows. HELP ME PLEASE! :frowning:

Shader "Skin for Unity 3/Bumped Specular" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 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" {}
}
 
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;

half4 LightingBumpSpecSkin (SurfaceOutput 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 ) );
	float spec = pow( nh, s.Specular ) * s.Gloss;

	half4 c;
	c.rgb = (s.Albedo + _SpecColor.rgb * spec * rim.a) * diffuse * (atten * 2) * _LightColor0.rgb;
	// specular passes by default put highlights to overbright
	c.a =  _LightColor0.a * _SpecColor.a * spec * atten;
	
	return c * _Color;
}

struct Input {
	float2 uv_MainTex;
	float2 uv_BumpMap;
};

void surf (Input IN, inout SurfaceOutput o) {
	half4 texcol = tex2D( _MainTex, IN.uv_MainTex);	
	o.Albedo = texcol.rgb;
	o.Gloss = texcol.a;
	o.Specular = _Shininess * 128;
	o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
}

ENDCG

}

Fallback "Diffuse"

}

to prevent stupid questions:
Yes it unity Pro, yes Deffered render, yes other shaders receive shadows as well.
I am noob, but not a idiot.

Change the line

#pragma surface surf BumpSpecSkin

to

#pragma surface surf BumpSpecSkin fullforwardshadows

Wont work, I already try it. Shader just becomes purple.

You probably surpassed instruction limit for shader model 2, check the compiler output in console.
If it’s the case you can add #pragma target 3.0 directive to make it run on SM3 and up.

Just a plug: there are better alternatives to the shader from the wiki:

  1. The guy above has one on his blog, but is too shy to say anything :wink:
  2. Chicken’s pack has a good one.
  3. My shader is in review and will hopefully pop up on the asset store in a few days. Just saying.

The reason it doesn’t receive spotlight and point light shadows is because you’re using a custom lighting model. Forward lighting only has directional shadows, and deferred needs everything to be under the same lighting model.

Thakns for answers, but this “surpassed instruction limit for shader model 2” it’s china language for me) I try to do something with that but without good results.

cician,

  1. I’m try this shader, but “my” I like the better way. But I have to use it, if I don’t deal with shadows. I’m really wan’t to shadows :slight_smile:

just change
#pragma surface surf BumpSpecSkin
to
#pragma surface surf BumpSpecSkin fullforwardshadows
#pragma target 3.0

Thanks, it’s working! :o I love you! :smile: