Skip to content

Commit c55b97d

Browse files
Restore lights in RTAO, at least on the CPU side + cleanups
1 parent dbbf5fb commit c55b97d

File tree

8 files changed

+435
-550
lines changed

8 files changed

+435
-550
lines changed

examples_tests/22.RaytracedAO/InstanceDataPerCamera.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
struct InstanceDataPerCamera
77
{
88
mat4 MVP;
9-
mat4x3 NormalMatrix;
9+
mat4x3 NormalMatAndFlags;
1010
};
1111

1212
#endif

examples_tests/22.RaytracedAO/common.glsl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,55 @@
33

44
#define MAX_ACCUMULATED_SAMPLES (1024*1024)
55

6+
67
#ifdef __cplusplus
78
#define mat4 irr::core::matrix4SIMD
89
#define mat4x3 irr::core::matrix3x4SIMD
910
#endif
1011

1112

13+
struct SLight
14+
{
15+
#ifdef __cplusplus
16+
SLight() : obb() {}
17+
SLight(const SLight& other) : obb(other.obb) {}
18+
SLight(const irr::core::aabbox3df& bbox, const irr::core::matrix3x4SIMD& tform) : SLight()
19+
{
20+
auto extent = bbox.getExtent();
21+
obb.setScale(irr::core::vectorSIMDf(extent.X,extent.Y,extent.Z));
22+
obb.setTranslation(irr::core::vectorSIMDf(bbox.MinEdge.X,bbox.MinEdge.Y,bbox.MinEdge.Z));
23+
24+
obb = irr::core::concatenateBFollowedByA(tform,obb);
25+
}
26+
27+
inline SLight& operator=(SLight&& other) noexcept
28+
{
29+
std::swap(obb, other.obb);
30+
31+
return *this;
32+
}
33+
34+
// also known as an upper bound on lumens put into the scene
35+
inline float computeFluxBound(const irr::core::vectorSIMDf& radiance) const
36+
{
37+
const irr::core::vectorSIMDf rec709LumaCoeffs(0.2126f, 0.7152f, 0.0722f, 0.f);
38+
const auto unitHemisphereArea = 2.f*irr::core::PI<float>();
39+
40+
const auto unitBoxScale = obb.getScale();
41+
const float obbArea = 2.f*(unitBoxScale.x*unitBoxScale.y+unitBoxScale.x*unitBoxScale.z+unitBoxScale.y*unitBoxScale.z);
42+
43+
return irr::core::dot(radiance,rec709LumaCoeffs).x*unitHemisphereArea*obbArea;
44+
}
45+
#endif
46+
47+
mat4x3 obb; // needs row_major qualifier
48+
};
49+
50+
51+
#ifdef __cplusplus
52+
#undef mat4
53+
#undef mat4x3
54+
#endif
55+
56+
1257
#endif

0 commit comments

Comments
 (0)