diff --git a/source/common/textures/hw_material.cpp b/source/common/textures/hw_material.cpp index 4f5c301db..8df0b6298 100644 --- a/source/common/textures/hw_material.cpp +++ b/source/common/textures/hw_material.cpp @@ -83,30 +83,30 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) auto placeholder = TexMan.GameByIndex(1); if (tx->Brightmap.get()) { - mTextureLayers.Push({ tx->Brightmap.get(), scaleflags }); + mTextureLayers.Push({ tx->Brightmap.get(), scaleflags, -1 }); mLayerFlags |= TEXF_Brightmap; } else { - mTextureLayers.Push({ placeholder->GetTexture(), 0 }); + mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 }); } if (tx->Detailmap.get()) { - mTextureLayers.Push({ tx->Detailmap.get(), 0 }); + mTextureLayers.Push({ tx->Detailmap.get(), 0, CLAMP_NONE }); mLayerFlags |= TEXF_Detailmap; } else { - mTextureLayers.Push({ placeholder->GetTexture(), 0 }); + mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 }); } if (tx->Glowmap.get()) { - mTextureLayers.Push({ tx->Glowmap.get(), scaleflags }); + mTextureLayers.Push({ tx->Glowmap.get(), scaleflags, -1 }); mLayerFlags |= TEXF_Glowmap; } else { - mTextureLayers.Push({ placeholder->GetTexture(), 0 }); + mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 }); } auto index = tx->GetShaderIndex(); diff --git a/source/common/textures/hw_material.h b/source/common/textures/hw_material.h index d7509cc94..e8c013d2b 100644 --- a/source/common/textures/hw_material.h +++ b/source/common/textures/hw_material.h @@ -12,6 +12,7 @@ struct MaterialLayerInfo { FTexture* layerTexture; int scaleFlags; + int clampflags; }; //=========================================================================== @@ -37,6 +38,10 @@ public: int GetShaderIndex() const { return mShaderIndex; } int GetScaleFlags() const { return mScaleFlags; } virtual void DeleteDescriptors() { } + FVector2 GetDetailScale() const + { + return sourcetex->GetDetailScale(); + } FGameTexture* Source() const { diff --git a/source/glbackend/gl_shader.cpp b/source/glbackend/gl_shader.cpp index 9cdc56c50..ac7aa9d1a 100644 --- a/source/glbackend/gl_shader.cpp +++ b/source/glbackend/gl_shader.cpp @@ -148,11 +148,11 @@ 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"); RotMatrix.Init(hShader, "u_rotMatrix"); ModelMatrix.Init(hShader, "u_modelMatrix"); ProjectionMatrix.Init(hShader, "u_projectionMatrix"); - DetailMatrix.Init(hShader, "u_detailMatrix"); TextureMatrix.Init(hShader, "u_textureMatrix"); @@ -161,7 +161,6 @@ bool PolymostShader::Load(const char * name, const char * vert_prog, const char VSMatrix identity(0); TextureMatrix.Set(identity.get()); - DetailMatrix.Set(identity.get()); int SamplerLoc; SamplerLoc = glGetUniformLocation(hShader, "s_texture"); diff --git a/source/glbackend/gl_shader.h b/source/glbackend/gl_shader.h index a6eeaf05a..754174ba0 100644 --- a/source/glbackend/gl_shader.h +++ b/source/glbackend/gl_shader.h @@ -49,12 +49,12 @@ public: FBufferedUniformPalEntry TintModulate; FBufferedUniformPalEntry TintOverlay; FBufferedUniform1i TintFlags; + FBufferedUniform2f DetailParms; FUniformMatrix4f RotMatrix; FUniformMatrix4f ModelMatrix; FUniformMatrix4f ProjectionMatrix; - FUniformMatrix4f DetailMatrix; FUniformMatrix4f TextureMatrix; public: diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index d8539dd25..e1b58b435 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -194,7 +194,6 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count) rendercommands.Push(renderState); clearMapFog(); SetIdentityMatrix(Matrix_Texture); - SetIdentityMatrix(Matrix_Detail); renderState.StateFlags &= ~(STF_CLEARCOLOR | STF_CLEARDEPTH | STF_VIEWPORTSET | STF_SCISSORSET); } @@ -312,16 +311,17 @@ void PolymostRenderState::ApplyMaterial(FMaterial* mat, int clampmode, int trans MaterialLayerInfo* layer; auto base = static_cast(mat->GetLayer(0, translation, &layer)); scf |= layer->scaleFlags; - if (base->BindOrCreate(layer->layerTexture, 0, clampmode, translation, scf)) + if (base->BindOrCreate(layer->layerTexture, 0, layer->clampflags == -1? clampmode : layer->clampflags, translation, scf)) { for (int i = 1; i < numLayers; i++) { auto systex = static_cast(mat->GetLayer(i, 0, &layer)); // fixme: Upscale flags must be disabled for certain layers. - systex->BindOrCreate(layer->layerTexture, i, clampmode, 0, layer->scaleFlags); + systex->BindOrCreate(layer->layerTexture, i, layer->clampflags == -1 ? clampmode : layer->clampflags, 0, layer->scaleFlags); maxbound = i; } } + // The palette lookup must be done manually. #if 0 // unbind everything from the last texture that's still active @@ -343,6 +343,7 @@ 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); } if (PaletteTexture != nullptr) @@ -497,8 +498,6 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState) shader->ProjectionMatrix.Set(matrixArray[matrixIndex[Matrix_Projection]].get()); if (matrixIndex[Matrix_Model] != -1) shader->ModelMatrix.Set(matrixArray[matrixIndex[Matrix_Model]].get()); - if (matrixIndex[Matrix_Detail] != -1) - shader->DetailMatrix.Set(matrixArray[matrixIndex[Matrix_Detail]].get()); if (matrixIndex[Matrix_Texture] != -1) shader->TextureMatrix.Set(matrixArray[matrixIndex[Matrix_Texture]].get()); memset(matrixIndex, -1, sizeof(matrixIndex)); diff --git a/source/glbackend/hw_draw2d.cpp b/source/glbackend/hw_draw2d.cpp index 0fc2040ea..b7a349786 100644 --- a/source/glbackend/hw_draw2d.cpp +++ b/source/glbackend/hw_draw2d.cpp @@ -104,7 +104,6 @@ void GLInstance::Draw2D(F2DDrawer *drawer) VSMatrix mat(0); SetIdentityMatrix(Matrix_View); SetIdentityMatrix(Matrix_Model); - SetIdentityMatrix(Matrix_Detail); mat.ortho(0, xdim, ydim, 0, -1, 1); SetMatrix(Matrix_Projection, mat.get()); SetViewport(0, 0, xdim, ydim); diff --git a/source/glbackend/pm_renderstate.h b/source/glbackend/pm_renderstate.h index 7cbf798ca..e15899c52 100644 --- a/source/glbackend/pm_renderstate.h +++ b/source/glbackend/pm_renderstate.h @@ -12,7 +12,6 @@ enum EMatrixType Matrix_View, Matrix_Projection, Matrix_Model, - Matrix_Detail, Matrix_Texture, // These are the only ones being used. NUMMATRICES @@ -71,7 +70,7 @@ struct PolymostRenderState float AlphaThreshold = 0.5f; bool AlphaTest = true; float Color[4] = { 1,1,1,1 }; - short matrixIndex[NUMMATRICES] = { 0,0,0,0,0 }; + short matrixIndex[NUMMATRICES] = { 0,0,0,0 }; PalEntry fullscreenTint = 0xffffff, hictint = 0xffffff, hictint_overlay = 0xffffff; int hictint_flags = -1; FDepthBiasState mBias{ }; diff --git a/wadsrc/static/engine/shaders/glsl/polymost.vp b/wadsrc/static/engine/shaders/glsl/polymost.vp index 3784f3db0..b2387ad02 100644 --- a/wadsrc/static/engine/shaders/glsl/polymost.vp +++ b/wadsrc/static/engine/shaders/glsl/polymost.vp @@ -11,8 +11,8 @@ uniform float u_usePalette; uniform mat4 u_rotMatrix; uniform mat4 u_modelMatrix; uniform mat4 u_projectionMatrix; -uniform mat4 u_detailMatrix; uniform mat4 u_textureMatrix; +uniform vec2 u_detailParms; in vec4 i_vertPos; in vec4 i_texCoord; @@ -30,7 +30,7 @@ void main() eyeCoordPosition.xyz /= eyeCoordPosition.w; v_texCoord = u_textureMatrix * i_texCoord; - v_detailCoord = u_detailMatrix * i_texCoord; + v_detailCoord = vec4(i_texCoord.x * u_detailParms.x, i_texCoord.y * u_detailParms.y, 0.0, 0.0); v_fogCoord = abs(eyeCoordPosition.z);