게임개발/게임 그래픽 프로그래밍
Standard - Lambert -HalfLambert
pudding81
2024. 2. 20. 12:39
Lambert와 HalfLambert는 빛의 반사나 발산에 관한 두 가지 모델입니다.
Lambert는 램버시안 코사인 법칙1을 따르는 램버시안 표면의 성질을 모델링합니다.
반면, HalfLambert는 램버시안 표면보다 더 부드럽고 밝은 반사를 만들기 위해 코사인 법칙을 수정한 것입니다
Shader "Custom/Standard"
{
Properties
{
_BumpMap("Normalmap",2D) ="bump"{}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Standard //스탠다드
#pragma target 3.0
sampler2D _BumpMap;
struct Input
{
float4 color:COLOR;
float2 uv_BumpMap;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
//노멀맵
fixed4 n =tex2D (_BumpMap, IN.uv_BumpMap);
fixed3 normal =UnpackNormal(n);
o.Normal =normal;
o.Albedo =1;
}
ENDCG
}
FallBack "Diffuse"
}
Shader "Custom/CustomLambert"
{
Properties
{
_BumpMap("Normalmap",2D) ="bump"{}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf _MyLambert //noamient
#pragma target 3.0
sampler2D _BumpMap;
struct Input
{
float4 color:COLOR;
float2 uv_BumpMap;
};
void surf (Input IN, inout SurfaceOutput o)
{
//노멀맵
fixed4 n =tex2D (_BumpMap, IN.uv_BumpMap);
fixed3 normal =UnpackNormal(n);
o.Normal =normal;
o.Albedo =1;
}
// 하프램버트
float4 Lighting_MyLambert(SurfaceOutput s,float3 lightDir, float atten)
{
//조명과 노멀의 각도를 표현
float ndotl =dot(s.Normal,lightDir);
//0~1을 반환
float4 final = saturate(ndotl);
//텍스처 s.Albedo , 조명색상과 강도 _LightColor0.rgb , 감쇠 atten 를 연산
final.rgb=ndotl*s.Albedo*_LightColor0.rgb*atten;
return final;
}
ENDCG
}
FallBack "Diffuse"
}
Shader "Custom/Half"
{
Properties
{
_BumpMap("Normalmap",2D) ="bump"{}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf _MyLambert //noamient
#pragma target 3.0
sampler2D _BumpMap;
struct Input
{
float4 color:COLOR;
float2 uv_BumpMap;
};
void surf (Input IN, inout SurfaceOutput o)
{
//노멀맵
fixed4 n =tex2D (_BumpMap, IN.uv_BumpMap);
fixed3 normal =UnpackNormal(n);
o.Normal =normal;
o.Albedo =1;
}
// 하프램버트
float4 Lighting_MyLambert(SurfaceOutput s,float3 lightDir, float atten)
{
//조명과 노멀의 각도를 표현
float ndotl =dot(s.Normal,lightDir)*0.5+0.5; //음영이 부드러워짐- 밝아짐
float powNdotl=pow(ndotl,3); //3제곱- 어둡게 수정
//0~1을 반환
float4 final = saturate(powNdotl);
//텍스처 s.Albedo , 조명색상과 강도 _LightColor0.rgb , 감쇠 atten 를 연산
final.rgb=powNdotl*s.Albedo*_LightColor0.rgb*atten;
return final;
}
ENDCG
}
FallBack "Diffuse"
}