Added new uniform bool polyAlpha to shaders

Added original matrix functions back into Mat4 class though they are currently unused
This commit is contained in:
gm-matthew 2023-12-22 16:31:05 +00:00
parent 9f66fcaac7
commit 6acb1165d4
7 changed files with 55 additions and 11 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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);
}

View file

@ -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);
}