SpaceWarp previous model matrix provided

This commit is contained in:
Lubos 2022-05-20 11:58:01 +02:00
parent 390ad3f3f2
commit 88033ce5b6
10 changed files with 45 additions and 9 deletions

View file

@ -5,6 +5,7 @@ attribute vec4 attr_Color;
attribute vec4 attr_TexCoord0;
uniform mat4 u_ModelMatrix;
uniform mat4 u_PrevModelMatrix;
uniform vec4 u_BaseColor;
@ -32,7 +33,7 @@ void main()
vec3 normal = attr_Normal;
clipPos = u_ViewProjectionMatrices[gl_ViewID_OVR] * (u_ModelMatrix * vec4(position, 1.0));
prevClipPos = u_PrevViewProjectionMatrices[gl_ViewID_OVR] * (u_ModelMatrix * vec4(position, 1.0));
prevClipPos = u_PrevViewProjectionMatrices[gl_ViewID_OVR] * (u_PrevModelMatrix * vec4(position, 1.0));
var_DiffuseTex = attr_TexCoord0.st;
var_Color = u_VertColor * attr_Color + u_BaseColor;

View file

@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
backEndData_t *backEndData;
backEndState_t backEnd;
float prevModelMatrix[16];
static float s_flipMatrix[16] = {
// convert from our coordinate system (looking down X)
@ -277,6 +278,11 @@ void GL_SetModelMatrix(mat4_t matrix)
Mat4Copy(matrix, glState.modelMatrix);
}
void GL_SetPrevModelMatrix(mat4_t matrix)
{
Mat4Copy(matrix, glState.prevModelMatrix);
}
/*
================
@ -361,12 +367,11 @@ void RB_BeginDrawingView (void) {
// ensures that depth writes are enabled for the depth clear
GL_State( GLS_DEFAULT );
// clear relevant buffers
//TODO:resolve GL_ERROR
/*if( VR_RenderMotionVector() )
if( VR_RenderMotionVector() )
{
clearBits = 0;
}
else*/
else
{
clearBits = GL_DEPTH_BUFFER_BIT;
}
@ -520,6 +525,11 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
R_TransformDlights( backEnd.refdef.num_dlights, backEnd.refdef.dlights, &backEnd.or );
}
if (!VR_RenderMotionVector()) {
memcpy( &backEnd.currentEntity->prevModelMatrix[0], &backEnd.or.modelMatrix[0], sizeof(float) * 16);
} else {
GL_SetPrevModelMatrix( backEnd.currentEntity->prevModelMatrix );
}
GL_SetModelMatrix( backEnd.or.modelMatrix );
GL_SetProjectionMatrix( backEnd.viewParms.projectionMatrix );
@ -570,7 +580,11 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
FBO_Bind(fbo);
// go back to the world model matrix
if (!VR_RenderMotionVector()) {
memcpy( &prevModelMatrix[0], &backEnd.viewParms.world.modelMatrix[0], sizeof(float) * 16);
} else {
GL_SetPrevModelMatrix( prevModelMatrix );
}
GL_SetModelMatrix( backEnd.viewParms.world.modelMatrix );
#ifdef __ANDROID__
@ -717,6 +731,7 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
GLSL_BindProgram(&tr.textureColorShader);
GLSL_SetUniformMat4(&tr.textureColorShader, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(&tr.textureColorShader, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(&tr.textureColorShader);
GLSL_SetUniformVec4(&tr.textureColorShader, UNIFORM_COLOR, colorWhite);

View file

@ -593,6 +593,7 @@ void FBO_BlitFromTexture(struct image_s *src, vec4_t inSrcTexCorners, vec2_t inS
GLSL_BindProgram(shaderProgram);
GLSL_SetUniformMat4(shaderProgram, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(shaderProgram, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(shaderProgram);
GLSL_SetUniformVec4(shaderProgram, UNIFORM_COLOR, color);
GLSL_SetUniformVec2(shaderProgram, UNIFORM_INVTEXRES, invTexRes);

View file

@ -146,6 +146,7 @@ static uniformInfo_t uniformsInfo[] =
{ "u_FogColorMask", GLSL_VEC4 },
{ "u_ModelMatrix", GLSL_MAT16 },
{ "u_PrevModelMatrix", GLSL_MAT16 },
{ "u_Time", GLSL_FLOAT },
{ "u_VertexLerp" , GLSL_FLOAT },

View file

@ -105,6 +105,8 @@ typedef struct {
vec3_t ambientLight; // color normalized to 0-255
int ambientLightInt; // 32 bit rgba packed
vec3_t directedLight;
float prevModelMatrix[16];
} trRefEntity_t;
@ -677,6 +679,7 @@ typedef enum
UNIFORM_FOGCOLORMASK,
UNIFORM_MODELMATRIX,
UNIFORM_PREVMODELMATRIX,
UNIFORM_TIME,
UNIFORM_VERTEXLERP,
@ -1396,6 +1399,7 @@ typedef struct {
vao_t *currentVao;
mat4_t modelMatrix;
mat4_t prevModelMatrix;
mat4_t projection;
qboolean isDrawingHUD;
} glstate_t;
@ -1937,6 +1941,7 @@ void GL_CheckErrs( char *file, int line );
#define GL_CheckErrors(...) GL_CheckErrs(__FILE__, __LINE__)
void GL_State( unsigned long stateVector );
void GL_SetProjectionMatrix(mat4_t matrix);
void GL_SetPrevModelMatrix(mat4_t matrix);
void GL_SetModelMatrix(mat4_t matrix);
void GL_Cull( int cullType );

View file

@ -115,6 +115,7 @@ static void DrawTris (shaderCommands_t *input) {
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(sp);
VectorSet4(color, 1, 1, 1, 1);
GLSL_SetUniformVec4(sp, UNIFORM_COLOR, color);
@ -354,6 +355,7 @@ static void ProjectDlightTexture( void ) {
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation);
@ -694,6 +696,7 @@ static void ForwardDlight( void ) {
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformVec3(sp, UNIFORM_VIEWORIGIN, backEnd.viewParms.or.origin);
GLSL_SetUniformVec3(sp, UNIFORM_LOCALVIEWORIGIN, backEnd.or.viewOrigin);
@ -757,6 +760,7 @@ static void ForwardDlight( void ) {
GLSL_SetUniformInt(sp, UNIFORM_ALPHATEST, 0);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(sp);
if (pStage->bundle[TB_DIFFUSEMAP].image[0])
@ -849,6 +853,7 @@ static void ProjectPshadowVBOGLSL( void ) {
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(sp);
VectorCopy(origin, vector);
@ -926,6 +931,7 @@ static void RB_FogPass( void ) {
fog = tr.world->fogs + tess.fogNum;
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation);
@ -1101,6 +1107,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformVec3(sp, UNIFORM_VIEWORIGIN, backEnd.viewParms.or.origin);
GLSL_SetUniformVec3(sp, UNIFORM_LOCALVIEWORIGIN, backEnd.or.viewOrigin);
@ -1218,6 +1225,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
}
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformVec4(sp, UNIFORM_NORMALSCALE, pStage->normalScale);
@ -1422,6 +1430,7 @@ static void RB_RenderShadowmap( shaderCommands_t *input )
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation);

View file

@ -426,6 +426,7 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(sp);
color[0] =

View file

@ -228,6 +228,7 @@ void RB_InstantQuad(vec4_t quadVerts[4])
GLSL_BindProgram(&tr.textureColorShader);
GLSL_SetUniformMat4(&tr.textureColorShader, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(&tr.textureColorShader, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(&tr.textureColorShader);
GLSL_SetUniformVec4(&tr.textureColorShader, UNIFORM_COLOR, colorWhite);
@ -541,6 +542,7 @@ static void RB_SurfaceBeam( void )
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_PREVMODELMATRIX, glState.prevModelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformVec4(sp, UNIFORM_COLOR, colorRed);

View file

@ -505,9 +505,9 @@ void VR_DrawFrame( engine_t* engine ) {
if (vr_spacewarp->integer) {
renderMotionVector = qtrue;
VR_RenderScene( engine, fov, qfalse );
renderMotionVector = qfalse;
VR_RenderScene( engine, fov, qtrue );
renderMotionVector = qfalse;
VR_RenderScene( engine, fov, qfalse );
} else {
VR_RenderScene( engine, fov, qfalse );
}
@ -548,7 +548,7 @@ void VR_DrawFrame( engine_t* engine ) {
proj_spacewarp_views[eye].depthSubImage.imageRect.extent.width = frameBuffer->MotionVectorDepthSwapChain.Width;
proj_spacewarp_views[eye].depthSubImage.imageRect.extent.height = frameBuffer->MotionVectorDepthSwapChain.Height;
proj_spacewarp_views[eye].depthSubImage.imageArrayIndex = eye;
proj_spacewarp_views[eye].appSpaceDeltaPose = prevInvViewTransform[eye]; //TODO:XrPosef_Multiply(prevInvViewTransform[eye], viewTransform[eye]);
proj_spacewarp_views[eye].appSpaceDeltaPose = XrPosef_Multiply(prevInvViewTransform[eye], viewTransform[eye]);
proj_spacewarp_views[eye].minDepth = 0.0f;
proj_spacewarp_views[eye].maxDepth = 1.0f;

View file

@ -5,6 +5,7 @@ attribute vec4 attr_Color;
attribute vec4 attr_TexCoord0;
uniform mat4 u_ModelMatrix;
uniform mat4 u_PrevModelMatrix;
uniform vec4 u_BaseColor;
@ -32,7 +33,7 @@ void main()
vec3 normal = attr_Normal;
clipPos = u_ViewProjectionMatrices[gl_ViewID_OVR] * (u_ModelMatrix * vec4(position, 1.0));
prevClipPos = u_PrevViewProjectionMatrices[gl_ViewID_OVR] * (u_ModelMatrix * vec4(position, 1.0));
prevClipPos = u_PrevViewProjectionMatrices[gl_ViewID_OVR] * (u_PrevModelMatrix * vec4(position, 1.0));
var_DiffuseTex = attr_TexCoord0.st;
var_Color = u_VertColor * attr_Color + u_BaseColor;