I’m new to shaders and trying to learn to make a custom blinn-phong lighting model, with some additional effects like modifying the color. What I’ve got looks correct in editor, but on iOS 6 and 7 the specular blows out and the gloss amount appears to change, giving the effect of looking very plastic.
I’ve bumped all of my setting to the highest possible on build. I wonder, am I doing anything in my shader that’s incompatible with mobile?
Shader "Custom/LightingModelTest"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Tint Color", Color) = (1,1,1,1)
_DiffPower ("Diff Power", Range(0.0,5.0)) = 1.0
_BumpMap ("Bumpmap", 2D) = "bump" {}
_SpecMap ("Specular", 2D) = "spec" {}
_SpecularPower ("Specular Power", Range(0.01,100.0)) = 0.01
_SpecularGloss ("Specular Gloss", Range(0.01,100.0)) = 0.01
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent"}
Pass {
ZWrite On
ColorMask 0
}
CGPROGRAM
// Using the custom lighting modle SimpleSpecular defined below
#pragma surface surf SimpleSpecular alpha
struct SurfaceOutputColorSpec
{
fixed3 Albedo;
fixed3 Normal;
fixed3 Specular;
fixed3 Emission;
fixed Alpha;
fixed SpecPower;
fixed SpecGloss;
float DiffPower;
float4 Color;
};
half4 LightingSimpleSpecular (SurfaceOutputColorSpec s, half3 lightDir, half3 viewDir, half atten)
{
// Get half reflection - Blinn-Phong model faster than calculating Phong
half3 h = normalize (viewDir + lightDir);
float nh = max (0, dot (s.Normal, h));
// nh to the power of SpecGloss controls the size of the light glow over the surface
float spec = pow (nh, s.SpecGloss) * s.Specular * s.SpecPower;
// Get NdotL angle for diffuse lighting
half diff = dot (s.Normal, lightDir);
// Apply diffuse color and lighting, and add specular color on top
half4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff * s.DiffPower * s.Color.rgb + _LightColor0.rgb * spec) * (atten * 1.5);
c.a = 1;
return c;
}
struct Input
{
// Pass in uv maps to surf
float2 uv_MainTex;
float2 uv_BumpMap;
};
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _SpecMap;
float _SpecularPower;
float _SpecularGloss;
float _DiffPower;
float4 _Color;
void surf (Input IN, inout SurfaceOutputColorSpec o)
{
// Pass specular values from inspector into the output struct
o.SpecPower = _SpecularPower;
o.SpecGloss = _SpecularGloss;
o.DiffPower = _DiffPower;
o.Color = _Color;
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
// Apply the normal map
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
// Apply the specular map
o.Specular = tex2D (_SpecMap, IN.uv_MainTex).rgb;
}
ENDCG
}
Fallback "Diffuse"
}