Skip to content

Commit 4497482

Browse files
robust ray origins (work out the transforms like PBRT does)
1 parent 5103cd2 commit 4497482

File tree

5 files changed

+65
-19
lines changed

5 files changed

+65
-19
lines changed

examples_tests/22.RaytracedAO/Renderer.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Renderer::Renderer(IVideoDriver* _driver, IAssetManager* _assetManager, scene::I
4949
#ifdef _NBL_BUILD_OPTIX_
5050
m_optixManager(), m_cudaStream(nullptr), m_optixContext(),
5151
#endif
52-
m_prevView(), m_sceneBound(FLT_MAX,FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX,-FLT_MAX),
52+
m_prevView(), m_prevCamTform(), m_sceneBound(FLT_MAX,FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX,-FLT_MAX),
5353
m_framesDispatched(0u), m_rcpPixelSize{0.f,0.f},
5454
m_staticViewData{{0.f,0.f,0.f},0u,{0u,0u},0u,0u}, m_raytraceCommonData{vec3(),0.f,0u,0u,0u,0u},
5555
m_indirectDrawBuffers{nullptr},m_cullPushConstants{core::matrix4SIMD(),1.f,0u,0u,0u},m_cullWorkGroups(0u),
@@ -1163,15 +1163,14 @@ void Renderer::render(nbl::ITimer* timer)
11631163

11641164
// check if camera moved
11651165
{
1166-
const auto currentView = camera->getViewMatrix();
1167-
auto properEquals = [](const auto& lhs, const auto& rhs) -> bool
1166+
auto properEquals = [](const core::matrix4x3& lhs, const core::matrix4x3& rhs) -> bool
11681167
{
11691168
const float rotationTolerance = 1.01f;
11701169
const float positionTolerance = 1.005f;
11711170
for (auto r=0; r<3u; r++)
11721171
for (auto c=0; c<4u; c++)
11731172
{
1174-
const float ratio = core::abs(rhs.rows[r][c]/lhs.rows[r][c]);
1173+
const float ratio = core::abs((&rhs.getColumn(c).X)[r]/(&lhs.getColumn(c).X)[r]);
11751174
// TODO: do by ULP
11761175
if (core::isnan(ratio) || core::isinf(ratio))
11771176
continue;
@@ -1181,17 +1180,15 @@ void Renderer::render(nbl::ITimer* timer)
11811180
}
11821181
return true;
11831182
};
1184-
if (!properEquals(currentView,m_prevView))
1183+
auto tform = camera->getRelativeTransformationMatrix();
1184+
if (!properEquals(tform,m_prevCamTform))
11851185
{
11861186
m_framesDispatched = 0u;
1187-
m_prevView = currentView;
1187+
m_prevView = camera->getViewMatrix();
1188+
m_prevCamTform = tform;
11881189
}
11891190
else // need this to stop mouse cursor drift
1190-
{
1191-
core::matrix3x4SIMD invView;
1192-
m_prevView.getInverse(invView);
1193-
camera->setRelativeTransformationMatrix(invView.getAsRetardedIrrlichtMatrix());
1194-
}
1191+
camera->setRelativeTransformationMatrix(m_prevCamTform);
11951192
}
11961193

11971194
// TODO: update positions and rr->Commit() if stuff starts to move

examples_tests/22.RaytracedAO/Renderer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
128128
nbl::core::vector<::RadeonRays::Shape*> rrInstances;
129129

130130
nbl::core::matrix3x4SIMD m_prevView;
131+
nbl::core::matrix4x3 m_prevCamTform;
131132
nbl::core::aabbox3df m_sceneBound;
132133
uint32_t m_framesDispatched;
133134
vec2 m_rcpPixelSize;

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,13 @@ for (uint i=1u; i!=vertex_depth; i++)
290290
const uint baseOutputID = atomicAdd(rayCount[pc.cummon.rayCountWriteIx],raysToAllocate);
291291

292292
// TODO: improve
293-
const vec3 error = vec3(0.0001f);// abs(origin)* uintBitsToFloat(0x35480005);
293+
const vec3 error = vec3(0.01f);// abs(origin)* uintBitsToFloat(0x35480005);
294294
uint offset = 0u;
295295
for (uint i=0u; i<maxRaysToGen; i++)
296296
if (maxT[i]!=0.f)
297297
{
298298
nbl_glsl_ext_RadeonRays_ray newRay;
299-
newRay.origin = origin+direction[i]*0.002;// nbl_glsl_robust_ray_origin(origin, direction[i], error, normalizedN);
299+
newRay.origin = nbl_glsl_robust_ray_origin(origin,direction[i],error,normalizedN);
300300
newRay.maxT = maxT[i];
301301
newRay.direction = direction[i];
302302
newRay.time = packOutPixelLocation(outPixelLocation);

include/nbl/builtin/glsl/limits/numeric.glsl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,25 @@ float nbl_glsl_numeric_limits_float_epsilon()
6969
return nbl_glsl_FLT_EPSILON;
7070
}
7171

72+
7273
float nbl_glsl_ieee754_gamma(float n)
7374
{
7475
const float a = nbl_glsl_numeric_limits_float_epsilon(n);
7576
return a/(1.f-a);
7677
}
78+
float nbl_glsl_ieee754_rcpgamma(float n)
79+
{
80+
const float a = nbl_glsl_numeric_limits_float_epsilon(n);
81+
return 1.f/a-1.f;
82+
}
83+
7784
float nbl_glsl_ieee754_gamma(uint n)
7885
{
7986
return nbl_glsl_ieee754_gamma(float(n));
8087
}
88+
float nbl_glsl_ieee754_rcpgamma(uint n)
89+
{
90+
return nbl_glsl_ieee754_rcpgamma(float(n));
91+
}
8192

8293
#endif

include/nbl/builtin/glsl/utils/transform.glsl

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,56 @@
55
#ifndef _NBL_BUILTIN_GLSL_UTILS_TRANSFORM_INCLUDED_
66
#define _NBL_BUILTIN_GLSL_UTILS_TRANSFORM_INCLUDED_
77

8+
mat3 nbl_glsl_mul_with_bounds_wo_gamma(out mat3 error, in mat3 a, in mat3 b, in mat3 b_error)
9+
{
10+
mat3 retval;
11+
for (int i=0; i<3; i++)
12+
{
13+
vec3 tmp = a[0]*b[i][0];
14+
retval[i] = tmp;
15+
error[i] = abs(tmp);
16+
vec3 additional_error = abs(a[0]*b_error[i][0]);
17+
for (int j=1; j<3; j++)
18+
{
19+
tmp = a[j]*b[i][j];
20+
retval[i] += tmp;
21+
error[i] += abs(tmp);
22+
additional_error += abs(a[j]*b_error[i][j]);
23+
}
24+
additional_error *= nbl_glsl_ieee754_rcpgamma(2u)+1.f;
25+
error[i] += additional_error;
26+
}
27+
return retval;
28+
}
29+
mat3 nbl_glsl_mul_with_bounds_wo_gamma(out mat3 error, in mat3 a, in mat3 b)
30+
{
31+
mat3 retval;
32+
for (int i=0; i<3; i++)
33+
{
34+
vec3 tmp = a[0]*b[i][0];
35+
retval[i] = tmp;
36+
error[i] = abs(tmp);
37+
for (int j=1; j<3; j++)
38+
{
39+
tmp = a[j]*b[i][j];
40+
retval[i] += tmp;
41+
error[i] += abs(tmp);
42+
}
43+
}
44+
return retval;
45+
}
46+
847
mat3 nbl_glsl_mul_with_bounds(out mat3 error, in mat3 a, in mat3 b, in mat3 b_error)
948
{
10-
// error = abs(tform[0]*positions.x)+abs(tform[1]*positions.y)+abs(tform[2]*positions.z);
11-
// error *= nbl_glsl_ieee754_gamma(2u);
12-
return a*b;
49+
return nbl_glsl_mul_with_bounds_wo_gamma(error,a,b,b_error);
1350
}
51+
1452
mat3 nbl_glsl_mul_with_bounds(out mat3 error, in mat3 a, in mat3 b)
1553
{
16-
// error = abs(tform[0]*positions.x)+abs(tform[1]*positions.y)+abs(tform[2]*positions.z);
17-
// error *= nbl_glsl_ieee754_gamma(2u);
18-
return a*b;
54+
return nbl_glsl_mul_with_bounds_wo_gamma(error,a,b);
1955
}
2056

57+
2158
vec4 nbl_glsl_pseudoMul4x4with3x1(in mat4 m, in vec3 v)
2259
{
2360
return m[0] * v.x + m[1] * v.y + m[2] * v.z + m[3];

0 commit comments

Comments
 (0)