Skip to content

Commit 12e6fd2

Browse files
committed
Fix deferred lighting one-frame stale InvViewProj shadow flicker
SceneBase::Update called m_lightManager->UpdateAndBind() before object updates. LightManager::UpdateDeferredCB builds InvViewProj from the static Camera matrices, but the Camera object's Update() (which refreshes those matrices) ran afterward, so the deferred CB was one frame stale. The lighting pass reconstructed world positions from this stale InvViewProj while the depth buffer had been written with the fresh matrices, producing a coherent world-space shear on any camera rotation. That shear projected every visible fragment into the wrong shadow-map texels simultaneously, causing full-terrain shadow flashes on vertical mouselook, jumping, and fast movement. Fix: update objects first so Camera::View/Projection reflect the current frame, then call UpdateAndBind so the deferred CB, shadow UBO, and geometry/lighting passes all see the same matrices.
1 parent 741027f commit 12e6fd2

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

Engine/src/SceneBase.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,22 @@ void SceneBase::Begin() {
136136
void SceneBase::Update(float deltaTime) {
137137
if (!bActive) return;
138138

139-
if (m_lightManager)
140-
m_lightManager->UpdateAndBind();
141-
139+
// Update objects FIRST so Camera::View/Projection reflect this frame's
140+
// rotation/position before any render-side UBO computes InvViewProj.
141+
// Why: LightManager::UpdateDeferredCB reads the static Camera matrices
142+
// to build InvViewProj for the deferred lighting pass. If it ran
143+
// before the camera object updated, InvViewProj was one frame stale
144+
// and the lighting pass reconstructed wrong world positions on any
145+
// camera rotation, causing whole-terrain shadow flicker.
142146
for (size_t i = 0; i < Objects.GetSize(); ++i) {
143147
if (Objects[i] && Objects[i]->IsActive() && !Objects[i]->HasParent()) {
144148
Objects[i]->Update(deltaTime);
145149
}
146150
}
147151

152+
if (m_lightManager)
153+
m_lightManager->UpdateAndBind();
154+
148155
if (m_skybox)
149156
m_skybox->Render();
150157

0 commit comments

Comments
 (0)