I’d like to take a screenshot of a model inside my unity game and save it on the disk. This works with a built-in shader like the diffuse shader. But when I use another shader (like below) there is just a grey outline of the mesh on the screenshot.
What’s wrong with my shader?
Shader "SNS/Specular"
{
Properties
{
_MainTexture("Diffuse Map", 2D) = "white"{}
_SpecularMap("Specular Map", 2D) = "white"{}
_Shininess("Shininess", Range(0,5)) = 2.5
}
SubShader
{
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf ColoredSpecular
struct MySurfaceOutput
{
half3 Albedo;
half3 Normal;
half3 Emission;
half Specular;
half3 GlossColor;
half Alpha;
};
inline half4 LightingColoredSpecular (MySurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, 32.0 * s.Specular);
half3 specCol = spec * s.GlossColor;
half4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * specCol) * (atten * 2);
c.a = s.Alpha;
return c;
}
inline half4 LightingColoredSpecular_PrePass (MySurfaceOutput s, half4 light)
{
half3 spec = light.a * s.GlossColor;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha + spec * _SpecColor.a;
return c;
}
struct Input
{
float2 uv_MainTexture;
float2 uv_SpecularMap;
};
sampler2D _MainTexture;
sampler2D _SpecularMap;
float _Shininess;
void surf (Input IN, inout MySurfaceOutput o)
{
fixed4 tex = tex2D(_MainTexture, IN.uv_MainTexture);
o.Albedo = tex.rgb;
half4 spec = tex2D (_SpecularMap, IN.uv_SpecularMap);
o.GlossColor = spec.rgb;
o.Specular = _Shininess;
}
ENDCG
}
}