게임개발/게임 그래픽 프로그래밍
BlinnPhong 스펙큘러
pudding81
2024. 2. 21. 10:33
Shader "Custom/BlinnPhong2"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_SpecColor("SpecColor",Color)=(1,1,1,1)
_BumpMap("Normalmap",2D) ="bump"{}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf _Phong noambient
#pragma target 3.0
sampler2D _MainTex;
sampler2D _BumpMap;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
float4 c = tex2D (_MainTex, IN.uv_MainTex);
//노멀맵
fixed4 n =tex2D(_BumpMap,IN.uv_MainTex);
o.Normal =UnpackNormal(n);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
float4 Lighting_Phong(SurfaceOutput s, float3 lightDir, float3 viewDir,float atten)
{
//램버트 연산 diffuse N L
float3 diffuseColor;
float ndotl =saturate(dot(s.Normal,lightDir)); //0~1
diffuseColor=ndotl*s.Albedo*_LightColor0.rgb*atten;
// spec
float3 h = normalize(lightDir+viewDir); //하프 단위 벡터 구하기
float spec =saturate(dot(h,s.Normal));//스펙튤러 구하기/ 제일 밝음
float3 specColor = pow(spec,100) * _SpecColor.rgb;
//final 적용
float4 final;
final.rgb= diffuseColor.rgb+ specColor;
final.a =s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}