Apply matrix basis change transparently to projection instead of view

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 10 years ago
parent 5b59e6ba95
commit 3a2f04bfb5

@ -192,6 +192,15 @@ CDriverGL3::CDriverGL3()
_DefaultCursor = EmptyCursor;
_BlankCursor = EmptyCursor;
// Create change basis matrix matrix
{
CVector I(1, 0, 0);
CVector J(0, 0, -1);
CVector K(0, 1, 0);
_ChangeBasis.identity();
_ChangeBasis.setRot(I, J, K, true);
}
_AlphaBlendedCursorSupported = false;
_AlphaBlendedCursorSupportRetrieved = false;
_CurrCol = CRGBA::White;

@ -74,7 +74,6 @@
#include "unix_event_emitter.h"
#endif // NL_OS_UNIX
// For optimisation consideration, allow 256 lightmaps at max.
#define NL3D_DRV_MAX_LIGHTMAP 256
#define UNSUPPORTED_INDEX_OFFSET_MSG "Unsupported by driver, check IDriver::supportIndexOffset."
@ -862,6 +861,8 @@ private:
// Precision ZBuffer: The Current cameraPosition, to remove from each model Position.
CVector _PZBCameraPos;
// Change to OpenGL matrix basis for render output. Transparently applied to projection matrix.
CMatrix _ChangeBasis;
// Current computed (OpenGL basis) ModelView matrix.
// NB: This matrix have already substracted the _PZBCameraPos

@ -59,14 +59,7 @@ void CDriverGL3::setupViewMatrixEx(const CMatrix& mtx, const CVector &cameraPos)
_UserViewMtx= mtx;
// Setup the matrix to transform the CScene basis in openGL basis.
CMatrix changeBasis;
CVector I(1,0,0);
CVector J(0,0,-1);
CVector K(0,1,0);
changeBasis.identity();
changeBasis.setRot(I,J,K, true);
_ViewMtx=changeBasis*mtx;
_ViewMtx = mtx;
// Reset the viewMtx position.
_ViewMtx.setPos(CVector::Null);
_PZBCameraPos= cameraPos;
@ -74,7 +67,6 @@ void CDriverGL3::setupViewMatrixEx(const CMatrix& mtx, const CVector &cameraPos)
_SpecularTexMtx = _ViewMtx;
_SpecularTexMtx.setPos(CVector(0.0f,0.0f,0.0f));
_SpecularTexMtx.invert();
_SpecularTexMtx = changeBasis * _SpecularTexMtx;
}
@ -84,23 +76,13 @@ void CDriverGL3::setupViewMatrix(const CMatrix& mtx)
H_AUTO_OGL(CDriverGL3_setupViewMatrix)
_UserViewMtx= mtx;
// Setup the matrix to transform the CScene basis in openGL basis.
CMatrix changeBasis;
CVector I(1,0,0);
CVector J(0,0,-1);
CVector K(0,1,0);
changeBasis.identity();
changeBasis.setRot(I,J,K, true);
_ViewMtx=changeBasis*mtx;
_ViewMtx = mtx;
// Just set the PZBCameraPos to 0.
_PZBCameraPos= CVector::Null;
_SpecularTexMtx = _ViewMtx;
_SpecularTexMtx.setPos(CVector(0.0f,0.0f,0.0f));
_SpecularTexMtx.invert();
_SpecularTexMtx = changeBasis * _SpecularTexMtx;
}
// ***************************************************************************

@ -547,7 +547,7 @@ void ppGenerate(std::string &result, const CPPBuiltin &desc, CGlExtensions &glex
//case CShaderDesc::Linear:
ss << "vec4 applyFog(vec4 col)" << std::endl;
ss << "{" << std::endl;
ss << "float z = ecPos.z / ecPos.w;" << std::endl;
ss << "float z = ecPos.y / ecPos.w;" << std::endl;
ss << "z = abs(z);" << std::endl;
ss << "float fogFactor = (fogParams.t - z) / (fogParams.t - fogParams.s);" << std::endl;
ss << "fogFactor = clamp(fogFactor, 0.0, 1.0);" << std::endl;

@ -538,10 +538,10 @@ void CDriverGL3::setUniformMatrix(TProgram program, uint index, TMatrix matrix,
mat = _ModelViewMatrix;
break;
case IDriver::Projection:
mat = _GLProjMat;
mat = _GLProjMat * _ChangeBasis;
break;
case IDriver::ModelViewProjection:
mat = _ModelViewMatrix * _GLProjMat;
mat = _GLProjMat * _ChangeBasis * _ModelViewMatrix;
break;
}
@ -760,7 +760,7 @@ void CDriverGL3::setupUniforms(TProgram program)
uint mvpIndex = p->getUniformIndex(CProgramIndex::ModelViewProjection);
if (mvpIndex != ~0)
{
CMatrix mvp = _GLProjMat * _ModelViewMatrix;
CMatrix mvp = _GLProjMat * _ChangeBasis * _ModelViewMatrix;
setUniform4x4f(program, mvpIndex, mvp);
}

Loading…
Cancel
Save