Unity/Shader
[5.6] Light 연산 연습
ljw4104
2021. 5. 6. 13:06
Shader "Custom/Test"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_BumpTex ("Albedo (RGB)", 2D) = "bump" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Test noambient
sampler2D _MainTex;
sampler2D _BumpTex;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
fixed4 n = tex2D (_BumpTex, IN.uv_BumpTex);
o.Albedo = c.rgb;
o.Normal = UnpackNormal(n);
o.Alpha = c.a;
}
float4 LightingTest(SurfaceOutput s, float3 lightDir, float atten)
{
//Lambert Light
//float ndotl = saturate(dot(s.Normal, lightDir));
//return ndotl;
//Half-Lambert
float ndotl = dot(s.Normal, lightDir) * 0.5 + 0.5;
float4 final;
final.rgb = ndotl * s.Albedo * _LightColor0.rgb * atten;
final.a = s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}