diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index 44c6a1633..8eeca1c00 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -1647,7 +1647,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) GLInterface.SetClamp(0); VSMatrix imat = 0; imat.scale(1024, 1024, 1024); - auto matrixindex = GLInterface.SetMatrix(Matrix_Model, &imat); + GLInterface.SetMatrix(Matrix_Model, &imat); for (surfi=0; surfihead.numsurfs; surfi++) { @@ -1796,9 +1796,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) GLInterface.SetCull(Cull_None); - VSMatrix identity(0); - GLInterface.RestoreMatrix(Matrix_Model, matrixindex); - + GLInterface.SetIdentityMatrix(Matrix_Model); GLInterface.SetTinting(-1, 0xffffff, 0xffffff); GLInterface.SetClamp(prevClamp); diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 834343ee8..aa4b01e38 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -209,7 +209,6 @@ static void resizeglcheck(void) m[2][3] = 1.f; m[3][2] = -(2.f * farclip * nearclip) / (farclip - nearclip); renderSetProjectionMatrix(&m[0][0]); - GLInterface.SetIdentityMatrix(Matrix_Model); } //(dpx,dpy) specifies an n-sided polygon. The polygon must be a convex clockwise loop. diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index db542102f..15aa1bab8 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -1124,7 +1124,7 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) for (int i = 0; i < 15; i++) mat[i] *= 1024.f; - int matrixindex = GLInterface.SetMatrix(Matrix_Model, mat); + GLInterface.SetMatrix(Matrix_Model, mat); const float ru = 1.f/((float)m->mytexx); const float rv = 1.f/((float)m->mytexy); @@ -1217,8 +1217,7 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr) { GLInterface.SetDepthFunc(Depth_Less); } - VSMatrix identity(0); - GLInterface.RestoreMatrix(Matrix_Model, matrixindex); + GLInterface.SetIdentityMatrix(Matrix_Model); GLInterface.SetFadeDisable(false); GLInterface.SetTinting(-1, 0xffffff, 0xffffff); return 1; diff --git a/source/glbackend/gl_shader.cpp b/source/glbackend/gl_shader.cpp index 1fa5c48f5..6f03e469a 100644 --- a/source/glbackend/gl_shader.cpp +++ b/source/glbackend/gl_shader.cpp @@ -151,10 +151,10 @@ bool PolymostShader::Load(const char * name, const char * vert_prog, const char TintModulate.Init(hShader, "u_tintModulate"); TintOverlay.Init(hShader, "u_tintOverlay"); TintFlags.Init(hShader, "u_tintFlags"); - DetailParms.Init(hShader, "u_detailParms"); - ModelMatrix.Init(hShader, "u_modelMatrix"); - TextureMatrix.Init(hShader, "u_textureMatrix"); + DetailParms.Init(hShader, "uDetailParms"); + ModelMatrix.Init(hShader, "ModelMatrix"); + TextureMatrix.Init(hShader, "TextureMatrix"); diff --git a/source/glbackend/gl_shader.h b/source/glbackend/gl_shader.h index 00e5c30f1..32667334c 100644 --- a/source/glbackend/gl_shader.h +++ b/source/glbackend/gl_shader.h @@ -48,7 +48,7 @@ public: FBufferedUniformPalEntry TintModulate; FBufferedUniformPalEntry TintOverlay; FBufferedUniform1i TintFlags; - FBufferedUniform2f DetailParms; + FBufferedUniform4f DetailParms; FUniformMatrix4f ModelMatrix; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index d6b5aa78c..5e2f1e275 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -101,24 +101,28 @@ void GLInstance::Init(int ydim) } FString i_data = R"( - #version 330 - // This must match the HWViewpointUniforms struct - layout(std140) uniform ViewpointUBO { - mat4 ProjectionMatrix; - mat4 ViewMatrix; - mat4 NormalViewMatrix; + #version 330 + // This must match the HWViewpointUniforms struct + layout(std140) uniform ViewpointUBO { + mat4 ProjectionMatrix; + mat4 ViewMatrix; + mat4 NormalViewMatrix; - vec4 uCameraPos; - vec4 uClipLine; + vec4 uCameraPos; + vec4 uClipLine; - float uGlobVis; // uGlobVis = R_GetGlobVis(r_visibility) / 32.0 - int uPalLightLevels; - int uViewHeight; // Software fuzz scaling - float uClipHeight; - float uClipHeightDirection; - int uShadowmapFilter; - }; - )"; + float uGlobVis; // uGlobVis = R_GetGlobVis(r_visibility) / 32.0 + int uPalLightLevels; + int uViewHeight; // Software fuzz scaling + float uClipHeight; + float uClipHeightDirection; + int uShadowmapFilter; + }; + uniform mat4 ModelMatrix; + uniform mat4 NormalModelMatrix; + uniform mat4 TextureMatrix; + uniform vec4 uDetailParms; +)"; void GLInstance::LoadPolymostShader() { @@ -374,7 +378,8 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState) { mMaterial.mChanged = false; ApplyMaterial(mMaterial.mMaterial, mMaterial.mClampMode, mMaterial.mTranslation, mMaterial.mOverrideShader); - shader->DetailParms.Set(mMaterial.mMaterial->GetDetailScale().X, mMaterial.mMaterial->GetDetailScale().Y); + float buffer[] = { mMaterial.mMaterial->GetDetailScale().X, mMaterial.mMaterial->GetDetailScale().Y, 1.f, 0.f }; + shader->DetailParms.Set(buffer); } if (PaletteTexture != nullptr) @@ -524,8 +529,6 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState) shader->FullscreenTint.Set(fullscreenTint); if (matrixIndex[Matrix_Model] != -1) shader->ModelMatrix.Set(matrixArray[matrixIndex[Matrix_Model]].get()); - if (matrixIndex[Matrix_Texture] != -1) - shader->TextureMatrix.Set(matrixArray[matrixIndex[Matrix_Texture]].get()); memset(matrixIndex, -1, sizeof(matrixIndex)); } @@ -553,7 +556,6 @@ void WriteSavePic(FileWriter* file, int width, int height) OpenGLRenderer::GLRenderer->mBuffers->BindSceneFB(false); screen->SetViewportRects(&bounds); - int oldx = xdim; int oldy = ydim; auto oldwindowxy1 = windowxy1; diff --git a/source/glbackend/hw_draw2d.cpp b/source/glbackend/hw_draw2d.cpp index adc896aa1..16e2faad7 100644 --- a/source/glbackend/hw_draw2d.cpp +++ b/source/glbackend/hw_draw2d.cpp @@ -106,7 +106,6 @@ void GLInstance::Draw2D(F2DDrawer *drawer) { VSMatrix mat(0); screen->mViewpoints->Set2D(OpenGLRenderer::gl_RenderState, xdim, ydim); - SetIdentityMatrix(Matrix_Model); SetViewport(0, 0, xdim, ydim); EnableDepthTest(false); EnableMultisampling(false); diff --git a/source/glbackend/pm_renderstate.h b/source/glbackend/pm_renderstate.h index fb2549e66..84b828869 100644 --- a/source/glbackend/pm_renderstate.h +++ b/source/glbackend/pm_renderstate.h @@ -10,7 +10,6 @@ class FMaterial; enum EMatrixType { Matrix_Model, - Matrix_Texture, // These are the only ones being used. NUMMATRICES }; @@ -67,7 +66,7 @@ struct PolymostRenderState float AlphaThreshold = 0.5f; bool AlphaTest = true; float Color[4] = { 1,1,1,1 }; - short matrixIndex[NUMMATRICES] = { 0,0 }; + short matrixIndex[NUMMATRICES] = { 0 }; PalEntry fullscreenTint = 0xffffff, hictint = 0xffffff, hictint_overlay = 0xffffff; int hictint_flags = -1; FDepthBiasState mBias{ }; diff --git a/wadsrc/static/engine/shaders/glsl/polymost.fp b/wadsrc/static/engine/shaders/glsl/polymost.fp index 655d408f8..93c60d0f0 100644 --- a/wadsrc/static/engine/shaders/glsl/polymost.fp +++ b/wadsrc/static/engine/shaders/glsl/polymost.fp @@ -38,7 +38,6 @@ uniform float u_alphaThreshold; uniform vec4 u_tintOverlay, u_tintModulate; uniform int u_tintFlags; uniform vec4 u_fullscreenTint; -uniform vec2 u_detailParms; uniform float u_npotEmulationFactor; uniform float u_npotEmulationXOffset; @@ -170,7 +169,7 @@ void main() vec4 detailColor = vec4(1.0); if ((u_flags & RF_DetailMapping) != 0) { - detailColor = texture(s_detail, newCoord * u_detailParms); + detailColor = texture(s_detail, newCoord * uDetailParms.xy) * uDetailParms.z; detailColor = mix(vec4(1.0), 2.0 * detailColor, detailColor.a); // Application of this differs based on render mode because for paletted rendering with palettized shade tables it can only be done after processing the shade table. We only have a palette index before. } diff --git a/wadsrc/static/engine/shaders/glsl/polymost.vp b/wadsrc/static/engine/shaders/glsl/polymost.vp index c2015e3cd..bb55ecc98 100644 --- a/wadsrc/static/engine/shaders/glsl/polymost.vp +++ b/wadsrc/static/engine/shaders/glsl/polymost.vp @@ -5,8 +5,6 @@ out float v_fogCoord; out vec4 v_eyeCoordPosition; uniform float u_usePalette; -uniform mat4 u_modelMatrix; -uniform mat4 u_textureMatrix; in vec4 i_vertPos; in vec4 i_texCoord; @@ -16,14 +14,14 @@ in vec4 i_color; void main() { - vec4 vertex = u_modelMatrix * i_vertPos; + vec4 vertex = ModelMatrix * i_vertPos; vec4 eyeCoordPosition = ViewMatrix * vertex; v_eyeCoordPosition = eyeCoordPosition; gl_Position = ProjectionMatrix * eyeCoordPosition; eyeCoordPosition.xyz /= eyeCoordPosition.w; - v_texCoord = u_textureMatrix * i_texCoord; + v_texCoord = TextureMatrix * i_texCoord; v_fogCoord = abs(eyeCoordPosition.z);