Orthographic projection now working

the main fix is in tr_glsl.c, the other changes are peripheral and probably contribute nothing
This commit is contained in:
Simon 2022-03-29 22:41:36 +01:00
parent e1a16cbeb2
commit e8da743153
21 changed files with 194 additions and 197 deletions

View file

@ -60,12 +60,6 @@ void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
float screenXScale = cgs.screenXScale / 2.75f;
float screenYScale = cgs.screenYScale / 2.25f;
const auto depth = (int)trap_Cvar_VariableValue( "vr_hudDepth" );
int xoffset = 120 - (depth * 20);
if (cg.stereoView == STEREO_RIGHT) {
xoffset *= -1;
}
*x *= screenXScale;
*y *= screenYScale;
if (hudflags & HUD_FLAGS_DRAWMODEL)
@ -81,7 +75,7 @@ void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
*h *= screenYScale;
}
*x += (cg.refdef.width - (640 * screenXScale)) / 2.0f + xoffset;
*x += (cg.refdef.width - (640 * screenXScale)) / 2.0f;
*y += (cg.refdef.height - (480 * screenYScale)) / 2.0f - trap_Cvar_VariableValue( "vr_hudYOffset" );
}
}

View file

@ -12,16 +12,17 @@ uniform float u_Time;
uniform vec4 u_Color;
uniform mat4 u_ModelMatrix;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
{
uniform mat4 u_ProjectionMatrix;
};
varying vec2 var_Tex1;
varying vec4 var_Color;

View file

@ -1,16 +1,17 @@
attribute vec3 attr_Position;
attribute vec4 attr_TexCoord0;
uniform mat4 u_ModelMatrix;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
uniform mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
varying vec2 var_TexCoords;

View file

@ -15,6 +15,8 @@ uniform vec4 u_FogDistance;
uniform vec4 u_FogDepth;
uniform float u_FogEyeT;
uniform mat4 u_ModelMatrix;
#if defined(USE_DEFORM_VERTEXES)
uniform int u_DeformGen;
uniform float u_DeformParams[5];
@ -22,17 +24,6 @@ uniform float u_DeformParams[5];
uniform float u_Time;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
#if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp;
#elif defined(USE_BONE_ANIMATION)
@ -41,6 +32,16 @@ uniform mat4 u_BoneMatrix[MAX_GLSL_BONES];
uniform vec4 u_Color;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying float var_Scale;
#if defined(USE_DEFORM_VERTEXES)

View file

@ -36,6 +36,8 @@ uniform float u_FogEyeT;
uniform vec4 u_FogColorMask;
#endif
uniform mat4 u_ModelMatrix;
#if defined(USE_DEFORM_VERTEXES)
uniform int u_DeformGen;
uniform float u_DeformParams[5];
@ -43,17 +45,6 @@ uniform float u_Time;
#endif
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
uniform vec4 u_BaseColor;
uniform vec4 u_VertColor;
@ -72,6 +63,16 @@ uniform float u_VertexLerp;
uniform mat4 u_BoneMatrix[MAX_GLSL_BONES];
#endif
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying vec2 var_DiffuseTex;
varying vec4 var_Color;

View file

@ -42,16 +42,7 @@ uniform vec4 u_DiffuseTexOffTurb;
#endif
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
uniform mat4 u_ModelMatrix;
uniform vec4 u_BaseColor;
uniform vec4 u_VertColor;
@ -75,6 +66,16 @@ uniform vec4 u_PrimaryLightOrigin;
uniform float u_PrimaryLightRadius;
#endif
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying vec4 var_TexCoords;
varying vec4 var_Color;

View file

@ -1,16 +1,16 @@
attribute vec3 attr_Position;
attribute vec3 attr_Normal;
// Uniforms
uniform mat4 u_ModelMatrix;
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
uniform mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
varying vec3 var_Position;
varying vec3 var_Normal;

View file

@ -10,6 +10,9 @@ attribute vec4 attr_BoneIndexes;
attribute vec4 attr_BoneWeights;
#endif
// Uniforms
//#if defined(USE_DEFORM_VERTEXES)
uniform int u_DeformGen;
uniform float u_DeformParams[5];
@ -17,16 +20,7 @@ uniform float u_DeformParams[5];
uniform float u_Time;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
uniform mat4 u_ModelMatrix;
#if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp;
@ -34,6 +28,15 @@ uniform float u_VertexLerp;
uniform mat4 u_BoneMatrix[MAX_GLSL_BONES];
#endif
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying vec3 var_Position;
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)

View file

@ -1,18 +1,18 @@
attribute vec3 attr_Position;
attribute vec4 attr_TexCoord0;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
uniform mat4 u_ModelMatrix;
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying vec2 var_Tex1;

View file

@ -1,20 +1,21 @@
attribute vec3 attr_Position;
attribute vec4 attr_TexCoord0;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
uniform mat4 u_ModelMatrix;
uniform vec3 u_ToneMinAvgMaxLinear;
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying vec2 var_TexCoords;
varying float var_InvWhite;

View file

@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "tr_local.h"
#include "tr_dsa.h"
#include "../vr/vr_base.h"
extern const char *fallbackShader_bokeh_vp;
@ -54,6 +55,8 @@ extern const char *fallbackShader_texturecolor_fp;
extern const char *fallbackShader_tonemap_vp;
extern const char *fallbackShader_tonemap_fp;
extern cvar_t *vr_hudDepth;
typedef struct uniformInfo_s
{
char *name;
@ -193,9 +196,16 @@ static void GLSL_ViewMatricesUniformBuffer(const float value[32]) {
if (i == ORTHO_PROJECTION)
{
//don't want depth when in screen view
const auto depth = VR_useScreenLayer() ? 0 : (5-vr_hudDepth->integer) * 20;
//For now just set identity matrices
Mat4Identity(viewMatrices);
Mat4Identity(viewMatrices + 16);
vec3_t translate;
VectorSet(translate, depth, 0, 0);
Mat4Translation( translate, viewMatrices );
VectorSet(translate, -depth, 0, 0);
Mat4Translation( translate, viewMatrices + 16 );
}
else
{
@ -327,9 +337,9 @@ static void GLSL_GetShaderHeader( GLenum shaderType, const GLchar *extra, char *
}
// HACK: use in main menu medium float precision (to prevent issue with missing models textures)
if (Cvar_Get("r_uiFullScreen", "1", 0)->integer)
Q_strcat(dest, size, "precision mediump float;\n");
else
// if (Cvar_Get("r_uiFullScreen", "1", 0)->integer)
// Q_strcat(dest, size, "precision mediump float;\n");
// else
Q_strcat(dest, size, "precision highp float;\n");
if(shaderType == GL_VERTEX_SHADER)
@ -1652,40 +1662,16 @@ void GLSL_PrepareUniformBuffers(void)
height = glConfig.vidHeight;
}
static qboolean first = qtrue;
static float defaultProjection[16];
if (first)
{
first = qfalse;
memset(defaultProjection, 0, 16 * sizeof(float));
}
float orthoProjectionMatrix[16];
Mat4Ortho(0, width, height, 0, 0, 1, orthoProjectionMatrix);
static int vidWidth = 1;
static int vidHeight = 1;
if (vidWidth != width || vidHeight != height)
{
//ortho projection matrix
GLSL_ProjectionMatricesUniformBuffer(projectionMatricesBuffer[ORTHO_PROJECTION],
orthoProjectionMatrix);
float orthoProjectionMatrix[16];
Mat4Ortho(0, vidWidth, vidHeight, 0, 0, 1, orthoProjectionMatrix);
//ortho projection matrix
GLSL_ProjectionMatricesUniformBuffer(projectionMatricesBuffer[ORTHO_PROJECTION],
orthoProjectionMatrix);
vidWidth = width;
vidHeight = height;
}
//We only need to do the following if the default projection changes
if (memcmp(defaultProjection, tr.vrParms.projection, 16 * sizeof(float)) != 0)
{
//Take a copy of the default projection
memcpy(defaultProjection, tr.vrParms.projection, 16 * sizeof(float));
//unadjusted projection matrix
GLSL_ProjectionMatricesUniformBuffer(projectionMatricesBuffer[NORMAL_PROJECTION],
tr.vrParms.projection);
}
//VR projection matrix
GLSL_ProjectionMatricesUniformBuffer(projectionMatricesBuffer[NORMAL_PROJECTION],
tr.vrParms.projection);
//Set up the buffers that won't change this frame
GLSL_ViewMatricesUniformBuffer(tr.viewParms.world.eyeViewMatrix);
@ -1704,7 +1690,6 @@ void GLSL_BindProgram(shaderProgram_t * program)
if (GL_UseProgram(programObject))
backEnd.pc.c_glslShaderBinds++;
}
static GLuint GLSL_CalculateProjection() {

View file

@ -12,16 +12,17 @@ uniform float u_Time;
uniform vec4 u_Color;
uniform mat4 u_ModelMatrix;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
{
uniform mat4 u_ProjectionMatrix;
};
varying vec2 var_Tex1;
varying vec4 var_Color;

View file

@ -1,16 +1,17 @@
attribute vec3 attr_Position;
attribute vec4 attr_TexCoord0;
uniform mat4 u_ModelMatrix;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
uniform mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
varying vec2 var_TexCoords;

View file

@ -15,6 +15,8 @@ uniform vec4 u_FogDistance;
uniform vec4 u_FogDepth;
uniform float u_FogEyeT;
uniform mat4 u_ModelMatrix;
#if defined(USE_DEFORM_VERTEXES)
uniform int u_DeformGen;
uniform float u_DeformParams[5];
@ -22,17 +24,6 @@ uniform float u_DeformParams[5];
uniform float u_Time;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
#if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp;
#elif defined(USE_BONE_ANIMATION)
@ -41,6 +32,16 @@ uniform mat4 u_BoneMatrix[MAX_GLSL_BONES];
uniform vec4 u_Color;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying float var_Scale;
#if defined(USE_DEFORM_VERTEXES)

View file

@ -36,6 +36,8 @@ uniform float u_FogEyeT;
uniform vec4 u_FogColorMask;
#endif
uniform mat4 u_ModelMatrix;
#if defined(USE_DEFORM_VERTEXES)
uniform int u_DeformGen;
uniform float u_DeformParams[5];
@ -43,17 +45,6 @@ uniform float u_Time;
#endif
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
uniform vec4 u_BaseColor;
uniform vec4 u_VertColor;
@ -72,6 +63,16 @@ uniform float u_VertexLerp;
uniform mat4 u_BoneMatrix[MAX_GLSL_BONES];
#endif
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying vec2 var_DiffuseTex;
varying vec4 var_Color;

View file

@ -42,16 +42,7 @@ uniform vec4 u_DiffuseTexOffTurb;
#endif
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
uniform mat4 u_ModelMatrix;
uniform vec4 u_BaseColor;
uniform vec4 u_VertColor;
@ -75,6 +66,16 @@ uniform vec4 u_PrimaryLightOrigin;
uniform float u_PrimaryLightRadius;
#endif
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying vec4 var_TexCoords;
varying vec4 var_Color;

View file

@ -1,16 +1,16 @@
attribute vec3 attr_Position;
attribute vec3 attr_Normal;
// Uniforms
uniform mat4 u_ModelMatrix;
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
uniform mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
varying vec3 var_Position;
varying vec3 var_Normal;

View file

@ -10,6 +10,9 @@ attribute vec4 attr_BoneIndexes;
attribute vec4 attr_BoneWeights;
#endif
// Uniforms
//#if defined(USE_DEFORM_VERTEXES)
uniform int u_DeformGen;
uniform float u_DeformParams[5];
@ -17,16 +20,7 @@ uniform float u_DeformParams[5];
uniform float u_Time;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
uniform mat4 u_ModelMatrix;
#if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp;
@ -34,6 +28,15 @@ uniform float u_VertexLerp;
uniform mat4 u_BoneMatrix[MAX_GLSL_BONES];
#endif
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying vec3 var_Position;
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)

View file

@ -1,18 +1,18 @@
attribute vec3 attr_Position;
attribute vec4 attr_TexCoord0;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
uniform mat4 u_ModelMatrix;
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying vec2 var_Tex1;

View file

@ -1,20 +1,21 @@
attribute vec3 attr_Position;
attribute vec4 attr_TexCoord0;
// Uniforms
layout(shared) uniform ViewMatrices
{
uniform highp mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform highp mat4 u_ProjectionMatrix;
};
uniform highp mat4 u_ModelMatrix;
uniform mat4 u_ModelMatrix;
uniform vec3 u_ToneMinAvgMaxLinear;
layout(shared) uniform ViewMatrices
{
uniform mat4 u_ViewMatrices[NUM_VIEWS];
};
layout(shared) uniform ProjectionMatrix
{
uniform mat4 u_ProjectionMatrix;
};
varying vec2 var_TexCoords;
varying float var_InvWhite;