Files
3d-bianpo/Assets/URPWater/Shaders/HLSL/Includes/URPWaterFoam.hlsl
2026-03-03 11:30:53 +08:00

62 lines
1.9 KiB
HLSL

//-----------------------------------------------------------------------------
// Copyright(C) Yan Verde - All Rights Reserved
// Copyright protected under Unity Asset Store EULA
// Refer to https://unity3d.com/legal/as_terms for more informations
// -----------------------------------------------------------------------------
// URP Water
// Author : Yan Verde
// Date : April 10, 2021
// -----------------------------------------------------------------------------
#ifndef URPWATER_FOAM_INCLUDED
#define URPWATER_FOAM_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "URPWaterHelpers.hlsl"
#include "URPWaterVariables.hlsl"
void ComputeFoam(inout GlobalData data, Varyings IN)
{
#if _FOAM_ON
float2 foamDistortion = data.worldNormal.xz * _FoamDistortion;
float edgeMask = DistanceFade(data.sceneDepth, data.pixelDepth, 0, max(0,_FoamSize));
float foamTex = SAMPLE_TEXTURE2D(_FoamTex, URPWater_trilinear_repeat_sampler, IN.texcoord1.zw + foamDistortion).r;
#if _DISPLACEMENTMODE_GERSTNER || _DISPLACEMENTMODE_GERSTNERPLUS
#if _FOAM_WHITECAPS_ON
half capMask = saturate(IN.texcoord3.y * _FoamCapsIntensity);
capMask = smoothstep(_FoamCapsRangeMin, _FoamCapsRangeMax, capMask);
edgeMask += capMask;
#endif
#endif
#if _DYNAMIC_EFFECTS_ON
edgeMask += data.dynamicData.b * _DynamicFoam;
#endif
#if _ADD_FOAM_ON
edgeMask = max(edgeMask, IN.color.r);
#endif
#if _FOAM_RIPPLE_ON
float rippleMask = DistanceFade(data.sceneDepth, data.pixelDepth, 0, max(0, _FoamRippleDistance));
float rippleSpeed = 1 - _FoamRippleSpeed - 1;
float rippleSize = _FoamRippleSize + _FoamSize;
float ripples = rippleMask * saturate(sin((rippleMask - _Time.y * rippleSpeed + foamDistortion) * rippleSize * URP_WATER_PI) ).r;
data.foamMask = foamTex * max(edgeMask, ripples);
#else
data.foamMask = foamTex * edgeMask;
#endif
#endif
}
#endif