Skip to content

Commit

Permalink
Merge branch 'rain-fx-fixes' into rain-fix-update
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlum authored Nov 18, 2024
2 parents da40478 + f423f57 commit 574e906
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WetnessEffects
{
Texture2D<float4> TexPrecipOcclusion : register(t31);

// https://www.unrealengine.com/en-US/blog/physically-based-shading-on-mobile
float2 EnvBRDFApproxWater(float3 F0, float Roughness, float NoV)
{
Expand Down Expand Up @@ -58,15 +60,15 @@ namespace WetnessEffects
const float rippleBreadthRcp = rcp(wetnessEffectsSettings.RippleBreadth);

float2 gridUV = worldPos.xy * wetnessEffectsSettings.RaindropGridSizeRcp;
gridUV += normal.xy * 0.5;
gridUV += normal.xy;
int2 grid = floor(gridUV);
gridUV -= grid;

float3 rippleNormal = float3(0, 0, 1);
float wetness = 0;

if (wetnessEffectsSettings.EnableSplashes || wetnessEffectsSettings.EnableRipples)
for (int i = -1; i <= 1; i++)
if (wetnessEffectsSettings.EnableSplashes || wetnessEffectsSettings.EnableRipples) {
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
int2 gridCurr = grid + int2(i, j);
float tOffset = float(Random::iqint3(gridCurr)) * uintToFloat;
Expand Down Expand Up @@ -122,12 +124,7 @@ namespace WetnessEffects
}
}
}

if (wetnessEffectsSettings.EnableChaoticRipples) {
float3 turbulenceNormal = Random::perlinNoise(float3(worldPos.xy * wetnessEffectsSettings.ChaoticRippleScaleRcp, t * wetnessEffectsSettings.ChaoticRippleSpeed));
turbulenceNormal.z = turbulenceNormal.z * .5 + 5;
turbulenceNormal = normalize(turbulenceNormal);
rippleNormal = normalize(rippleNormal + float3(turbulenceNormal.xy * wetnessEffectsSettings.ChaoticRippleStrength, 0));
}
}

wetness *= wetnessEffectsSettings.SplashesStrength;
Expand Down
14 changes: 5 additions & 9 deletions package/Shaders/Common/SharedData.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ struct LightLimitFixSettings

struct WetnessEffectsSettings
{
row_major float4x4 OcclusionViewProj;

float Time;
float Raining;
float Wetness;
Expand All @@ -92,26 +94,20 @@ struct WetnessEffectsSettings

bool EnableSplashes;
bool EnableRipples;
bool EnableChaoticRipples;
float RaindropFxRange;

float RaindropGridSizeRcp;
float RaindropIntervalRcp;

float RaindropChance;
float SplashesLifetime;

float SplashesStrength;
float SplashesMinRadius;

float SplashesMaxRadius;
float RippleStrength;

float RippleRadius;
float RippleBreadth;
float RippleLifetimeRcp;
float ChaoticRippleStrength;

float ChaoticRippleScaleRcp;
float ChaoticRippleSpeed;
float RippleLifetimeRcp;
};

struct SkylightingSettings
Expand Down
19 changes: 13 additions & 6 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -1783,16 +1783,23 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# endif

float4 raindropInfo = float4(0, 0, 1, 0);
if (worldSpaceNormal.z > 0 && wetnessEffectsSettings.Raining > 0.0f && wetnessEffectsSettings.EnableRaindropFx &&
(dot(input.WorldPosition, input.WorldPosition) < wetnessEffectsSettings.RaindropFxRange * wetnessEffectsSettings.RaindropFxRange)) {
if (wetnessOcclusion > 0.0)
if (worldSpaceNormal.z > 0 && wetnessEffectsSettings.Raining > 0.0f && wetnessEffectsSettings.EnableRaindropFx) {
float4 precipOcclusionTexCoord = mul(wetnessEffectsSettings.OcclusionViewProj, float4(input.WorldPosition.xyz, 1));
precipOcclusionTexCoord.y = -precipOcclusionTexCoord.y;
float2 precipOcclusionUV = precipOcclusionTexCoord.xy * 0.5 + 0.5;

if (saturate(precipOcclusionUV.x) == precipOcclusionUV.x && saturate(precipOcclusionUV.y) == precipOcclusionUV.y) {
float precipOcclusionZ = WetnessEffects::TexPrecipOcclusion.SampleLevel(SampColorSampler, precipOcclusionUV, 0).x;

if (precipOcclusionTexCoord.z < precipOcclusionZ + 0.1)
# if defined(SKINNED)
raindropInfo = WetnessEffects::GetRainDrops(input.ModelPosition.xyz, wetnessEffectsSettings.Time, worldSpaceNormal);
raindropInfo = WetnessEffects::GetRainDrops(input.ModelPosition.xyz, wetnessEffectsSettings.Time, worldSpaceNormal);
# elif defined(DEFERRED)
raindropInfo = WetnessEffects::GetRainDrops(input.WorldPosition.xyz + CameraPosAdjust[eyeIndex].xyz, wetnessEffectsSettings.Time, worldSpaceNormal);
raindropInfo = WetnessEffects::GetRainDrops(input.WorldPosition.xyz + CameraPosAdjust[eyeIndex].xyz, wetnessEffectsSettings.Time, worldSpaceNormal);
# else
raindropInfo = WetnessEffects::GetRainDrops(!FrameParams.y ? input.ModelPosition.xyz : input.WorldPosition.xyz + CameraPosAdjust[eyeIndex].xyz, wetnessEffectsSettings.Time, worldSpaceNormal);
raindropInfo = WetnessEffects::GetRainDrops(!FrameParams.y ? input.ModelPosition.xyz : input.WorldPosition.xyz + CameraPosAdjust[eyeIndex].xyz, wetnessEffectsSettings.Time, worldSpaceNormal);
# endif
}
}

float rainWetness = wetnessEffectsSettings.Wetness * minWetnessAngle * wetnessEffectsSettings.MaxRainWetness;
Expand Down
6 changes: 3 additions & 3 deletions package/Shaders/Particle.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ PS_OUTPUT main(PS_INPUT input)
# endif // !VR

# if defined(ENVCUBE)
float2 precipitationOcclusionUv = (input.PrecipitationOcclusionTexCoord.xy * 0.5 + 0.5) * TextureSize.x;
float2 precipitationOcclusionUV = (input.PrecipitationOcclusionTexCoord.xy * 0.5 + 0.5) * TextureSize.x;
# ifdef VR
precipitationOcclusionUv *= DynamicResolutionParams1.x; // only difference in VR
precipitationOcclusionUV *= DynamicResolutionParams1.x; // only difference in VR
# endif
float precipitationOcclusion = -input.PrecipitationOcclusionTexCoord.z + TexPrecipitationOcclusionTexture.SampleLevel(SampSourceTexture, precipitationOcclusionUv, 0).x;
float precipitationOcclusion = -input.PrecipitationOcclusionTexCoord.z + TexPrecipitationOcclusionTexture.Load(float3(precipitationOcclusionUV, 0)).x;
float2 underwaterMaskUv = TextureSize.yz * input.Position.xy;
float underwaterMask = TexUnderwaterMask.Sample(SampUnderwaterMask, underwaterMaskUv).x;
if (precipitationOcclusion - underwaterMask < 0) {
Expand Down
Loading

0 comments on commit 574e906

Please sign in to comment.