mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 20:58:07 +03:00
tr1/output/sprites: simplify projection matrix
This commit is contained in:
parent
e88764f280
commit
88870ef539
3 changed files with 2 additions and 71 deletions
|
@ -1,21 +1,14 @@
|
|||
#define NEW_ZBUFFER 0
|
||||
#define NEUTRAL_SHADE 0x1000
|
||||
|
||||
#ifdef VERTEX
|
||||
|
||||
uniform samplerBuffer uUVW; // texture u, v, layer
|
||||
uniform vec2 uViewportCenter;
|
||||
uniform vec2 uViewportSize;
|
||||
uniform mat4 uMatProjection;
|
||||
uniform mat4 uMatProjectionOG;
|
||||
uniform mat4 uMatModelView;
|
||||
uniform float uWibbleOffset;
|
||||
uniform vec2 uFog; // x = start, y = end
|
||||
|
||||
uniform float uPhdPersp;
|
||||
uniform float uPhdResZ;
|
||||
uniform float uPhdResZBuf;
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec2 inDisplacement;
|
||||
layout(location = 2) in int inTextureIdx;
|
||||
|
@ -25,7 +18,6 @@ out vec3 gUV; // x = u, y = v, z = layer
|
|||
out float gShade;
|
||||
|
||||
void main(void) {
|
||||
#if NEW_ZBUFFER
|
||||
vec4 centerEyeSpace = uMatModelView * vec4(inPosition, 1.0);
|
||||
centerEyeSpace.xy += inDisplacement;
|
||||
gl_Position = uMatProjection * centerEyeSpace;
|
||||
|
@ -34,26 +26,6 @@ void main(void) {
|
|||
gl_Position.xyz =
|
||||
waterWibble(gl_Position, uViewportSize, uWibbleOffset);
|
||||
}
|
||||
#else
|
||||
vec3 localPos = inPosition;
|
||||
vec3 worldPos = (uMatModelView * vec4(localPos, 1)).xyz;
|
||||
|
||||
if ((uMatProjection * vec4(worldPos, 1)).z <= 0) {
|
||||
// Terrible hack:
|
||||
// Push the vertex out of view (e.g. offscreen or behind clip).
|
||||
// Works for entire sprites, because worldPos is the position of the
|
||||
// sprite origin, the same for all vertices.
|
||||
gl_Position = vec4(2.0, 2.0, 1.0, 1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
vec3 screenCenterPos = vec3(
|
||||
uViewportCenter + worldPos.xy * uPhdPersp / worldPos.z,
|
||||
uPhdResZBuf - uPhdResZ / worldPos.z);
|
||||
vec3 screenCornerPos = screenCenterPos;
|
||||
screenCornerPos.xy += inDisplacement * uPhdPersp / worldPos.z;
|
||||
gl_Position = (uMatProjectionOG * vec4(screenCornerPos, 1));
|
||||
#endif
|
||||
|
||||
gUV = texelFetch(uUVW, int(inTextureIdx)).xyz;
|
||||
gShade = inShade;
|
||||
|
|
|
@ -1409,14 +1409,8 @@ void Output_GetProjectionMatrix(GLfloat output[][4])
|
|||
|
||||
output[2][0] = 0.0f;
|
||||
output[2][1] = 0.0f;
|
||||
// TODO(dash): these do not match the original game Z buffer mapping.
|
||||
// I couldn't figure out how to replicate the original MAP_DEPTH transform.
|
||||
// To combat this, the vertex shaders for now fence the simpler matrices
|
||||
// behind a `NEW_ZBUFFER` define, and fall back to doing the perspective
|
||||
// transform completely manually. This will be removable once we no longer
|
||||
// rely on PHD_VBUF / GFX_3D_Rendere for world rendering.
|
||||
output[2][2] = (far + near) / (far - near);
|
||||
output[2][3] = -(2.0f * far * near) / (far - near);
|
||||
output[2][2] = g_FltResZBuf;
|
||||
output[2][3] = -g_FltResZ / (float)(1 << W2V_SHIFT);
|
||||
|
||||
output[3][0] = 0.0f;
|
||||
output[3][1] = 0.0f;
|
||||
|
|
|
@ -13,13 +13,8 @@ typedef enum {
|
|||
M_UNIFORM_SMOOTHING_ENABLED,
|
||||
M_UNIFORM_BRIGHTNESS_MULTIPLIER,
|
||||
M_UNIFORM_GLOBAL_TINT,
|
||||
M_UNIFORM_VIEWPORT_CENTER,
|
||||
M_UNIFORM_VIEWPORT_SIZE,
|
||||
M_UNIFORM_PROJECTION_MATRIX,
|
||||
M_UNIFORM_PROJECTION_MATRIX_OG,
|
||||
M_UNIFORM_PHD_PERSP,
|
||||
M_UNIFORM_PHD_RES_Z,
|
||||
M_UNIFORM_PHD_RES_Z_BUF,
|
||||
M_UNIFORM_MODEL_MATRIX,
|
||||
M_UNIFORM_WIBBLE_OFFSET,
|
||||
M_UNIFORM_NUMBER_OF,
|
||||
|
@ -46,13 +41,8 @@ void Output_SpriteProgram_Init(void)
|
|||
[M_UNIFORM_SMOOTHING_ENABLED] = "uSmoothingEnabled",
|
||||
[M_UNIFORM_BRIGHTNESS_MULTIPLIER] = "uBrightnessMultiplier",
|
||||
[M_UNIFORM_GLOBAL_TINT] = "uGlobalTint",
|
||||
[M_UNIFORM_VIEWPORT_CENTER] = "uViewportCenter",
|
||||
[M_UNIFORM_VIEWPORT_SIZE] = "uViewportSize",
|
||||
[M_UNIFORM_PROJECTION_MATRIX] = "uMatProjection",
|
||||
[M_UNIFORM_PROJECTION_MATRIX_OG] = "uMatProjectionOG",
|
||||
[M_UNIFORM_PHD_PERSP] = "uPhdPersp",
|
||||
[M_UNIFORM_PHD_RES_Z] = "uPhdResZ",
|
||||
[M_UNIFORM_PHD_RES_Z_BUF] = "uPhdResZBuf",
|
||||
[M_UNIFORM_MODEL_MATRIX] = "uMatModelView",
|
||||
[M_UNIFORM_WIBBLE_OFFSET] = "uWibbleOffset",
|
||||
};
|
||||
|
@ -86,9 +76,6 @@ void Output_SpriteProgram_UploadCommonUniforms(void)
|
|||
GFX_TRACK_UNIFORM(
|
||||
glUniform1f, m_Uniforms[M_UNIFORM_BRIGHTNESS_MULTIPLIER],
|
||||
g_Config.visuals.brightness);
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniform2f, m_Uniforms[M_UNIFORM_VIEWPORT_CENTER],
|
||||
Viewport_GetCenterX(), Viewport_GetCenterY());
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniform2f, m_Uniforms[M_UNIFORM_VIEWPORT_SIZE],
|
||||
GFX_Context_GetDisplayWidth(), GFX_Context_GetDisplayHeight());
|
||||
|
@ -135,28 +122,6 @@ void Output_SpriteProgram_UploadProjectionMatrix(void)
|
|||
GFX_TRACK_UNIFORM(
|
||||
glUniformMatrix4fv, m_Uniforms[M_UNIFORM_PROJECTION_MATRIX], 1, GL_TRUE,
|
||||
&projection[0][0]);
|
||||
|
||||
const float left = 0.0f;
|
||||
const float top = 0.0f;
|
||||
const float right = GFX_Context_GetDisplayWidth();
|
||||
const float bottom = GFX_Context_GetDisplayHeight();
|
||||
GLfloat projection_og[4][4] = {
|
||||
{ 2.0f / (right - left), 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 2.0f / (top - bottom), 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, +1.0f, 0.0f },
|
||||
{ -(right + left) / (right - left), -(top + bottom) / (top - bottom),
|
||||
0.0f, 1.0f },
|
||||
};
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniformMatrix4fv, m_Uniforms[M_UNIFORM_PROJECTION_MATRIX_OG], 1,
|
||||
GL_FALSE, &projection_og[0][0]);
|
||||
|
||||
GFX_TRACK_UNIFORM(glUniform1f, m_Uniforms[M_UNIFORM_PHD_PERSP], g_PhdPersp);
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniform1f, m_Uniforms[M_UNIFORM_PHD_RES_Z],
|
||||
g_FltResZ / (float)(1 << W2V_SHIFT));
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniform1f, m_Uniforms[M_UNIFORM_PHD_RES_Z_BUF], g_FltResZBuf);
|
||||
}
|
||||
|
||||
void Output_SpriteProgram_UploadTint(const RGB_F tint)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue