I recently upgraded my project to Unity 5 from 4, and my shader has turned pink. Unfortunately, like many, it doesn’t work anymore. In addition, I’m now getting a NaN and infinity literals are not allowed by shader model. I heard that shader model got changed to HLSL, so maybe this had something to do with it. I found no tips on my problem, unfortunately, from the Unity 5.0 manual.
Shader "voxelShader"
{
Properties
{
_DiffuseColor("_DiffuseColor", Color) = (1,0,0,1)
_MainTex("_MainTex", 2D) = "black" {}
}
SubShader
{
Tags
{
"Queue"="Geometry"
"IgnoreProjector"="False"
"RenderType"="Opaque"
}
Cull Back
ZWrite On
ZTest LEqual
ColorMask RGBA
Fog{
}
CGPROGRAM
#pragma surface surf BlinnPhongEditor vertex:vert
#pragma target 2.0
float4 _DiffuseColor;
sampler2D _MainTex;
struct EditorSurfaceOutput {
half3 Albedo;
half3 Normal;
half3 Emission;
half3 Gloss;
half Specular;
half Alpha;
half4 Custom;
};
inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
{
half3 spec = light.a * s.Gloss;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha;
return c;
}
inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half3 h = normalize (lightDir + viewDir);
half diff = max (0.00001f, dot ( lightDir, s.Normal ));
float nh = max (0.00001f, dot (s.Normal, h));
float spec = pow (nh, s.Specular*128.0);
half4 res;
res.rgb = _LightColor0.rgb * diff;
res.w = spec * Luminance (_LightColor0.rgb);
res *= atten * 2.0;
return LightingBlinnPhongEditor_PrePass( s, res );
}
struct Input {
float2 uv_MainTex;
float4 color : COLOR;
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
//v.vertex = v.vertex;
//v.color = v.color;
v.normal = (float4( v.normal.x, v.normal.y, v.normal.z, 1.0 )).xyz;
v.tangent = float4( 0.0, 0.0, 0.0, 0.0 );
}
void surf (Input IN, inout EditorSurfaceOutput o) {
o.Normal = float3(0.0,0.0,1.0);
o.Alpha = 1.0;
o.Albedo = 0.0;
o.Emission = 0.0;
o.Gloss = 0.0;
o.Specular = 0.0;
o.Custom = 0.0;
float4 Sampled2D0=tex2D(_MainTex,IN.uv_MainTex.xy);
float4 SplatAlpha0=IN.color.w;
float4 Add0=IN.color + SplatAlpha0;
float4 Multiply0=Sampled2D0 * Add0;
float4 Master0_1_NoInput = float4(0,0,1,1);
float4 Master0_2_NoInput = float4(0,0,0,0);
float4 Master0_3_NoInput = float4(0,0,0,0);
float4 Master0_4_NoInput = float4(0,0,0,0);
float4 Master0_5_NoInput = float4(1,1,1,1);
float4 Master0_7_NoInput = float4(0,0,0,0);
float4 Master0_6_NoInput = float4(1,1,1,1);
o.Albedo = Multiply0;
o.Normal = normalize(o.Normal);
}
ENDCG
}
Fallback "Diffuse"
}