Skip to content

Commit bd09830

Browse files
fix up the camera drift a little bit more
1 parent 7842c90 commit bd09830

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

examples_tests/22.RaytracedAO/dirty_source/ExtraCrap.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Renderer::Renderer(IVideoDriver* _driver, IAssetManager* _assetManager, scene::I
5050
#ifdef _IRR_BUILD_OPTIX_
5151
m_optixManager(), m_cudaStream(nullptr), m_optixContext(),
5252
#endif
53-
rrShapeCache(), rrInstances(), m_prevViewProj(), m_sceneBound(FLT_MAX,FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX,-FLT_MAX),
53+
rrShapeCache(), rrInstances(), m_prevView(), m_sceneBound(FLT_MAX,FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX,-FLT_MAX),
5454
m_maxRaysPerDispatch(0), m_staticViewData{{0.f,0.f,0.f},0u,{0.f,0.f},{0.f,0.f},{0u,0u},0u,0u},
5555
m_raytraceCommonData{core::matrix4SIMD(),core::matrix3x4SIMD(),0,0,0},
5656
m_indirectDrawBuffers{nullptr},m_cullPushConstants{core::matrix4SIMD(),1.f,0u,0u,0u},m_cullWorkGroups(0u),
@@ -994,7 +994,7 @@ void Renderer::deinit()
994994
m_raytraceCommonData = {core::matrix4SIMD(),core::matrix3x4SIMD(),0,0,0};
995995
m_staticViewData = {{0.f,0.f,0.f},0u,{0.f,0.f},{0.f,0.f},{0u,0u},0u,0u};
996996
m_maxRaysPerDispatch = 0u;
997-
std::fill_n(m_prevViewProj.pointer(),16u,0.f);
997+
std::fill_n(m_prevView.pointer(),12u,0.f);
998998
m_sceneBound = core::aabbox3df(FLT_MAX, FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX);
999999

10001000
m_rrManager->detachInstances(rrInstances.begin(),rrInstances.end());
@@ -1021,32 +1021,25 @@ void Renderer::render(nbl::ITimer* timer)
10211021

10221022
// check if camera moved
10231023
{
1024-
const auto currentViewProj = camera->getConcatenatedMatrix();
1025-
auto properEquals = [](const auto& rhs, const auto& lhs) -> bool
1024+
const auto currentView = camera->getViewMatrix();
1025+
auto properEquals = [](const auto& lhs, const auto& rhs) -> bool
10261026
{
1027-
const float rotationTolerance = 1.001f;
1028-
const float positionTolerance = 1.005f;
1029-
const float projectionTolerance = 1.0005f;
1030-
const core::matrix4SIMD tolerance(
1031-
rotationTolerance,rotationTolerance,rotationTolerance,positionTolerance,
1032-
rotationTolerance,rotationTolerance,rotationTolerance,positionTolerance,
1033-
rotationTolerance,rotationTolerance,rotationTolerance,positionTolerance,
1034-
projectionTolerance,projectionTolerance,projectionTolerance,projectionTolerance
1035-
);
1036-
for (auto r=0; r<4u; r++)
1027+
const float rotationTolerance = 1.005f;
1028+
const float positionTolerance = 1.001f;
1029+
for (auto r=0; r<3u; r++)
10371030
for (auto c=0; c<4u; c++)
10381031
{
10391032
const float ratio = core::abs(rhs.rows[r][c]/lhs.rows[r][c]);
10401033
// TODO: do by ULP
10411034
if (core::isnan(ratio) || core::isinf(ratio))
10421035
continue;
1043-
if (ratio>tolerance.rows[r][c] || ratio*tolerance.rows[r][c]<1.f)
1036+
const float tolerance = c!=3u ? rotationTolerance:positionTolerance;
1037+
if (ratio>tolerance || ratio*tolerance<1.f)
10441038
return false;
10451039
}
10461040
return true;
10471041
};
1048-
//static core::matrix4x3 prevView;
1049-
if (!properEquals(m_prevViewProj,currentViewProj))
1042+
if (!properEquals(currentView,m_prevView))
10501043
{
10511044
m_raytraceCommonData.framesDispatched = 0u;
10521045

@@ -1056,18 +1049,21 @@ void Renderer::render(nbl::ITimer* timer)
10561049
m_driver->clearColorBuffer(EFAP_COLOR_ATTACHMENT0, clearAccumulation);
10571050
}
10581051

1059-
m_prevViewProj = currentViewProj;
1060-
//prevView = camera->getRelativeTransformationMatrix();
1052+
m_prevView = currentView;
1053+
}
1054+
else // need this to stop mouse cursor drift
1055+
{
1056+
core::matrix3x4SIMD invView;
1057+
m_prevView.getInverse(invView);
1058+
camera->setRelativeTransformationMatrix(invView.getAsRetardedIrrlichtMatrix());
10611059
}
1062-
//else // need this to stop mouse cursor drift
1063-
//camera->setRelativeTransformationMatrix(prevView);
10641060
}
10651061
// draw jittered frame
10661062
{
10671063
// jitter with AA AntiAliasingSequence
10681064
const auto modifiedViewProj = [&](uint32_t frameID)
10691065
{
1070-
const float stddev = 1.25f;
1066+
const float stddev = 0.707f;
10711067
const float* sample = AntiAliasingSequence[frameID];
10721068
const float phi = core::PI<float>()*(2.f*sample[1]-1.f);
10731069
const float sinPhi = sinf(phi);
@@ -1077,7 +1073,7 @@ void Renderer::render(nbl::ITimer* timer)
10771073
core::matrix4SIMD jitterMatrix;
10781074
jitterMatrix.rows[0][3] = cosPhi*r*m_staticViewData.rcpPixelSize.x;
10791075
jitterMatrix.rows[1][3] = sinPhi*r*m_staticViewData.rcpPixelSize.y;
1080-
return core::concatenateBFollowedByA(jitterMatrix,m_prevViewProj);
1076+
return core::concatenateBFollowedByA(jitterMatrix,core::concatenateBFollowedByA(camera->getProjectionMatrix(),m_prevView));
10811077
}(m_raytraceCommonData.framesDispatched++);
10821078
m_raytraceCommonData.rcpFramesDispatched = 1.f/float(m_raytraceCommonData.framesDispatched);
10831079

examples_tests/22.RaytracedAO/dirty_source/ExtraCrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
125125
nbl::ext::RadeonRays::Manager::MeshBufferRRShapeCache rrShapeCache;
126126
nbl::ext::RadeonRays::Manager::NblInstanceRRInstanceCache rrInstances;
127127

128-
nbl::core::matrix4SIMD m_prevViewProj;
128+
nbl::core::matrix3x4SIMD m_prevView;
129129
nbl::core::aabbox3df m_sceneBound;
130130
uint32_t m_maxRaysPerDispatch;
131131
StaticViewData_t m_staticViewData;

0 commit comments

Comments
 (0)