Merge pull request #1352 from marauder2k9-torque/Probe-baking-matrix-issues

BUG: Probe baking look at matrix was wrong
This commit is contained in:
Brian Roberts 2025-01-07 09:46:52 -06:00 committed by GitHub
commit 67ae3d136b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 56 additions and 56 deletions

View file

@ -508,30 +508,24 @@ inline MatrixF& MatrixF::add( const MatrixF& a )
inline void MatrixF::LookAt(const VectorF& eye, const VectorF& target, const VectorF& up) inline void MatrixF::LookAt(const VectorF& eye, const VectorF& target, const VectorF& up)
{ {
VectorF yAxis = target - eye; // Forward // Calculate the forward vector (camera direction).
yAxis.normalize(); VectorF zAxis = target; // Camera looks towards the target
zAxis.normalize();
VectorF xAxis = mCross(up, yAxis); // Right // Calculate the right vector.
VectorF xAxis = mCross(up, zAxis);
xAxis.normalize(); xAxis.normalize();
VectorF zAxis = mCross(yAxis, xAxis); // Up // Recalculate the up vector.
VectorF yAxis = mCross(zAxis, xAxis);
// Right vector. // Set the rotation part of the matrix (camera axes).
setColumn(0, xAxis); setColumn(0, xAxis); // Right
m[12] = -mDot(xAxis, eye); setColumn(1, zAxis); // Forward
setColumn(2, yAxis); // Up
// Forward vector. // Set the translation part (camera position).
setColumn(1, yAxis); setPosition(eye);
m[13] = -mDot(yAxis, eye);
// Up vector.
setColumn(2, zAxis);
m[14] = -mDot(zAxis, eye);
m[3] = 0.0f;
m[7] = 0.0f;
m[11] = 0.0f;
m[15] = 1.0f;
} }

View file

@ -566,13 +566,15 @@ void RenderProbeMgr::bakeProbe(ReflectionProbe* probe)
ReflectParams reflParams; ReflectParams reflParams;
MatrixF camTrans = clientProbe->getTransform();
camTrans.setPosition(clientProbe->getTransform().getPosition() + clientProbe->mProbeRefOffset);
//need to get the query somehow. Likely do some sort of get function to fetch from the guiTSControl that's active //need to get the query somehow. Likely do some sort of get function to fetch from the guiTSControl that's active
CameraQuery query; //need to get the last cameraQuery CameraQuery query; //need to get the last cameraQuery
query.fov = 90; //90 degree slices for each of the 6 sides query.fov = 90; //90 degree slices for each of the 6 sides
query.nearPlane = 0.1f; query.nearPlane = 0.0001f;
query.farPlane = farPlane; query.farPlane = farPlane;
query.headMatrix = MatrixF(); query.headMatrix = MatrixF();
query.cameraMatrix = clientProbe->getTransform(); query.cameraMatrix = camTrans;
Frustum culler; Frustum culler;
culler.set(false, culler.set(false,

View file

@ -326,36 +326,32 @@ void CubeReflector::updateReflection( const ReflectParams &params, Point3F expli
if ( mRenderTarget.isNull() ) if ( mRenderTarget.isNull() )
mRenderTarget = GFX->allocRenderToTextureTarget(); mRenderTarget = GFX->allocRenderToTextureTarget();
GFX->pushActiveRenderTarget();
mDepthBuff = LightShadowMap::_getDepthTarget(texDim, texDim); mDepthBuff = LightShadowMap::_getDepthTarget(texDim, texDim);
mRenderTarget->attachTexture(GFXTextureTarget::DepthStencil, mDepthBuff); mRenderTarget->attachTexture(GFXTextureTarget::DepthStencil, mDepthBuff);
F32 oldVisibleDist = gClientSceneGraph->getVisibleDistance(); F32 oldVisibleDist = gClientSceneGraph->getVisibleDistance();
gClientSceneGraph->setVisibleDistance( mDesc->farDist ); gClientSceneGraph->setVisibleDistance( mDesc->farDist );
// store current matrices
GFXTransformSaver saver;
F32 detailAdjustBackup = TSShapeInstance::smDetailAdjust; F32 detailAdjustBackup = TSShapeInstance::smDetailAdjust;
TSShapeInstance::smDetailAdjust *= mDesc->detailAdjust; TSShapeInstance::smDetailAdjust *= mDesc->detailAdjust;
// store current matrices
GFXTransformSaver saver;
// set projection to 90 degrees vertical and horizontal // set projection to 90 degrees vertical and horizontal
F32 left, right, top, bottom; F32 left, right, top, bottom;
MathUtils::makeFrustum(&left, &right, &top, &bottom, M_HALFPI_F, 1.0f, mDesc->nearDist); MathUtils::makeFrustum(&left, &right, &top, &bottom, M_HALFPI_F, 1.0f, mDesc->nearDist);
GFX->setFrustum(left, right, bottom, top, mDesc->nearDist, mDesc->farDist); GFX->setFrustum(left, right, bottom, top, mDesc->nearDist, mDesc->farDist);
// We don't use a special clipping projection, but still need to initialize GFX->pushActiveRenderTarget();
// this for objects like SkyBox which will use it during a reflect pass.
gClientSceneGraph->setNonClipProjection(GFX->getProjectionMatrix());
for (S32 i = 5; i >= 0; i--) { for (S32 i = 5; i >= 0; i--) {
updateFace(params, i, explicitPostion); updateFace(params, i, explicitPostion);
} }
GFX->popActiveRenderTarget();
TSShapeInstance::smDetailAdjust = detailAdjustBackup; TSShapeInstance::smDetailAdjust = detailAdjustBackup;
mCubemap->generateMipMaps(); mCubemap->generateMipMaps();
GFX->popActiveRenderTarget();
gClientSceneGraph->setVisibleDistance(oldVisibleDist); gClientSceneGraph->setVisibleDistance(oldVisibleDist);
@ -379,47 +375,51 @@ void CubeReflector::updateFace( const ReflectParams &params, U32 faceidx, Point3
eye = explicitPostion; eye = explicitPostion;
} }
VectorF vUpVec(0.0f, 0.0f, 0.0f); // Standard view that will be overridden below.
VectorF vLookatPt(0.0f, 0.0f, 0.0f), vUpVec(0.0f, 0.0f, 0.0f), vRight(0.0f, 0.0f, 0.0f);
switch( faceidx ) switch (faceidx)
{ {
case 0 : // D3DCUBEMAP_FACE_POSITIVE_X: case 0: // D3DCUBEMAP_FACE_POSITIVE_X:
target = eye + VectorF( 1.0f, 0.0f, 0.0f ); vLookatPt = VectorF(1.0f, 0.0f, 0.0f);
vUpVec = VectorF( 0.0f, 1.0f, 0.0f ); vUpVec = VectorF(0.0f, 1.0f, 0.0f);
break; break;
case 1 : // D3DCUBEMAP_FACE_NEGATIVE_X: case 1: // D3DCUBEMAP_FACE_NEGATIVE_X:
target = eye + VectorF( -1.0f, 0.0f, 0.0f ); vLookatPt = VectorF(-1.0f, 0.0f, 0.0f);
vUpVec = VectorF( 0.0f, 1.0f, 0.0f ); vUpVec = VectorF(0.0f, 1.0f, 0.0f);
break; break;
case 2 : // D3DCUBEMAP_FACE_POSITIVE_Y: case 2: // D3DCUBEMAP_FACE_POSITIVE_Y:
target = eye + VectorF( 0.0f, 1.0f, 0.0f ); vLookatPt = VectorF(0.0f, 1.0f, 0.0f);
vUpVec = VectorF( 0.0f, 0.0f,-1.0f ); vUpVec = VectorF(0.0f, 0.0f, -1.0f);
break; break;
case 3 : // D3DCUBEMAP_FACE_NEGATIVE_Y: case 3: // D3DCUBEMAP_FACE_NEGATIVE_Y:
target = eye + VectorF( 0.0f, -1.0f, 0.0f ); vLookatPt = VectorF(0.0f, -1.0f, 0.0f);
vUpVec = VectorF( 0.0f, 0.0f, 1.0f ); vUpVec = VectorF(0.0f, 0.0f, 1.0f);
break; break;
case 4 : // D3DCUBEMAP_FACE_POSITIVE_Z: case 4: // D3DCUBEMAP_FACE_POSITIVE_Z:
target = eye + VectorF( 0.0f, 0.0f, 1.0f ); vLookatPt = VectorF(0.0f, 0.0f, 1.0f);
vUpVec = VectorF( 0.0f, 1.0f, 0.0f ); vUpVec = VectorF(0.0f, 1.0f, 0.0f);
break; break;
case 5: // D3DCUBEMAP_FACE_NEGATIVE_Z: case 5: // D3DCUBEMAP_FACE_NEGATIVE_Z:
target = eye + VectorF( 0.0f, 0.0f, -1.0f ); vLookatPt = VectorF(0.0f, 0.0f, -1.0f);
vUpVec = VectorF( 0.0f, 1.0f, 0.0f ); vUpVec = VectorF(0.0f, 1.0f, 0.0f);
break; break;
} }
// create camera matrix // create camera matrix
MatrixF matView(true); MatrixF lightMatrix(true);
matView.LookAt(eye, target, vUpVec); lightMatrix.LookAt(eye, vLookatPt, vUpVec);
matView.inverse(); lightMatrix.inverse();
GFX->setWorldMatrix(matView); GFX->setWorldMatrix(lightMatrix);
GFX->clearTextureStateImmediate(0); GFX->clearTextureStateImmediate(0);
mRenderTarget->attachTexture( GFXTextureTarget::Color0, mCubemap, faceidx ); mRenderTarget->attachTexture( GFXTextureTarget::Color0, mCubemap, faceidx ); // Setup textures and targets...
S32 texDim = mDesc->texSize;
texDim = getMax(texDim, 32);
mRenderTarget->attachTexture(GFXTextureTarget::DepthStencil, LightShadowMap::_getDepthTarget(texDim, texDim));
GFX->setActiveRenderTarget(mRenderTarget); GFX->setActiveRenderTarget(mRenderTarget);
GFX->clear( GFXClearStencil | GFXClearTarget | GFXClearZBuffer, gCanvasClearColor, 0.0f, 0); GFX->clear( GFXClearStencil | GFXClearTarget | GFXClearZBuffer, gCanvasClearColor, 1.0f, 0);
SceneRenderState reflectRenderState SceneRenderState reflectRenderState
( (
@ -429,7 +429,11 @@ void CubeReflector::updateFace( const ReflectParams &params, U32 faceidx, Point3
); );
reflectRenderState.getMaterialDelegate().bind( REFLECTMGR, &ReflectionManager::getReflectionMaterial ); reflectRenderState.getMaterialDelegate().bind( REFLECTMGR, &ReflectionManager::getReflectionMaterial );
reflectRenderState.setDiffuseCameraTransform( params.query->headMatrix ); reflectRenderState.setDiffuseCameraTransform(lightMatrix);//params.query->headMatrix );
// We don't use a special clipping projection, but still need to initialize
// this for objects like SkyBox which will use it during a reflect pass.
gClientSceneGraph->setNonClipProjection(GFX->getProjectionMatrix());
// render scene // render scene
LIGHTMGR->registerGlobalLights( &reflectRenderState.getCullingFrustum(), false ); LIGHTMGR->registerGlobalLights( &reflectRenderState.getCullingFrustum(), false );