diff --git a/Src/Graphics/New3D/Mat4.cpp b/Src/Graphics/New3D/Mat4.cpp index 2181cd7..ba0a925 100644 --- a/Src/Graphics/New3D/Mat4.cpp +++ b/Src/Graphics/New3D/Mat4.cpp @@ -149,7 +149,40 @@ void Mat4::Rotate(float angle, float x, float y, float z) Mat4::MultiMatrices(currentMatrix, m, currentMatrix); } -void Mat4::Frustum(float left, float right, float bottom, float top, float nearVal) +void Mat4::Frustum(float left, float right, float bottom, float top, float nearVal, float farVal) +{ + float x = 2.0F / (right - left); + float y = 2.0F / (top - bottom); + float a = (right + left) / (right - left); + float b = (top + bottom) / (top - bottom); + float c = -(farVal + nearVal) / (farVal - nearVal); + float d = -(2.0F * farVal * nearVal) / (farVal - nearVal); + + float m[16]; + m[0] = x; + m[1] = 0.f; + m[2] = 0.f; + m[3] = 0.f; + + m[4] = 0.f; + m[5] = y; + m[6] = 0.f; + m[7] = 0.f; + + m[8] = a; + m[9] = b; + m[10] = c; + m[11] = -1.f; + + m[12] = 0.f; + m[13] = 0.f; + m[14] = d; + m[15] = 0.f; + + Mat4::MultiMatrices(currentMatrix, m, currentMatrix); +} + +void Mat4::FrustumRZ(float left, float right, float bottom, float top, float nearVal) { float x = 2.0F / (right - left); float y = 2.0F / (top - bottom); @@ -180,19 +213,19 @@ void Mat4::Frustum(float left, float right, float bottom, float top, float nearV Mat4::MultiMatrices(currentMatrix, m, currentMatrix); } -void Mat4::Perspective(float fovy, float aspect, float zNear) +void Mat4::Perspective(float fovy, float aspect, float zNear, float zFar) { float ymax = tanf(fovy * (float)(M_PI / 360.0)); float xmax = ymax * aspect; - Frustum(-xmax, xmax, -ymax, ymax, zNear); + Frustum(-xmax, xmax, -ymax, ymax, zNear, zFar); } void Mat4::Ortho(float left, float right, float bottom, float top, float nearVal, float farVal) { float tx = -(right + left) / (right - left); float ty = -(top + bottom) / (top - bottom); - float tz = (farVal + nearVal - 1.f) / (farVal - nearVal); + float tz = -(farVal + nearVal) / (farVal - nearVal); float m[16]; m[0] = 2.f/(right-left); @@ -207,7 +240,7 @@ void Mat4::Ortho(float left, float right, float bottom, float top, float nearVal m[8] = 0.f; m[9] = 0.f; - m[10] = 1.f/(farVal-nearVal); + m[10] = -2.f/(farVal-nearVal); m[11] = 0.f; m[12] = tx; diff --git a/Src/Graphics/New3D/Mat4.h b/Src/Graphics/New3D/Mat4.h index f8f6702..1c3f81a 100644 --- a/Src/Graphics/New3D/Mat4.h +++ b/Src/Graphics/New3D/Mat4.h @@ -15,8 +15,9 @@ public: void Translate (float x, float y, float z); void Rotate (float angle, float x, float y, float z); void Scale (float x, float y, float z); - void Frustum (float left, float right, float bottom, float top, float nearVal); - void Perspective (float fovy, float aspect, float zNear); + void Frustum (float left, float right, float bottom, float top, float nearVal, float farVal); + void FrustumRZ (float left, float right, float bottom, float top, float nearVal); + void Perspective (float fovy, float aspect, float zNear, float zFar); void Ortho (float left, float right, float bottom, float top, float nearVal, float farVal); void MultMatrix (const float *m); void LoadMatrix (const float *m); diff --git a/Src/Graphics/New3D/New3D.cpp b/Src/Graphics/New3D/New3D.cpp index 40c2b72..88e5be6 100644 --- a/Src/Graphics/New3D/New3D.cpp +++ b/Src/Graphics/New3D/New3D.cpp @@ -1543,7 +1543,7 @@ void CNew3D::CalcViewport(Viewport* vp) vp->width = m_totalXRes; vp->height = (int)((float)vp->vpHeight*m_yRatio); - vp->projectionMatrix.Frustum(l*correction, r*correction, b, t, NEAR_PLANE); + vp->projectionMatrix.FrustumRZ(l*correction, r*correction, b, t, NEAR_PLANE); } else { @@ -1552,7 +1552,7 @@ void CNew3D::CalcViewport(Viewport* vp) vp->width = (int)((float)vp->vpWidth*m_xRatio); vp->height = (int)((float)vp->vpHeight*m_yRatio); - vp->projectionMatrix.Frustum(l, r, b, t, NEAR_PLANE); + vp->projectionMatrix.FrustumRZ(l, r, b, t, NEAR_PLANE); } } diff --git a/Src/Graphics/New3D/R3DShader.cpp b/Src/Graphics/New3D/R3DShader.cpp index fb7a6bd..2c4c9e0 100644 --- a/Src/Graphics/New3D/R3DShader.cpp +++ b/Src/Graphics/New3D/R3DShader.cpp @@ -112,6 +112,7 @@ bool R3DShader::LoadShader(const char* vertexShader, const char* fragmentShader) m_locTextureInverted = glGetUniformLocation(m_shaderProgram, "textureInverted"); m_locTexWrapMode = glGetUniformLocation(m_shaderProgram, "textureWrapMode"); m_locColourLayer = glGetUniformLocation(m_shaderProgram, "colourLayer"); + m_locPolyAlpha = glGetUniformLocation(m_shaderProgram, "polyAlpha"); m_locFogIntensity = glGetUniformLocation(m_shaderProgram, "fogIntensity"); m_locFogDensity = glGetUniformLocation(m_shaderProgram, "fogDensity"); @@ -292,6 +293,11 @@ void R3DShader::SetMeshUniforms(const Mesh* m) m_translatorMap = m->translatorMap; } + if (m_dirtyMesh || m->polyAlpha != m_polyAlpha) { + glUniform1i(m_locPolyAlpha, m->polyAlpha); + m_polyAlpha = m->polyAlpha; + } + if (m_dirtyMesh || m->wrapModeU != m_texWrapMode[0] || m->wrapModeV != m_texWrapMode[1]) { m_texWrapMode[0] = m->wrapModeU; m_texWrapMode[1] = m->wrapModeV; diff --git a/Src/Graphics/New3D/R3DShader.h b/Src/Graphics/New3D/R3DShader.h index 778a910..84ca182 100644 --- a/Src/Graphics/New3D/R3DShader.h +++ b/Src/Graphics/New3D/R3DShader.h @@ -55,6 +55,7 @@ private: GLint m_locTexWrapMode; GLint m_locTranslatorMap; GLint m_locColourLayer; + GLint m_locPolyAlpha; // cached mesh values bool m_textured1; @@ -68,6 +69,7 @@ private: bool m_specularEnabled; bool m_fixedShading; bool m_translatorMap; + bool m_polyAlpha; bool m_layered; bool m_noLosReturn; diff --git a/Src/Graphics/New3D/R3DShaderQuads.h b/Src/Graphics/New3D/R3DShaderQuads.h index be8c7cc..5a81d49 100644 --- a/Src/Graphics/New3D/R3DShaderQuads.h +++ b/Src/Graphics/New3D/R3DShaderQuads.h @@ -211,6 +211,7 @@ uniform float fogAmbient; uniform bool fixedShading; uniform int hardwareStep; uniform int colourLayer; +uniform bool polyAlpha; // matrices (shared with vertex shader) uniform mat4 projMat; @@ -434,7 +435,7 @@ void main() // Optional clamping, value is allowed to be negative // We suspect that translucent polygons are always clamped (e.g. lasers in Daytona 2) - if(sunClamp || fsColor.a < 0.99) { + if(sunClamp || polyAlpha) { sunFactor = max(sunFactor,0.0); } diff --git a/Src/Graphics/New3D/R3DShaderTriangles.h b/Src/Graphics/New3D/R3DShaderTriangles.h index 0d868b9..b28ac24 100644 --- a/Src/Graphics/New3D/R3DShaderTriangles.h +++ b/Src/Graphics/New3D/R3DShaderTriangles.h @@ -102,6 +102,7 @@ uniform float fogAmbient; uniform bool fixedShading; uniform int hardwareStep; uniform int colourLayer; +uniform bool polyAlpha; // matrices (shared with vertex shader) uniform mat4 projMat; @@ -210,7 +211,7 @@ void main() // Optional clamping, value is allowed to be negative // We suspect that translucent polygons are always clamped (e.g. lasers in Daytona 2) - if(sunClamp || fsColor.a < 0.99) { + if(sunClamp || polyAlpha) { sunFactor = max(sunFactor,0.0); }