diff --git a/features/Water Lighting/Shaders/WaterLighting/WaterCaustics.hlsli b/features/Water Lighting/Shaders/WaterLighting/WaterCaustics.hlsli index b8e379391..bb53cfd7c 100644 --- a/features/Water Lighting/Shaders/WaterLighting/WaterCaustics.hlsli +++ b/features/Water Lighting/Shaders/WaterLighting/WaterCaustics.hlsli @@ -2,13 +2,9 @@ Texture2D WaterCaustics : register(t70); namespace WaterLighting { - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Caustics - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - float2 PanCausticsUV(float2 uv, float speed, float tiling) { - return (float2(1, 0) * Timer * speed) + (uv * tiling); + return frac((float2(1, 0) * Timer * speed) + (uv * tiling)); } float3 SampleCaustics(float2 uv) @@ -16,57 +12,36 @@ namespace WaterLighting return WaterCaustics.Sample(SampColorSampler, uv).r; } - float3 ComputeCaustics(float2 uv) - { - float2 causticsUV = uv * 10.0; - - float2 causticsUV1 = PanCausticsUV(causticsUV, 0.5 * 0.2, 1.0); - float2 causticsUV2 = PanCausticsUV(causticsUV, 1.0 * 0.2, -0.5); - - float3 caustics1 = SampleCaustics(causticsUV1); - float3 caustics2 = SampleCaustics(causticsUV2); - - float3 caustics = min(caustics1, caustics2) * 5.0; - - return caustics; - } - - float3 ComputeCaustics(float4 waterData, float3 worldPosition, float3 worldSpaceNormal) + float3 ComputeCaustics(float4 waterData, float3 worldPosition, uint eyeIndex) { float causticsDistToWater = waterData.w - worldPosition.z; float shoreFactorCaustics = saturate(causticsDistToWater / 64.0); - float upAmount = worldSpaceNormal.z * 0.5 + 0.5; - - float causticsAmount = shoreFactorCaustics * upAmount; - if (causticsAmount > 0.0) { + if (shoreFactorCaustics > 0.0) { float causticsFade = 1.0 - saturate(causticsDistToWater / 1024.0); causticsFade *= causticsFade; - float2 causticsUV = (worldPosition.xy + CameraPosAdjust[0].xy) * 0.005; + float2 causticsUV = (worldPosition.xy + CameraPosAdjust[eyeIndex].xy) * 0.005; float2 causticsUV1 = PanCausticsUV(causticsUV, 0.5 * 0.2, 1.0); float2 causticsUV2 = PanCausticsUV(causticsUV, 1.0 * 0.2, -0.5); - float3 caustics1 = SampleCaustics(causticsUV1); - float3 caustics2 = SampleCaustics(causticsUV2); - - float3 causticsHigh = min(caustics1, caustics2) * 5.0; + float3 causticsHigh = 1.0; + + if (causticsFade > 0.0) + causticsHigh = min(SampleCaustics(causticsUV1), SampleCaustics(causticsUV2)); causticsUV *= 0.5; causticsUV1 = PanCausticsUV(causticsUV, 0.5 * 0.1, 1.0); causticsUV2 = PanCausticsUV(causticsUV, 1.0 * 0.1, -0.5); - caustics1 = SampleCaustics(causticsUV1); - caustics2 = SampleCaustics(causticsUV2); - - float3 causticsLow = sqrt(min(caustics1, caustics2)); + float3 causticsLow = 1.0; - float3 caustics = lerp(causticsLow, causticsHigh, causticsFade); - caustics = lerp(causticsLow, caustics, upAmount); + if (causticsFade < 1.0) + causticsLow = min(SampleCaustics(causticsUV1), SampleCaustics(causticsUV2)); - return lerp(1.0, caustics, shoreFactorCaustics * upAmount); + return lerp(causticsLow * 4.0, causticsHigh * 4.0, causticsFade); } return 1.0; diff --git a/package/Shaders/Lighting.hlsl b/package/Shaders/Lighting.hlsl index 87220fa15..f840f3011 100644 --- a/package/Shaders/Lighting.hlsl +++ b/package/Shaders/Lighting.hlsl @@ -1855,7 +1855,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 dirLightColorMultiplier = 1; # if defined(WATER_LIGHTING) - dirLightColorMultiplier *= WaterLighting::ComputeCaustics(waterData, input.WorldPosition.xyz, worldSpaceNormal); + dirLightColorMultiplier *= WaterLighting::ComputeCaustics(waterData, input.WorldPosition.xyz, eyeIndex); # endif float selfShadowFactor = 1.0f; diff --git a/package/Shaders/RunGrass.hlsl b/package/Shaders/RunGrass.hlsl index 82312f2b4..edea5ce02 100644 --- a/package/Shaders/RunGrass.hlsl +++ b/package/Shaders/RunGrass.hlsl @@ -412,6 +412,10 @@ cbuffer AlphaTestRefCB : register(b11) # include "Skylighting/Skylighting.hlsli" # endif +# if defined(WATER_LIGHTING) +# include "WaterLighting/WaterCaustics.hlsli" +# endif + # ifdef GRASS_LIGHTING # if defined(TRUE_PBR) @@ -540,7 +544,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float dirShadow = !InInterior ? shadowColor.x : 1.0; float dirDetailShadow = 1.0; - if (dirShadow > 0.0) { + if (dirShadow > 0.0 && !InInterior) { if (dirLightAngle > 0.0) { # if defined(SCREEN_SPACE_SHADOWS) dirDetailShadow = ScreenSpaceShadows::GetScreenSpaceShadow(input.HPosition.xyz, screenUV, screenNoise, eyeIndex); @@ -555,10 +559,17 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # endif // TERRAIN_SHADOWS # if defined(CLOUD_SHADOWS) - if (dirShadow != 0.0) { + if (dirShadow > 0.0) { dirShadow *= CloudShadows::GetCloudShadowMult(input.WorldPosition.xyz, SampBaseSampler); } # endif // CLOUD_SHADOWS + +# if defined(WATER_LIGHTING) + if (dirShadow > 0.0) { + float4 waterData = SharedData::GetWaterData(input.WorldPosition.xyz); + dirShadow *= WaterLighting::ComputeCaustics(waterData, input.WorldPosition.xyz, eyeIndex); + } +# endif } float3 diffuseColor = 0; @@ -764,10 +775,9 @@ PS_OUTPUT main(PS_INPUT input) float4 shadowColor = TexShadowMaskSampler.Load(int3(input.HPosition.xy, 0)); float dirShadow = !InInterior ? shadowColor.x : 1.0; - float dirDetailShadow = 1.0; - if (dirShadow > 0.0) { + if (dirShadow > 0.0 && !InInterior) { # if defined(SCREEN_SPACE_SHADOWS) dirDetailShadow = ScreenSpaceShadows::GetScreenSpaceShadow(input.HPosition.xyz, screenUV, screenNoise, eyeIndex); # endif // SCREEN_SPACE_SHADOWS @@ -780,10 +790,17 @@ PS_OUTPUT main(PS_INPUT input) # endif // TERRAIN_SHADOWS # if defined(CLOUD_SHADOWS) - if (dirShadow != 0.0) { + if (dirShadow > 0.0) { dirShadow *= CloudShadows::GetCloudShadowMult(input.WorldPosition.xyz, SampBaseSampler); } # endif // CLOUD_SHADOWS + +# if defined(WATER_LIGHTING) + if (dirShadow > 0.0) { + float4 waterData = SharedData::GetWaterData(input.WorldPosition.xyz); + dirShadow *= WaterLighting::ComputeCaustics(waterData, input.WorldPosition.xyz, eyeIndex); + } +# endif } float3 diffuseColor = DirLightColorShared.xyz * dirShadow * lerp(dirDetailShadow, 1.0, 0.5) * 0.5;