Shader/Shader - SurfaceShader

12-2 Rim 라이트

소나무꼴 2020. 4. 4. 20:30
Shader "Custom/12-2"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
		_RimColor("RimColor", Color) = (1,1,1,1)
		_RimPower("RimPower", Range(1, 10)) = 3
		_BumpMap ("NormalMap (RGB)", 2D) = "white" {}
	}
	SubShader
	{
		Tags { "RenderType" = "Opaque" }
		LOD 200

		CGPROGRAM
		#pragma surface surf Lambert 

		sampler2D _MainTex;
		float4 _RimColor;
		float _RimPower;
		sampler2D _BumpMap;

        struct Input
        {
            float2 uv_MainTex;
            float3 viewDir;
            float2 uv_BumpMap;
        };

        void surf(Input IN, inout SurfaceOutput o)
        {

			fixed4 c = tex2D(_MainTex, IN.uv_MainTex);			
			o.Albedo = c.rgb;
			o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
			o.Alpha = c.a;

			float rim = dot(o.Normal, -IN.viewDir);
			rim = max(0, rim);
			o.Emission = pow(1 - rim, _RimPower) * _RimColor.rgb;
			o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

'Shader > Shader - SurfaceShader' 카테고리의 다른 글

13-3 Gloss  (0) 2020.04.05
13-2 스펙귤러  (0) 2020.04.05
12-1 프리넬 공식  (0) 2020.04.04
11 - 3(Half-Lambert)  (0) 2020.04.04
11 - 2 (Lambert 라이트연산)  (0) 2020.04.04