Shader / URP
Advanced
Unity 2021.3+ / Unity 6 (URP)
카메라 깊이 텍스처(_CameraDepthTexture) 페이드 기반 해안선 수면 폼(Foam) 셰이더
수면 지오메트리의 스크린 깊이와 바닥 지형 깊이의 차이를 계산하여 해안선이나 바위에 자연스럽게 하얀 거품이 생성되는 URP 물 셰이더.
#Shader #URP #Water #DepthTexture #VFX
핵심 개념URP의
_CameraDepthTexture를 읽으면 수면 메시 뒤에 있는 해저 바닥의 실제 선형 깊이($SceneDepth$)를 알 수 있습니다. 여기에 현재 수면 메시의 깊이($SurfaceDepth$)를 뺀 깊이차($\Delta Depth$)가 작을수록 해안가에 가깝다는 의미이므로 폼(Foam) 텍스처를 블렌딩합니다.1. 깊이 페이드 연산 HLSL
float2 screenUV = input.positionCS.xy / _ScaledScreenParams.xy;
float rawDepth = SampleSceneDepth(screenUV);
float sceneEyeDepth = LinearEyeDepth(rawDepth, _ZBufferParams);
float surfaceEyeDepth = input.positionCS.w;
float depthDiff = sceneEyeDepth - surfaceEyeDepth;
float foamFactor = 1.0 - saturate(depthDiff / _FoamDistance);
half4 foamColor = _FoamColor * foamFactor;