게임 그래픽 프로그래밍
바디
101won
2024. 9. 7. 00:37
Shader "Custom/body"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_BumpTex ("Bump (RGB)", 2D) = "white" {}
_RampTex ("Ramp (RGB)", 2D) = "white" {}
}
SubShader {
Tags {
"RenderType" ="Opaque"
}
CGPROGRAM
#pragma surface surf _CustomLight
sampler2D _MainTex;
sampler2D _BumpTex;
sampler2D _RampTex;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 Main = tex2D (_MainTex, IN.uv_MainTex);
fixed4 Bump = tex2D (_BumpTex, IN.uv_BumpTex);
o.Albedo = Main.rgb;
o.Alpha = Main.a;
}
float4 Lighting_CustomLight(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten)
{
float3 H = normalize(lightDir+viewDir);
float spec = saturate(dot(s.Normal, H));
spec = pow(spec, 100);
float rim = abs(dot(s.Normal, viewDir));
float ndotl = dot(s.Normal, lightDir) * 0.5 + 0.5;
fixed4 Ramp = tex2D (_RampTex, float2(ndotl, rim));
float4 final;
final.rgb = Ramp.rgb * s.Albedo.rgb + spec + s.Albedo.rgb *0.01;
final.a = s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}