Small progress

world is now rendering correctly, but..
- All items in world are rendering in the wrong place
- no 2D still
This commit is contained in:
Simon 2022-03-27 23:19:16 +01:00
parent 71708ee91e
commit e2a5472667
14 changed files with 57 additions and 97 deletions

View file

@ -56,10 +56,6 @@ uniform highp mat4 u_ModelMatrix;
uniform vec4 u_BaseColor;
uniform vec4 u_VertColor;
#if defined(USE_MODELTRANSFORMMATRIX)
uniform mat4 u_ModelTransformMatrix;
#endif
#if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp;
@ -202,11 +198,11 @@ void main()
gl_Position = u_ProjectionMatrix * (u_ViewMatrices[gl_ViewID_OVR] * (u_ModelMatrix * vec4(position, 1.0)));
#if defined(USE_MODELTRANSFORMMATRIX)
position = (u_ModelTransformMatrix * vec4(position, 1.0)).xyz;
normal = (u_ModelTransformMatrix * vec4(normal, 0.0)).xyz;
#if defined(USE_MODELMATRIX)
position = (u_ModelMatrix * vec4(position, 1.0)).xyz;
normal = (u_ModelMatrix * vec4(normal, 0.0)).xyz;
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
tangent = (u_ModelTransformMatrix * vec4(tangent, 0.0)).xyz;
tangent = (u_ModelMatrix * vec4(tangent, 0.0)).xyz;
#endif
#endif
@ -218,8 +214,8 @@ void main()
vec3 L = u_LightOrigin.xyz - (position * u_LightOrigin.w);
#elif defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
vec3 L = attr_LightDirection;
#if defined(USE_MODELTRANSFORMMATRIX)
L = (u_ModelTransformMatrix * vec4(L, 0.0)).xyz;
#if defined(USE_MODELMATRIX)
L = (u_ModelMatrix * vec4(L, 0.0)).xyz;
#endif
#endif

View file

@ -272,9 +272,9 @@ void GL_SetProjectionMatrix(mat4_t matrix)
Mat4Copy(matrix, glState.projection);
}
void GL_SetModelviewMatrix(mat4_t matrix)
void GL_SetModelMatrix(mat4_t matrix)
{
Mat4Copy(matrix, glState.modelview);
Mat4Copy(matrix, glState.modelMatrix);
}
@ -410,8 +410,7 @@ void RB_BeginDrawingView (void) {
plane2[3] = DotProduct (plane, backEnd.viewParms.or.origin) - plane[3];
#endif
//TODO: This probably won't work at the moment!!
GL_SetModelviewMatrix( s_flipMatrix );
GL_SetModelMatrix( s_flipMatrix );
}
}
@ -530,7 +529,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
R_TransformDlights( backEnd.refdef.num_dlights, backEnd.refdef.dlights, &backEnd.or );
}
GL_SetModelviewMatrix( backEnd.or.eyeViewMatrix[2] );
GL_SetModelMatrix( backEnd.or.modelMatrix );
//
// change depthrange. Also change projection matrix so first person weapon does not look like coming
@ -600,9 +599,9 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
if (glRefConfig.framebufferObject)
FBO_Bind(fbo);
// go back to the world modelview matrix
// go back to the world model matrix
GL_SetModelviewMatrix( backEnd.viewParms.world.eyeViewMatrix[2] );
GL_SetModelMatrix( backEnd.viewParms.world.modelMatrix );
#ifdef __ANDROID__
glDepthRangef(0, 1);
@ -654,7 +653,7 @@ void RB_SetGL2D (void) {
Mat4Ortho(0, width, height, 0, 0, 1, matrix);
GL_SetProjectionMatrix(matrix);
Mat4Identity(matrix);
GL_SetModelviewMatrix(matrix);
GL_SetModelMatrix(matrix);
GL_State( GLS_DEPTHTEST_DISABLE |
GLS_SRCBLEND_SRC_ALPHA |
@ -737,8 +736,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_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(&tr.textureColorShader, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(&tr.textureColorShader, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(&tr.textureColorShader);
GLSL_SetUniformVec4(&tr.textureColorShader, UNIFORM_COLOR, colorWhite);

View file

@ -577,8 +577,7 @@ void FBO_BlitFromTexture(struct image_s *src, vec4_t inSrcTexCorners, vec2_t inS
GLSL_BindProgram(shaderProgram);
GLSL_SetUniformMat4(shaderProgram, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(shaderProgram, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(shaderProgram, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(shaderProgram);
GLSL_SetUniformVec4(shaderProgram, UNIFORM_COLOR, color);
GLSL_SetUniformVec2(shaderProgram, UNIFORM_INVTEXRES, invTexRes);

View file

@ -472,7 +472,7 @@ void RB_RenderFlares (void) {
flare_t *f;
flare_t **prev;
qboolean draw;
mat4_t oldmodelview, oldprojection, matrix;
mat4_t oldmodelmatrix, oldprojection, matrix;
if ( !r_flares->integer ) {
return;
@ -527,9 +527,9 @@ void RB_RenderFlares (void) {
}
Mat4Copy(glState.projection, oldprojection);
Mat4Copy(glState.modelview, oldmodelview);
Mat4Copy(glState.modelMatrix, oldmodelmatrix);
Mat4Identity(matrix);
GL_SetModelviewMatrix(matrix);
GL_SetModelMatrix(matrix);
Mat4Ortho( backEnd.viewParms.viewportX, backEnd.viewParms.viewportX + backEnd.viewParms.viewportWidth,
backEnd.viewParms.viewportY, backEnd.viewParms.viewportY + backEnd.viewParms.viewportHeight,
-99999, 99999, matrix );
@ -544,7 +544,7 @@ void RB_RenderFlares (void) {
}
GL_SetProjectionMatrix(oldprojection);
GL_SetModelviewMatrix(oldmodelview);
GL_SetModelMatrix(oldmodelmatrix);
}

View file

@ -130,7 +130,6 @@ static uniformInfo_t uniformsInfo[] =
{ "u_FogColorMask", GLSL_VEC4 },
{ "u_ModelMatrix", GLSL_MAT16 },
{ "u_ModelTransformMatrix", GLSL_MAT16 },
{ "u_Time", GLSL_FLOAT },
{ "u_VertexLerp" , GLSL_FLOAT },
@ -1314,7 +1313,7 @@ void GLSL_InitGPUShaders(void)
if (i & LIGHTDEF_ENTITY_VERTEX_ANIMATION)
{
Q_strcat(extradefines, 1024, "#define USE_VERTEX_ANIMATION\n#define USE_MODELTRANSFORMMATRIX\n");
Q_strcat(extradefines, 1024, "#define USE_VERTEX_ANIMATION\n#define USE_MODELMATRIX\n");
attribs |= ATTR_POSITION2 | ATTR_NORMAL2;
if (r_normalMapping->integer)
@ -1324,7 +1323,7 @@ void GLSL_InitGPUShaders(void)
}
else if (i & LIGHTDEF_ENTITY_BONE_ANIMATION)
{
Q_strcat(extradefines, 1024, "#define USE_MODELTRANSFORMMATRIX\n");
Q_strcat(extradefines, 1024, "#define USE_MODELMATRIX\n");
Q_strcat(extradefines, 1024, va("#define USE_BONE_ANIMATION\n#define MAX_GLSL_BONES %d\n", glRefConfig.glslMaxAnimatedBones));
attribs |= ATTR_BONE_INDEXES | ATTR_BONE_WEIGHTS;
}
@ -1677,7 +1676,7 @@ void GLSL_PrepareUniformBuffers(void)
}
//Set up the buffers that won't change this frame
GLSL_ViewMatricesUniformBuffer(tr.viewParms.world.viewMatrix);
GLSL_ViewMatricesUniformBuffer(tr.viewParms.world.eyeViewMatrix);
}
void GLSL_BindProgram(shaderProgram_t * program)

View file

@ -107,11 +107,8 @@ typedef struct {
vec3_t origin; // in world coordinates
vec3_t axis[3]; // orientation in world
vec3_t viewOrigin; // viewParms->or.origin in local coordinates
float transformMatrix[16];
union {
float modelMatrix[16];
float eyeViewMatrix[3][16];
float viewMatrix[48];
};
} orientationr_t;
// Ensure this is >= the ATTR_INDEX_COUNT enum below
@ -674,7 +671,6 @@ typedef enum
UNIFORM_FOGCOLORMASK,
UNIFORM_MODELMATRIX,
UNIFORM_MODELTRANSFORMMATRIX,
UNIFORM_TIME,
UNIFORM_VERTEXLERP,
@ -843,6 +839,7 @@ typedef struct {
vec3_t visBounds[2];
float zFar;
float zNear;
stereoFrame_t stereoFrame;
} viewParms_t;
typedef struct {
@ -1390,7 +1387,7 @@ typedef struct {
FBO_t *currentFBO;
vao_t *currentVao;
mat4_t modelview;
mat4_t modelMatrix;
mat4_t projection;
} glstate_t;
@ -1922,7 +1919,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_SetModelviewMatrix(mat4_t matrix);
void GL_SetModelMatrix(mat4_t matrix);
void GL_Cull( int cullType );
#define GLS_SRCBLEND_ZERO 0x00000001

View file

@ -536,7 +536,7 @@ void R_RotateForEntity( const trRefEntity_t *ent, const viewParms_t *viewParms,
glMatrix[11] = 0;
glMatrix[15] = 1;
Mat4Copy(glMatrix, or->transformMatrix);
Mat4Copy(glMatrix, or->modelMatrix);
for (int eye = 0; eye <= 2; ++eye) {
myGlMultMatrix( glMatrix, viewParms->world.eyeViewMatrix[eye], or->eyeViewMatrix[eye] );
}
@ -616,6 +616,7 @@ void R_RotateForViewer (void)
// convert from our coordinate system (looking down X)
// to OpenGL's coordinate system (looking down -Z)
Mat4Copy(viewerMatrix, tr.or.modelMatrix);
myGlMultMatrix(viewerMatrix, s_flipMatrix, tr.or.eyeViewMatrix[eye]);
}

View file

@ -114,8 +114,7 @@ static void DrawTris (shaderCommands_t *input) {
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(sp);
VectorSet4(color, 1, 1, 1, 1);
GLSL_SetUniformVec4(sp, UNIFORM_COLOR, color);
@ -354,8 +353,7 @@ static void ProjectDlightTexture( void ) {
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation);
@ -695,8 +693,7 @@ static void ForwardDlight( void ) {
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformVec3(sp, UNIFORM_VIEWORIGIN, backEnd.viewParms.or.origin);
GLSL_SetUniformVec3(sp, UNIFORM_LOCALVIEWORIGIN, backEnd.or.viewOrigin);
@ -759,8 +756,7 @@ static void ForwardDlight( void ) {
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL );
GLSL_SetUniformInt(sp, UNIFORM_ALPHATEST, 0);
GLSL_SetUniformMat4(sp, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(sp);
if (pStage->bundle[TB_DIFFUSEMAP].image[0])
@ -852,8 +848,7 @@ static void ProjectPshadowVBOGLSL( void ) {
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(sp);
VectorCopy(origin, vector);
@ -930,8 +925,7 @@ static void RB_FogPass( void ) {
fog = tr.world->fogs + tess.fogNum;
GLSL_SetUniformMat4(sp, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation);
@ -1106,8 +1100,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformVec3(sp, UNIFORM_VIEWORIGIN, backEnd.viewParms.or.origin);
GLSL_SetUniformVec3(sp, UNIFORM_LOCALVIEWORIGIN, backEnd.or.viewOrigin);
@ -1224,8 +1217,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
}
}
GLSL_SetUniformMat4(sp, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformVec4(sp, UNIFORM_NORMALSCALE, pStage->normalScale);
@ -1429,8 +1421,7 @@ static void RB_RenderShadowmap( shaderCommands_t *input )
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformFloat(sp, UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation);

View file

@ -417,30 +417,15 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
// FIXME: A lot of this can probably be removed for speed, and refactored into a more convenient function
RB_UpdateTessVao(ATTR_POSITION | ATTR_TEXCOORD);
/*
{
shaderProgram_t *sp = &tr.textureColorShader;
GLSL_VertexAttribsState(ATTR_POSITION | ATTR_TEXCOORD);
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection);
color[0] =
color[1] =
color[2] = tr.identityLight;
color[3] = 1.0f;
GLSL_SetUniformVec4(sp, UNIFORM_COLOR, color);
}
*/
{
shaderProgram_t *sp = &tr.lightallShader[0];
vec4_t vector;
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(sp);
color[0] =
@ -802,11 +787,11 @@ void RB_DrawSun( float scale, shader_t *shader ) {
//qglTranslatef (backEnd.viewParms.or.origin[0], backEnd.viewParms.or.origin[1], backEnd.viewParms.or.origin[2]);
{
// FIXME: this could be a lot cleaner
mat4_t translation, modelview;
mat4_t translation, modelmatrix;
Mat4Translation( backEnd.viewParms.or.origin, translation );
Mat4Multiply( backEnd.viewParms.world.eyeViewMatrix[2], translation, modelview );
GL_SetModelviewMatrix( modelview );
Mat4Multiply( backEnd.viewParms.world.modelMatrix, translation, modelmatrix );
GL_SetModelMatrix( modelmatrix );
}
dist = backEnd.viewParms.zFar / 1.75; // div sqrt(3)
@ -883,16 +868,16 @@ void RB_StageIteratorSky( void ) {
// FIXME: this could be a lot cleaner
mat4_t trans, product;
Mat4Copy( glState.modelview, oldmodelview );
Mat4Copy( glState.modelMatrix, oldmodelview );
Mat4Translation( backEnd.viewParms.or.origin, trans );
Mat4Multiply( glState.modelview, trans, product );
GL_SetModelviewMatrix( product );
Mat4Multiply( glState.modelMatrix, trans, product );
GL_SetModelMatrix( product );
}
DrawSkyBox( tess.shader );
GL_SetModelviewMatrix( oldmodelview );
GL_SetModelMatrix( oldmodelview );
}
// generate the vertexes for all the clouds, which will be drawn

View file

@ -227,8 +227,7 @@ void RB_InstantQuad(vec4_t quadVerts[4])
GLSL_BindProgram(&tr.textureColorShader);
GLSL_SetUniformMat4(&tr.textureColorShader, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(&tr.textureColorShader, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(&tr.textureColorShader, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(&tr.textureColorShader);
GLSL_SetUniformVec4(&tr.textureColorShader, UNIFORM_COLOR, colorWhite);
@ -541,8 +540,7 @@ static void RB_SurfaceBeam( void )
GLSL_BindProgram(sp);
GLSL_SetUniformMat4(sp, UNIFORM_MODELTRANSFORMMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelview);
GLSL_SetUniformMat4(sp, UNIFORM_MODELMATRIX, glState.modelMatrix);
GLSL_BindBuffers(sp);
GLSL_SetUniformVec4(sp, UNIFORM_COLOR, colorRed);

View file

@ -136,7 +136,7 @@ public class MainActivity extends SDLActivity // implements KeyEvent.Callback
Log.d(TAG, "setting env");
try {
//commandLineParams += " +map q3dm6";
commandLineParams += " +map q3dm7";
setenv("commandline", commandLineParams, true);
} catch (Exception e) {
}

View file

@ -56,10 +56,6 @@ uniform highp mat4 u_ModelMatrix;
uniform vec4 u_BaseColor;
uniform vec4 u_VertColor;
#if defined(USE_MODELTRANSFORMMATRIX)
uniform mat4 u_ModelTransformMatrix;
#endif
#if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp;
@ -202,11 +198,11 @@ void main()
gl_Position = u_ProjectionMatrix * (u_ViewMatrices[gl_ViewID_OVR] * (u_ModelMatrix * vec4(position, 1.0)));
#if defined(USE_MODELTRANSFORMMATRIX)
position = (u_ModelTransformMatrix * vec4(position, 1.0)).xyz;
normal = (u_ModelTransformMatrix * vec4(normal, 0.0)).xyz;
#if defined(USE_MODELMATRIX)
position = (u_ModelMatrix * vec4(position, 1.0)).xyz;
normal = (u_ModelMatrix * vec4(normal, 0.0)).xyz;
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
tangent = (u_ModelTransformMatrix * vec4(tangent, 0.0)).xyz;
tangent = (u_ModelMatrix * vec4(tangent, 0.0)).xyz;
#endif
#endif
@ -218,8 +214,8 @@ void main()
vec3 L = u_LightOrigin.xyz - (position * u_LightOrigin.w);
#elif defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
vec3 L = attr_LightDirection;
#if defined(USE_MODELTRANSFORMMATRIX)
L = (u_ModelTransformMatrix * vec4(L, 0.0)).xyz;
#if defined(USE_MODELMATRIX)
L = (u_ModelMatrix * vec4(L, 0.0)).xyz;
#endif
#endif