I want to use this shader: http://www.unifycommunity.com/wiki/index.php?title=BumpColorSpec
in the latest version of unity, but it does not work. Could someone post a version that does work?
I would myself but I can’t write shaders, I only model and program…
What did unity tell you about the shader whin you click on it.
This should do it?
Shader "Bumped Color Specular" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_Shininess ("Glossiness", Range (0.03, 1)) = 0.078125
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_BumpMap ("Bump (Normal)", 2D) = "bump" {}
_SpecMap ("Spec (RGB)", 2D) = "white" {}
}
SubShader{
Tags { "RenderType"="Opaque" "Queue" = "Geometry" }
CGPROGRAM
struct SurfaceOutputColorSpec {
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
fixed3 Specular;
fixed Gloss;
fixed Alpha;
};
inline fixed4 LightingBlinnPhongColorSpec (SurfaceOutputColorSpec s, fixed3 lightDir, fixed3 viewDir, fixed atten)
{
fixed3 h = normalize (lightDir + viewDir);
fixed diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float3 spec = pow (nh, s.Gloss*128.0) * s.Specular;
fixed4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten * 2);
c.a = s.Alpha + _LightColor0.a * spec * atten;
return c;
}
#pragma surface surf BlinnPhongColorSpec
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
float2 uv_SpecMap;
};
sampler2D _MainTex, _BumpMap, _SpecMap;
float _Shininess;
void surf (Input IN, inout SurfaceOutputColorSpec o)
{
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
o.Gloss = _Shininess;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
o.Specular = tex2D(_SpecMap, IN.uv_SpecMap).rgb;
}
ENDCG
}
FallBack "Bumped Diffuse"
}
The shader works but it didn’t change the color of the specular it’s still white.
Whoops, updated it, should work now. Forgot to set the spec as float3 rather than float.
Thanks!
Your welcome from both of us. and to Farfarer thank you for fixing it. I’v needed this shader but I could not get it to work at all.
For the sake of completeness, here’s an alpha-tested one with gloss control in the spec map’s alpha channel. Bit more useful than having a “shininess” slider for gloss value.
Shader "Bumped Color Specular Gloss" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
_BumpMap ("Bump (Normal)", 2D) = "bump" {}
_SpecMap ("Spec (RGB) Gloss (A)", 2D) = "grey" {}
_Cutoff ("Alphatest Threshold", Range(0,1)) = 0.5
}
SubShader{
Tags { "RenderType"="Opaque" "Queue" = "Geometry" }
CGPROGRAM
struct SurfaceOutputColorSpec {
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
fixed3 Specular;
fixed Gloss;
fixed Alpha;
};
inline fixed4 LightingBlinnPhongColorSpec (SurfaceOutputColorSpec s, fixed3 lightDir, fixed3 viewDir, fixed atten)
{
fixed3 h = normalize (lightDir + viewDir);
fixed diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float3 spec = pow (nh, s.Gloss*128.0) * s.Specular;
fixed4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten * 2);
c.a = s.Alpha;
return c;
}
#pragma surface surf BlinnPhongColorSpec alphatest:_Cutoff
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
float2 uv_SpecMap;
};
sampler2D _MainTex, _BumpMap, _SpecMap;
void surf (Input IN, inout SurfaceOutputColorSpec o)
{
fixed4 diffuse = tex2D(_MainTex, IN.uv_MainTex);
fixed4 specular = tex2D(_SpecMap, IN.uv_SpecMap);
o.Albedo = diffuse.rgb;
o.Alpha = diffuse.a;
o.Specular = specular.rgb;
o.Gloss = specular.a;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
FallBack "Transparent/Cutout/Bumped Diffuse"
}