- Home /
Question by
alexander11 · Aug 17, 2017 at 12:58 PM ·
unity 5cg
What Happend to Specular in CG Unity 5x?
Hello i am learning CG from a book called "Unity Shaders and Effects Cookbook"(made in 2013 by Kenny Lammers).
And i am running into problem it seems like the Specular command is no Longer in Unity 5 for some reason, does anyone know what they Changed it into?
Here is the Code anyways.
Shader "Custom/Shader_09" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_SpeculColor ("Spec Color", Color) = (1,1,1,1)
_SpeculMask("Spec Mask", 2D) = "white" {}
_SpeculPower("Spec Power", Range(0.1,120)) = 3
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf CustomsPhong
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _SpeculMask;
float4 _SpeculColor;
float _SpeculPower;
struct SurfaceCustomOutput
{
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
fixed3 SpeculColor
fixed Specular;
fixed Gloss;
fixed Alpha;
};
inline fixed4 LightingCustomsPhong(SurfaceCustomOutput s, fixed3 lightDir, half3 viewDir, fixed atten)
{
float diff = dot(s.Normal, lightDir);
float3 reflectionVector = normalize(2.0 * s.Normal * diff - lightDir);
float spec = pow(max(0.0f, dot(reflectionVector, viewDir)), _SpeculPower) * s.Specular;
float3 finalSpec = s.SpecularColor * spec * _SpecularColor.rgb;
fixed4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff) + (_LightColor0.rgb * finalSpec);
c.a = s.Alpha;
return c;
}
struct Input {
float2 uv_MainTex;
float2 uv_SpeculMask;
};
fixed4 _Color;
void surf (Input IN, inout SurfaceCustomOutput o) {
// Albedo comes from a texture tinted by color
float4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
float4 specMask = tex2D(_SpeculMask, IN.uv_SpeculMask) * _SpeculColor;
o.Albedo = c.rgb;
o.Specular = specMask.r;
o.SpecularCOlor = specMask.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
(The error i am getting ("Shader error in 'Custom/Shader_09': Syntax error at line 32 (on ) ") )
Comment
Is it possible that it's a fixed3 form Unity 5 onwards?
https://docs.unity3d.com/$$anonymous$$anual/SL-SurfaceShaders.html
Still not what i am looking for but it will do for now. Thanks :D