ABOUT PORTFOLIO GAMES DEVLOG DOCS TOOLS CONTACT
HOME > DOCS > Shader / URP > 노이즈 텍스처와 스텝 함수 기반 URP 디졸브(Dissolve) 번 엣지 셰이더URP Dissolve Burn-Edge Shader Using Noise Textures and Step Functions
Shader / URP Intermediate Unity 2021.3+ / Unity 6 (URP)

노이즈 텍스처와 스텝 함수 기반 URP 디졸브(Dissolve) 번 엣지 셰이더URP Dissolve Burn-Edge Shader Using Noise Textures and Step Functions

Simplex/Perlin 노이즈와 step/smoothstep 함수를 결합해 오브젝트가 타들어가며 사라지는 가장자리 발광(Emissive Burn Edge) 셰이더 구현.Implementing an emissive burn-edge dissolve shader in URP by combining Simplex/Perlin noise sampling with cutoff clipping and edge interpolation.

#Shader #URP #HLSL #Dissolve #VFX
핵심 개념디졸브의 기본 원리는 노이즈 텍스처의 그레이스케일 값과 _Cutoff(0~1) 파라미터를 비교해 특정 임계치 이하의 픽셀을 clip()으로 폐기하는 것입니다. 여기에 컷오프 경계선 직전 구간을 마스킹하여 발광 색상(HDR Edge Color)을 보간하면 타들어가는 가장자리 효과를 구현할 수 있습니다.
Core ConceptA dissolve effect compares the grayscale value of a noise texture against a _Cutoff (0 to 1) parameter and discards pixels below the threshold using clip(). Masking the narrow band just above the cutoff threshold and interpolating an HDR edge color produces a glowing burn border.

1. URP HLSL 디졸브 셰이더 코드1. URP HLSL Dissolve Shader Code

DissolveBurn.shader
Shader "Custom/URP/DissolveBurn"
{
    Properties
    {
        _BaseMap ("Texture", 2D) = "white" {}
        _BaseColor ("Color", Color) = (1,1,1,1)
        _NoiseMap ("Noise Map", 2D) = "white" {}
        _Cutoff ("Dissolve Amount", Range(0, 1)) = 0.0
        _EdgeWidth ("Edge Width", Range(0, 0.2)) = 0.05
        [HDR] _EdgeColor ("Edge Burn Color", Color) = (2, 0.5, 0, 1)
    }
    SubShader
    {
        Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
        Pass
        {
            Name "ForwardLit"
            Tags { "LightMode" = "UniversalForward" }

            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            struct Attributes
            {
                float4 positionOS : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct Varyings
            {
                float4 positionCS : SV_POSITION;
                float2 uv : TEXCOORD0;
            };

            TEXTURE2D(_BaseMap);   SAMPLER(sampler_BaseMap);
            TEXTURE2D(_NoiseMap);  SAMPLER(sampler_NoiseMap);

            CBUFFER_START(UnityPerMaterial)
                float4 _BaseMap_ST;
                float4 _NoiseMap_ST;
                half4 _BaseColor;
                half4 _EdgeColor;
                float _Cutoff;
                float _EdgeWidth;
            CBUFFER_END

            Varyings vert(Attributes input)
            {
                Varyings output;
                output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
                output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
                return output;
            }

            half4 frag(Varyings input) : SV_Target
            {
                half noise = SAMPLE_TEXTURE2D(_NoiseMap, sampler_NoiseMap, input.uv).r;
                clip(noise - _Cutoff); // 컷오프보다 작으면 픽셀 폐기

                half4 baseTex = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv) * _BaseColor;
                // 가장자리 영역 마스킹 (noise가 _Cutoff + _EdgeWidth 미만일 때)
                float edgeFactor = 1.0 - saturate((noise - _Cutoff) / max(_EdgeWidth, 0.0001));
                half3 finalColor = lerp(baseTex.rgb, _EdgeColor.rgb, edgeFactor);

                return half4(finalColor, baseTex.a);
            }
            ENDHLSL
        }
    }
}
DissolveBurn.shader
Shader "Custom/URP/DissolveBurn"
{
    Properties
    {
        _BaseMap ("Texture", 2D) = "white" {}
        _BaseColor ("Color", Color) = (1,1,1,1)
        _NoiseMap ("Noise Map", 2D) = "white" {}
        _Cutoff ("Dissolve Amount", Range(0, 1)) = 0.0
        _EdgeWidth ("Edge Width", Range(0, 0.2)) = 0.05
        [HDR] _EdgeColor ("Edge Burn Color", Color) = (2, 0.5, 0, 1)
    }
    SubShader
    {
        Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
        Pass
        {
            Name "ForwardLit"
            Tags { "LightMode" = "UniversalForward" }

            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            struct Attributes
            {
                float4 positionOS : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct Varyings
            {
                float4 positionCS : SV_POSITION;
                float2 uv : TEXCOORD0;
            };

            TEXTURE2D(_BaseMap);   SAMPLER(sampler_BaseMap);
            TEXTURE2D(_NoiseMap);  SAMPLER(sampler_NoiseMap);

            CBUFFER_START(UnityPerMaterial)
                float4 _BaseMap_ST;
                float4 _NoiseMap_ST;
                half4 _BaseColor;
                half4 _EdgeColor;
                float _Cutoff;
                float _EdgeWidth;
            CBUFFER_END

            Varyings vert(Attributes input)
            {
                Varyings output;
                output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
                output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
                return output;
            }

            half4 frag(Varyings input) : SV_Target
            {
                half noise = SAMPLE_TEXTURE2D(_NoiseMap, sampler_NoiseMap, input.uv).r;
                clip(noise - _Cutoff); // Discard pixel if below cutoff

                half4 baseTex = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv) * _BaseColor;
                // Mask the edge region (when noise is below _Cutoff + _EdgeWidth)
                float edgeFactor = 1.0 - saturate((noise - _Cutoff) / max(_EdgeWidth, 0.0001));
                half3 finalColor = lerp(baseTex.rgb, _EdgeColor.rgb, edgeFactor);

                return half4(finalColor, baseTex.a);
            }
            ENDHLSL
        }
    }
}

2. 실무 적용 및 주의사항2. Practical Considerations and Caveats

  • 그림자 패스(ShadowCaster) 동기화: 본체 메시는 디졸브로 사라졌는데 그림자가 그대로 남아있지 않도록 ShadowCaster 패스에서도 동일한 _NoiseMap과 clip(noise - _Cutoff) 연산을 수행해야 합니다.
  • 노이즈 텍스처 sRGB 해제: 노이즈 맵 임포트 시 sRGB (Color Texture) 옵션을 해제하여 선형(Linear) 분포를 유지해야 _Cutoff 값 변화에 따라 일정한 속도로 디졸브가 진행됩니다.
  • 모바일 Early-Z 최적화 유의: clip()(Alpha Test)을 사용하는 패스는 모바일 TBDR GPU에서 Early-Z 최적화를 비활성화할 수 있으므로, 디졸브가 진행 중인 동안에만 해당 머티리얼이나 패스를 활성화하는 것이 유리합니다.
  • Synchronizing the ShadowCaster Pass: Apply the same _NoiseMap sample and clip(noise - _Cutoff) logic in the ShadowCaster pass so that the cast shadow dissolves in sync with the mesh.
  • Disable sRGB on Noise Textures: Uncheck sRGB (Color Texture) in the noise texture import settings to keep the grayscale distribution linear, ensuring a uniform dissolve progression as _Cutoff changes.
  • Early-Z Performance on Mobile GPUs: Using clip() (alpha testing) disables Early-Z optimizations on tile-based mobile GPUs, so consider switching to the dissolve material only while the transition is active.

노이즈 샘플링과 clip() 임계값 제어를 결합하면 별도의 반투명 정렬 비용 없이 오브젝트 소멸 및 생성 연출을 구현할 수 있습니다.

Combining noise texture sampling with clip() threshold control enables object spawn and disintegration effects without incurring alpha-blending sort overhead.

참고자료 & 관련 링크