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

[Unity/Shader] 파트18-3 : 디졸브

by Minkyu Lee 2023. 10. 10.

썸네일

 

코드

Shader "Custom/part13-3 1"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _NoiseTex ("NoiseTex", 2D) = "white" {}
        _Cut ("Alpha Cut", Range(0,1)) = 0
        [HDR]_OutColor("OutColor", Color) = (1,1,1,1)
        _OutThickness("OutThickness", Range(1,1.5)) = 1.15
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert alpha:fade

        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _NoiseTex;
        float _Cut;
        float4 _OutColor;
        float _OutThickness;

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_NoiseTex;
        };
        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);
            float4 noise = tex2D(_NoiseTex, IN.uv_NoiseTex);
            o.Albedo = c.rgb;

            float alpha;
            if(noise.r >= _Cut) alpha = 1;
            else alpha = 0; // 텍스쳐값이 기준값보다 작다면 사라진다.

            float outline;
            if(noise.r >= _Cut * _OutThickness) outline = 0; // 기준값 범위를 더 넓힌다. 넓힌 기준값보다 더 작다면 아웃라인을 가진다.
            else outline = 1;

            o.Emission = outline * _OutColor.rgb;
            o.Alpha = alpha;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

댓글