본문 바로가기
셰이더 (Shader)/유니티 쉐이더 스타트업 - 정종필

[Unity/Shader] 파트12-1 : Fresnel 공식 구현

by Minkyu Lee 2023. 8. 16.

뷰벡터와 노말을 내적한다.

외곽선을 얇게 만들기 위해 제곱한다.

 

코드

Shader "Custom/Part12-1"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Lambert noambient

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input
        {
            float2 uv_MainTex;
            float3 viewDir; // '버텍스에서' 바라보는 카메라의 방향
        };

        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = 0;

            float rim = 1-dot(o.Normal, IN.viewDir);
            o.Emission = pow(rim, 3);

            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

댓글