Skip to content

Commit aa3453f

Browse files
authored
Added per-fragment reflection probe bound check (#597)
1 parent 8f14e4c commit aa3453f

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

Resources/Engine/Shaders/Common/Buffers/ReflectionUBO.ovfxh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ layout (std140, binding = 1) uniform ReflectionUBO
66
vec4 boxHalfExtents;
77
float brightness;
88
bool boxProjection;
9+
bool local;
910
} ubo_ReflectionProbeData;

Resources/Engine/Shaders/Lighting/IBL.ovfxh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#include ":Shaders/Common/Buffers/ReflectionUBO.ovfxh"
22

3+
bool IsPointInOBB(vec3 point, vec3 obbCenter, vec3 obbHalfExtents, mat3 obbOrientation)
4+
{
5+
vec3 localPoint = obbOrientation * (point - obbCenter);
6+
7+
return abs(localPoint.x) <= obbHalfExtents.x &&
8+
abs(localPoint.y) <= obbHalfExtents.y &&
9+
abs(localPoint.z) <= obbHalfExtents.z;
10+
}
11+
312
// https://seblagarde.wordpress.com/wp-content/uploads/2012/08/parallax_corrected_cubemap-siggraph2012.pdf
413
vec3 BoxProjectionOBB(vec3 reflectionVector, vec3 worldPos, vec3 probePos, vec3 obbCenter, vec3 obbHalfExtents, mat3 obbOrientation)
514
{
@@ -77,6 +86,17 @@ vec3 CalculateImageBasedLighting(
7786
float transmission,
7887
float refractionIndex
7988
) {
89+
// Early exit if the fragment is outside the reflection probe bounds
90+
if (ubo_ReflectionProbeData.local && !IsPointInOBB(
91+
fragPos,
92+
ubo_ReflectionProbeData.boxCenter.xyz,
93+
ubo_ReflectionProbeData.boxHalfExtents.xyz,
94+
mat3(ubo_ReflectionProbeData.rotation))
95+
)
96+
{
97+
return vec3(0.0); // No reflection/refraction.
98+
}
99+
80100
// 0. Constants
81101
const int environmentMaxLOD = textureQueryLevels(environmentMap) - 1;
82102

Sources/Overload/OvCore/src/OvCore/ECS/Components/CReflectionProbe.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ namespace
2424
sizeof(OvMaths::FVector4) + // Box Center (vec3)
2525
sizeof(OvMaths::FVector4) + // Box Extents (vec3)
2626
sizeof(float) + // Brightness (float)
27-
sizeof(int); // Box Projection (bool)
27+
sizeof(int) + // Box Projection (bool)
28+
sizeof(int); // Local (bool)
2829

2930
constexpr uint32_t kBackBufferIndex = 0; // Cubemap that is being rendered
3031
constexpr uint32_t kCompleteBufferIndex = 1; // Cubemap that is used
@@ -432,14 +433,17 @@ void OvCore::ECS::Components::CReflectionProbe::_PrepareUBO()
432433
OvMaths::FVector4 boxHalfExtents;
433434
float brightness;
434435
bool boxProjection;
435-
std::byte padding[3];
436+
std::byte padding1[3];
437+
bool local;
438+
std::byte padding2[3];
436439
} uboDataPage{
437440
.position = probePosition,
438441
.rotation = probeRotationMatrix,
439442
.boxCenter = boxPosition,
440443
.boxHalfExtents = m_influenceSize,
441444
.brightness = m_brightness,
442445
.boxProjection = m_boxProjection && m_influencePolicy == EInfluencePolicy::LOCAL,
446+
.local = m_influencePolicy == EInfluencePolicy::LOCAL,
443447
};
444448
#pragma pack(pop)
445449

0 commit comments

Comments
 (0)