Skip to content

Commit e54ca9f

Browse files
committed
Fix numerical integration issues
1 parent b7ab076 commit e54ca9f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,10 @@ void IntegrateBSDF_LineRef(float3 V, float3 positionWS,
763763

764764
BSDF(V, L, positionWS, preLightData, bsdfData, lightDiff, lightSpec);
765765

766+
// The value of the specular BSDF could be infinite.
767+
// Summing up infinities leads to NaNs.
768+
lightSpec = min(lightSpec, FLT_MAX);
769+
766770
diffuseLighting += lightDiff * (sinLT / dist2 * NdotL);
767771
specularLighting += lightSpec * (sinLT / dist2 * NdotL);
768772
}

Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ void GetCubeFaceID(float3 dir, out int faceIndex)
216216
#define HALF_PI 1.57079632679
217217
#define INV_HALF_PI 0.636619772367
218218

219-
#define FLT_EPSILON 1.192092896e-07f // smallest such that 1.0 + FLT_EPSILON != 1.0
219+
#define FLT_EPSILON 1.192092896e-07 // Smallest positive number, such that 1.0 + FLT_EPSILON != 1.0
220+
#define FLT_MAX 3.402823466e+38 // Maximum representable floating-point number
220221

221222
#define MERGE_NAME(X, Y) X##Y
222223

0 commit comments

Comments
 (0)