11/28

이우석·2023년 11월 28일
0

SBS 국기수업

목록 보기
76/120

쉐이더 Dissolve 효과


Shader "Apply/LambertDissolveShader"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _NoiseTex ("Noise Map", 2D) = "white" {}
        _AlphaCut("AlphaCut Value", Range(0, 1)) = 0
        [HDR] _OutColor("Out Color", Color) = (1, 1, 1, 1)
        _OutThinkness("OutThinkness", Range(1, 1.15)) = 1.15
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert alpha:fade
        #pragma target 3.0

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_NoiseTex;
        };

        sampler2D _MainTex;
        sampler2D _NoiseTex;
        float _AlphaCut;
        fixed4 _OutColor;
        float _OutThinkness;

        UNITY_INSTANCING_BUFFER_START(Props)
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutput o)
        {
            float alpha;
            float outline;

            fixed4 diffuse = tex2D (_MainTex, IN.uv_MainTex);
            fixed4 noise = tex2D(_NoiseTex, IN.uv_NoiseTex);

            o.Albedo = diffuse.rgb;
            if(noise.r >= _AlphaCut)
            {
                alpha = 1;
            }
            else
            {
                alpha = 0;
            }

            if(noise.r >= _AlphaCut * _OutThinkness)
            {
                outline = 0;
            }
            else
            {
                outline = 1;
            }

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

이하 커스텀

Shader "Apply/CustomTTBasic"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _BumpTex ("Normal Map", 2D) = "bump" {}

        [Space(50)]

        _SpecularColor("Specular Color", Color) = (1, 1, 1, 1)
        _Specular("Specular", Range(1, 10)) = 3
        _Gloss("Gloss", Range(1, 10)) = 3

        [space(50)]

        _NoiseTex ("Noise Map", 2D) = "white" {}
        _AlphaCut("AlphaCut Value", Range(0, 1)) = 0
        [HDR] _OutColor("Out Color", Color) = (1, 1, 1, 1)
        _OutThinkness("OutThinkness", Range(1, 1.15)) = 1.15
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }
        LOD 200

        zwrite on
        colormask 0
        CGPROGRAM
        #pragma surface surf Standard
        #pragma target 3.0

        struct Input
        {
            float2 uv_MainTex;
        };

        void surf(Input IN, inout SurfaceOutputStandard o)
        {
        }
        ENDCG

        zwrite off
        CGPROGRAM
        #pragma surface surf CustomTTBasic alpha:blend
        #pragma target 3.0

        struct Input
        {
            float2 uv_MainTex;
            float2 uv_BumpTex;
            float2 uv_NoiseTex;
        };

        sampler2D _MainTex;
        sampler2D _BumpTex;
        sampler2D _NoiseTex;

        float _Specular;
        fixed4 _SpecularColor;
        fixed _Gloss;

        float _AlphaCut;
        float _Alpha;

        float _Outline;
        fixed4 _OutColor;
        float _OutThinkness;

        UNITY_INSTANCING_BUFFER_START(Props)
        UNITY_INSTANCING_BUFFER_END(Props)

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

            fixed3 bumpTex = UnpackNormal(tex2D(_BumpTex, IN.uv_BumpTex));
            o.Normal = bumpTex.rgb;
            o.Gloss = _Gloss;

            fixed4 noiseTex = tex2D(_NoiseTex, IN.uv_NoiseTex);
            if(noiseTex.r >= _AlphaCut)
            {
                _Alpha = diffTex.a;
            }
            else
            {
                _Alpha = 0;
            }

            if(noiseTex.r >= _AlphaCut * _OutThinkness)
            {
                _Outline = 0;
            }
            else
            {
                _Outline = 1;
            }
        }

        float4 LightingCustomTTBasic(inout SurfaceOutput s, float3 lightDir, float viewDir, float atten)
        {
            //Lambert
            float fNDotL = saturate(dot(s.Normal, lightDir)) * 0.5 +0.5;

            // Diffuse
            float3 diffColor;
            diffColor = s.Albedo * fNDotL * _LightColor0.rgb * atten;

            // Specular
            float3 halfVector = normalize(viewDir + lightDir); //하프 벡터
            float specular = saturate(dot(s.Normal, halfVector)); // 스펙큘라 (그레이 스케일)
            specular = pow(specular, _Specular) * s.Gloss;
            float3 specularColor = specular * _LightColor0.rgb * _SpecularColor.rgb;

            // Outline
            float3 outlineColor = _OutColor.rgb * _Outline;

            float4 result;
            result.rgb = diffColor + specularColor + outlineColor;
            result.a = _Alpha;
            return result;
        }
        ENDCG
    }
    FallBack "Diffuse"
}
profile
게임 개발자 지망생, 유니티 공부중!

0개의 댓글