Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Common/Color.hlsli"
#include "Common/FrameBuffer.hlsli"
#include "Common/GBuffer.hlsli"
#include "Common/Math.hlsli"
#include "Common/VR.hlsli"
#include "ScreenSpaceGI/common.hlsli"

Expand Down Expand Up @@ -126,7 +127,7 @@ void readHistory(
prev_ao, prev_y, prev_co_cg, prev_ambient, accum_frames, prev_gi_specular, wsum);

if (wsum > 1e-2) {
float rcpWsum = rcp(wsum + 1e-10);
float rcpWsum = rcp(wsum + EPSILON_WEIGHT_SUM);
# ifdef TEMPORAL_DENOISER
prev_ao *= rcpWsum;
prev_y *= rcpWsum;
Expand Down
4 changes: 2 additions & 2 deletions features/Skylighting/Shaders/Skylighting/Skylighting.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace Skylighting
wsum += w;
}

return SphericalHarmonics::Scale(sum, rcp(wsum + 1e-10));
return SphericalHarmonics::Scale(sum, rcp(wsum + EPSILON_WEIGHT_SUM));
}

sh2 sampleNoBias(SharedData::SkylightingSettings params, Texture3D<sh2> probeArray, float3 positionMS)
Expand Down Expand Up @@ -157,7 +157,7 @@ namespace Skylighting
wsum += w;
}

return SphericalHarmonics::Scale(sum, rcp(wsum + 1e-10));
return SphericalHarmonics::Scale(sum, rcp(wsum + EPSILON_WEIGHT_SUM));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef TERRAIN_VARIATION_HLSLI
#define TERRAIN_VARIATION_HLSLI

#include "Common/Math.hlsli"
#include "Common/Random.hlsli"
#include "Common/SharedData.hlsli"

Expand Down Expand Up @@ -62,7 +63,7 @@ inline float3 NormalizeWeights(float3 weights)
// Skip expensive division if already normalized
if (abs(weightSum - 1.0) < 0.01)
return weights;
float rcpWeightSum = rcp(max(weightSum, 1e-6));
float rcpWeightSum = rcp(max(weightSum, EPSILON_DIVISION));
return weights * rcpWeightSum;
}

Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/Common/Glints/Glints2023.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ namespace Glints
// ACCURATE PIXEL FOOTPRINT ELLIPSE
float2 ellipseMajor, ellipseMinor;
GetGradientEllipse(duvdx, duvdy, ellipseMajor, ellipseMinor);
float ellipseRatio = length(ellipseMajor) / (length(ellipseMinor) + 1e-8);
float ellipseRatio = length(ellipseMajor) / (length(ellipseMinor) + EPSILON_GLINTS);

// SHARED GLINT NDF VALUES
float halfScreenSpaceScaler = screenSpaceScale * 0.5;
Expand Down
8 changes: 5 additions & 3 deletions package/Shaders/Common/Math.hlsli
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef __MATH_DEPENDENCY_HLSL__
#define __MATH_DEPENDENCY_HLSL__

#define EPSILON_SSS_ALBEDO 1e-3f // For albedo clamping in SSS calculations
#define EPSILON_DOT_CLAMP 1e-5f // For dot product clamping
#define EPSILON_DIVISION 1e-6f // For division to avoid division by zero
#define EPSILON_SSS_ALBEDO 1e-3f // For albedo clamping in SSS calculations
#define EPSILON_DOT_CLAMP 1e-5f // For dot product clamping
#define EPSILON_DIVISION 1e-6f // For division to avoid division by zero
#define EPSILON_GLINTS 1e-8f // For glints calculations
#define EPSILON_WEIGHT_SUM 1e-10f // For weight normalization

namespace Math
{
Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/Common/PBRMath.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace PBR
inline float HairGaussian(float B, float Theta)
{
// Guard against division by zero: clamp B to a minimum value
float B_safe = max(B, 1e-6);
float B_safe = max(B, EPSILON_DIVISION);
return exp(-0.5 * Theta * Theta / (B_safe * B_safe)) / (sqrt(Math::TAU) * B_safe);
}

Expand Down
Loading