Shader "_MyShader/4_Texture/3_RampTexture/Ramp"
{
Properties
{
_RampTex ("RampTex", 2D) = "white" {}
_Color ("Color", COLOR) = (1,1,1,1)
_SpecularColor ("SpecularColor", COLOR) = (1,1,1,1)
_SpecularScale ("SpecularScale", Range(-2,50)) = 5
}
SubShader
{
Pass
{
Tags {"LightMode" = "ForwardBase"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Lighting.cginc"
sampler2D _RampTex;
float4 _RampTex_ST;
fixed4 _Color;
fixed4 _SpecularColor;
float _SpecularScale;
struct a2v
{
float4 ver : POSITION;
float3 norm : NORMAL;
float4 texc : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float3 worldNormalDir : POSITION1;
float3 worldLightDir : POSITION2;
float3 Blinn_PhongDir : POSITION3;
float2 uv : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (a2v v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP,v.ver);
float3 worldViewDir = normalize(WorldSpaceViewDir(v.ver));
o.worldLightDir = normalize(WorldSpaceLightDir (v.ver));
o.worldNormalDir = normalize(UnityObjectToWorldNormal (v.norm));
o.Blinn_PhongDir = normalize(worldViewDir + o.worldLightDir);
o.uv = TRANSFORM_TEX(v.texc,_RampTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed halfLambert = 0.5 * dot(i.worldLightDir,i.worldNormalDir) + 0.5;
fixed3 diffuseC = tex2D(_RampTex,fixed2(halfLambert,halfLambert)).rgb * _Color.rgb * _LightColor0.rgb;
fixed3 specularC = pow(saturate(dot(i.worldNormalDir,i.Blinn_PhongDir)),_SpecularScale) * _SpecularColor.rgb * _LightColor0.rgb;
fixed3 ambC = UNITY_LIGHTMODEL_AMBIENT.xyz;
fixed4 col = fixed4(diffuseC + specularC + ambC,1);
return col;
}
ENDCG
}
}
FallBack "Specular"
}