Skip to content

Commit

Permalink
feat: add raindrop ripples on water
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRiverwoodModder committed Sep 30, 2024
1 parent 6d59b81 commit 66a0a97
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace WetnessEffects
}

// xyz - ripple normal, w - splotches
float4 GetRainDrops(float3 worldPos, float t, float3 normal)
float4 GetRainDrops(float3 worldPos, float t, float3 normal, float rippleStrengthModifier = 1)
{
const static float uintToFloat = rcp(4294967295.0);
const float rippleBreadthRcp = rcp(wetnessEffectsSettings.RippleBreadth);
Expand Down Expand Up @@ -110,7 +110,7 @@ namespace WetnessEffects
float band_lerp = (sqrt(distSqr) - ripple_inner_radius) * rippleBreadthRcp;
if (band_lerp > 0. && band_lerp < 1.) {
float deriv = (band_lerp < .5 ? SmoothstepDeriv(band_lerp * 2.) : -SmoothstepDeriv(2. - band_lerp * 2.)) *
lerp(wetnessEffectsSettings.RippleStrength, 0, rippleT * rippleT);
lerp(wetnessEffectsSettings.RippleStrength * rippleStrengthModifier, 0, rippleT * rippleT);

float3 grad = float3(normalize(vec2Centre), -deriv);
float3 bitangent = float3(-grad.y, grad.x, 0);
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace WetnessEffects
float3 R = reflect(-V, N);
float NoV = saturate(dot(N, V));

#if defined(DYNAMIC_CUBEMAPS)
#if defined(DYNAMIC_CUBEMAPS) && !defined(WATER)
# if defined(DEFERRED)
float level = roughness * 7.0;
float3 specularIrradiance = 1.0;
Expand Down
Binary file not shown.
37 changes: 36 additions & 1 deletion package/Shaders/Water.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,9 @@ float3 GetFlowmapNormal(PS_INPUT input, float2 uvShift, float multiplier, float
}
# endif

# if (defined(FLOWMAP) && !defined(BLEND_NORMALS)) || defined(LOD)
# if defined(LOD)
# undef WATER_LIGHTING
# undef WETNESS_EFFECTS
# endif

# if defined(WATER_LIGHTING)
Expand All @@ -451,6 +452,10 @@ float3 GetFlowmapNormal(PS_INPUT input, float2 uvShift, float multiplier, float
# include "DynamicCubemaps/DynamicCubemaps.hlsli"
# endif

# if defined(WETNESS_EFFECTS)
# include "WetnessEffects/WetnessEffects.hlsli"
# endif

float3 GetWaterNormal(PS_INPUT input, float distanceFactor, float normalsDepthFactor, float3 viewDirection, float depth, uint a_eyeIndex)
{
float3 normalScalesRcp = rcp(input.NormalsScale.xyz);
Expand Down Expand Up @@ -531,6 +536,36 @@ float3 GetWaterNormal(PS_INPUT input, float distanceFactor, float normalsDepthFa
finalNormal = lerp(displacement, finalNormal, displacement.z);
# endif

# if defined(WETNESS_EFFECTS)
bool inWorld = ExtraShaderDescriptor & _InWorld;
# if defined(SKYLIGHTING)
# if defined(VR)
float3 positionMSSkylight = input.WPosition.xyz + CameraPosAdjust[a_eyeIndex].xyz - CameraPosAdjust[0].xyz;
# else
float3 positionMSSkylight = input.WPosition.xyz;
# endif
sh2 skylightingSH = Skylighting::sample(skylightingSettings, SkylightingProbeArray, positionMSSkylight, float3(0, 0, 1));
float skylighting = shUnproject(skylightingSH, float3(0, 0, 1));

float wetnessOcclusion = inWorld ? pow(saturate(skylighting), 2) : 0;
# else
float wetnessOcclusion = inWorld;
# endif

float4 raindropInfo = float4(0, 0, 1, 0);
float maxRainDropDistance = wetnessEffectsSettings.RaindropFxRange * wetnessEffectsSettings.RaindropFxRange * 3;
float rainDropDistance = dot(input.WPosition, input.WPosition);
float distanceFadeout = saturate((1 - saturate(rainDropDistance / maxRainDropDistance)) * 3);
if (finalNormal.z > 0 && wetnessEffectsSettings.Raining > 0.0f && wetnessEffectsSettings.EnableRaindropFx &&
(rainDropDistance < maxRainDropDistance) && wetnessOcclusion > 0.05) {
float rippleStrengthModifier = (wetnessOcclusion * wetnessOcclusion) * distanceFadeout;
raindropInfo = WetnessEffects::GetRainDrops(input.WPosition + CameraPosAdjust[a_eyeIndex], wetnessEffectsSettings.Time, finalNormal, rippleStrengthModifier);
}

float3 rippleNormal = normalize(raindropInfo.xyz);
finalNormal = WetnessEffects::ReorientNormal(rippleNormal, finalNormal);
# endif

return finalNormal;
}

Expand Down

0 comments on commit 66a0a97

Please sign in to comment.