From 35c2d6d14eda71dc86dca5736e30a85e7ffcf4b7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 28 Nov 2021 18:05:19 +0100 Subject: [PATCH] - fixed translucent voxel rendering. --- source/build/src/polymost.cpp | 23 ++++++++++++++++++++++ source/core/rendering/scene/hw_sprites.cpp | 7 ++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 907ac7fca..bf7911b24 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -3927,6 +3927,29 @@ int32_t polymost_voxdraw(voxmodel_t* m, tspriteptr_t const tspr, bool rotate) auto tex = TexMan.GetGameTexture(m->model->GetPaletteTexture()); GLInterface.SetTexture(tex, TRANSLATION(Translation_Remap + curbasepal, globalpal), CLAMP_NOFILTER_XY, true); GLInterface.SetModel(m->model, 0, 0, 0); + + // The shade rgb from the tint is ignored here. + pc[0] = (float)globalr * (1.f / 255.f); + pc[1] = (float)globalg * (1.f / 255.f); + pc[2] = (float)globalb * (1.f / 255.f); + + bool trans = (tspr->cstat & CSTAT_SPRITE_TRANSLUCENT); + float alpha; + FRenderStyle RenderStyle; + if (trans) + { + RenderStyle = GetRenderStyle(0, !!(tspr->cstat & CSTAT_SPRITE_TRANSLUCENT_INVERT)); + alpha = GetAlphaFromBlend((tspr->cstat & CSTAT_SPRITE_TRANSLUCENT_INVERT) ? DAMETH_TRANS2 : DAMETH_TRANS1, 0); + } + else + { + RenderStyle = LegacyRenderStyles[STYLE_Translucent]; + alpha = 1.f; + } + alpha *= 1.f - spriteext[tspr->owner].alpha; + GLInterface.SetRenderStyle(RenderStyle); + GLInterface.SetColor(pc[0], pc[1], pc[2], alpha); + GLInterface.Draw(DT_Triangles, 0, 0); GLInterface.SetModel(nullptr, 0, 0, 0); GLInterface.SetCull(Cull_None); diff --git a/source/core/rendering/scene/hw_sprites.cpp b/source/core/rendering/scene/hw_sprites.cpp index ee9882455..3082bc274 100644 --- a/source/core/rendering/scene/hw_sprites.cpp +++ b/source/core/rendering/scene/hw_sprites.cpp @@ -144,17 +144,19 @@ void HWSprite::DrawSprite(HWDrawInfo* di, FRenderState& state, bool translucent) } else { - state.EnableModelMatrix(true); - state.mModelMatrix = rotmat; FHWModelRenderer mr(state, dynlightindex); if (modelframe < 0) { + state.mModelMatrix = rotmat; + auto model = voxel->model; state.SetDepthFunc(DF_LEqual); state.EnableTexture(true); model->BuildVertexBuffer(&mr); + mr.BeginDrawModel(RenderStyle, nullptr, rotmat, portalState.isMirrored()); mr.SetupFrame(model, 0, 0, 0); model->RenderFrame(&mr, TexMan.GetGameTexture(model->GetPaletteTexture()), 0, 0, 0.f, TRANSLATION(Translation_Remap + curbasepal, palette)); + mr.EndDrawModel(RenderStyle, nullptr); state.SetDepthFunc(DF_Less); state.SetVertexBuffer(screen->mVertexData); @@ -165,7 +167,6 @@ void HWSprite::DrawSprite(HWDrawInfo* di, FRenderState& state, bool translucent) } state.SetObjectColor(0xffffffff); state.SetVertexBuffer(screen->mVertexData); - state.EnableModelMatrix(false); } if (translucent)