Shader "MannteraShader"
{
Properties
{
_MainTex("Texture",2D) = "red"{}
_SpecularPower("SpecularPower",float) = 10
_RampMap("RampMap",2D) = "white" {}
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float4 normal : NORMAL;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float3 wPos : WORLD_POS;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
};
v2f vert(appdata v)
{
v2f _out;
_out.pos = UnityObjectToClipPos(v.vertex);
_out.wPos = mul(unity_ObjectToWorld, v.vertex).xyz;
_out.normal = UnityObjectToWorldNormal(v.normal);
_out.uv = v.uv;
return _out;
}
sampler2D _MainTex;
sampler2D _RampMap;
float _SpecularPower;
float4 frag(v2f _in) : SV_Target
{
float4 col = (float4)0;
float4 texColor = tex2D(_MainTex, _in.uv);
float3 lightVector = normalize(_WorldSpaceLightPos0.xyz);
float3 viewVector = normalize(_WorldSpaceCameraPos - _in.wPos);
float d = dot(lightVector, _in.normal);
d = d * 0.5f + 0.5f;
d = d * d;
d = saturate(d);
float3 rampColor = tex2D(_RampMap, float2(0, d));
float4 diffuseColor = float4(rampColor.xyz,1) * texColor;
float3 ref = reflect(-lightVector, _in.normal);
float reflectionPower = dot(ref, viewVector);
reflectionPower = max(0, reflectionPower);
float3 specularColor = pow(reflectionPower, _SpecularPower);
col.xyz = diffuseColor.xyz +specularColor;
col.w = diffuseColor.w;
return col;
}
ENDCG
}
}
}