From bfe6bffd33d3a4d2a030a9bf6826e9cc6ce553b5 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 7 May 2018 00:33:16 +0200 Subject: [PATCH] - fix hud model clipping --- src/polyrenderer/drawers/poly_triangle.cpp | 19 +++++++++++++++++++ src/polyrenderer/drawers/poly_triangle.h | 15 +++++++++++++++ src/polyrenderer/drawers/screen_triangle.cpp | 10 +++++----- src/polyrenderer/drawers/screen_triangle.h | 1 + src/polyrenderer/scene/poly_model.cpp | 2 ++ src/swrenderer/things/r_model.cpp | 2 ++ 6 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/polyrenderer/drawers/poly_triangle.cpp b/src/polyrenderer/drawers/poly_triangle.cpp index 72174b900..37052aee7 100644 --- a/src/polyrenderer/drawers/poly_triangle.cpp +++ b/src/polyrenderer/drawers/poly_triangle.cpp @@ -79,6 +79,11 @@ void PolyTriangleDrawer::SetCullCCW(const DrawerCommandQueuePtr &queue, bool ccw queue->Push(ccw); } +void PolyTriangleDrawer::SetWeaponScene(const DrawerCommandQueuePtr &queue, bool enable) +{ + queue->Push(enable); +} + ///////////////////////////////////////////////////////////////////////////// void PolyTriangleThreadData::SetViewport(int x, int y, int width, int height, uint8_t *new_dest, int new_dest_width, int new_dest_height, int new_dest_pitch, bool new_dest_bgra, bool new_span_drawers) @@ -94,6 +99,7 @@ void PolyTriangleThreadData::SetViewport(int x, int y, int width, int height, ui dest_bgra = new_dest_bgra; span_drawers = new_span_drawers; ccw = true; + weaponScene = false; } void PolyTriangleThreadData::SetTransform(const Mat4f *newObjectToClip) @@ -117,6 +123,7 @@ void PolyTriangleThreadData::DrawElements(const PolyDrawArgs &drawargs) args.stencilValues = PolyStencilBuffer::Instance()->Values(); args.stencilMasks = PolyStencilBuffer::Instance()->Masks(); args.zbuffer = PolyZBuffer::Instance()->Values(); + args.depthOffset = weaponScene ? 1.0f : 0.0f; const TriVertex *vinput = drawargs.Vertices(); const unsigned int *elements = drawargs.Elements(); @@ -175,6 +182,7 @@ void PolyTriangleThreadData::DrawArrays(const PolyDrawArgs &drawargs) args.stencilValues = PolyStencilBuffer::Instance()->Values(); args.stencilMasks = PolyStencilBuffer::Instance()->Masks(); args.zbuffer = PolyZBuffer::Instance()->Values(); + args.depthOffset = weaponScene ? 1.0f : 0.0f; const TriVertex *vinput = drawargs.Vertices(); int vcount = drawargs.VertexCount(); @@ -580,6 +588,17 @@ void PolySetCullCCWCommand::Execute(DrawerThread *thread) ///////////////////////////////////////////////////////////////////////////// +PolySetWeaponSceneCommand::PolySetWeaponSceneCommand(bool value) : value(value) +{ +} + +void PolySetWeaponSceneCommand::Execute(DrawerThread *thread) +{ + PolyTriangleThreadData::Get(thread)->SetWeaponScene(value); +} + +///////////////////////////////////////////////////////////////////////////// + PolySetViewportCommand::PolySetViewportCommand(int x, int y, int width, int height, uint8_t *dest, int dest_width, int dest_height, int dest_pitch, bool dest_bgra, bool span_drawers) : x(x), y(y), width(width), height(height), dest(dest), dest_width(dest_width), dest_height(dest_height), dest_pitch(dest_pitch), dest_bgra(dest_bgra), span_drawers(span_drawers) { diff --git a/src/polyrenderer/drawers/poly_triangle.h b/src/polyrenderer/drawers/poly_triangle.h index bd147efb5..3cd88d803 100644 --- a/src/polyrenderer/drawers/poly_triangle.h +++ b/src/polyrenderer/drawers/poly_triangle.h @@ -35,6 +35,7 @@ public: static void ClearBuffers(DCanvas *canvas); static void SetViewport(const DrawerCommandQueuePtr &queue, int x, int y, int width, int height, DCanvas *canvas, bool span_drawers); static void SetCullCCW(const DrawerCommandQueuePtr &queue, bool ccw); + static void SetWeaponScene(const DrawerCommandQueuePtr &queue, bool enable); static void SetTransform(const DrawerCommandQueuePtr &queue, const Mat4f *objectToClip); }; @@ -46,6 +47,7 @@ public: void SetViewport(int x, int y, int width, int height, uint8_t *dest, int dest_width, int dest_height, int dest_pitch, bool dest_bgra, bool span_drawers); void SetTransform(const Mat4f *objectToClip); void SetCullCCW(bool value) { ccw = value; } + void SetWeaponScene(bool value) { weaponScene = value; } void DrawElements(const PolyDrawArgs &args); void DrawArrays(const PolyDrawArgs &args); @@ -79,6 +81,7 @@ private: bool dest_bgra = false; uint8_t *dest = nullptr; bool ccw = true; + bool weaponScene = false; const Mat4f *objectToClip = nullptr; bool span_drawers = false; @@ -109,6 +112,18 @@ private: bool ccw; }; +class PolySetWeaponSceneCommand : public DrawerCommand +{ +public: + PolySetWeaponSceneCommand(bool value); + + void Execute(DrawerThread *thread) override; + FString DebugInfo() override { return "PolySetWeaponSceneCommand"; } + +private: + bool value; +}; + class PolySetViewportCommand : public DrawerCommand { public: diff --git a/src/polyrenderer/drawers/screen_triangle.cpp b/src/polyrenderer/drawers/screen_triangle.cpp index 9182c5f0a..c8731dc3e 100644 --- a/src/polyrenderer/drawers/screen_triangle.cpp +++ b/src/polyrenderer/drawers/screen_triangle.cpp @@ -365,7 +365,7 @@ void TriangleBlock::DepthTest(const TriDrawTriangleArgs *args) float stepXW = args->gradientX.W; float stepYW = args->gradientY.W; - float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y); + float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y) + args->depthOffset; uint32_t mask0 = 0; uint32_t mask1 = 0; @@ -413,7 +413,7 @@ void TriangleBlock::DepthTest(const TriDrawTriangleArgs *args) float stepXW = args->gradientX.W; float stepYW = args->gradientY.W; - float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y); + float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y) + args->depthOffset; __m128 mposYW = _mm_setr_ps(posYW, posYW + stepXW, posYW + stepXW + stepXW, posYW + stepXW + stepXW + stepXW); __m128 mstepXW = _mm_set1_ps(stepXW * 4.0f); @@ -959,7 +959,7 @@ void TriangleBlock::DepthWrite(const TriDrawTriangleArgs *args) float stepXW = args->gradientX.W; float stepYW = args->gradientY.W; - float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y); + float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y) + args->depthOffset; if (Mask0 == 0xffffffff && Mask1 == 0xffffffff) { @@ -1020,7 +1020,7 @@ void TriangleBlock::DepthWrite(const TriDrawTriangleArgs *args) float stepXW = args->gradientX.W; float stepYW = args->gradientY.W; - float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y); + float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y) + args->depthOffset; __m128 mposYW = _mm_setr_ps(posYW, posYW + stepXW, posYW + stepXW + stepXW, posYW + stepXW + stepXW + stepXW); __m128 mstepXW = _mm_set1_ps(stepXW * 4.0f); @@ -1180,7 +1180,7 @@ void ScreenTriangle::DrawSWRender(const TriDrawTriangleArgs *args, PolyTriangleT float startX = x + (0.5f - v1X); float startY = y + (0.5f - v1Y); - float posXW = v1W + stepXW * startX + args->gradientY.W * startY; + float posXW = v1W + stepXW * startX + args->gradientY.W * startY + args->depthOffset; #ifndef NO_SSE __m128 mstepXW = _mm_set1_ps(stepXW * 4.0f); diff --git a/src/polyrenderer/drawers/screen_triangle.h b/src/polyrenderer/drawers/screen_triangle.h index 9480952a4..df635a29e 100644 --- a/src/polyrenderer/drawers/screen_triangle.h +++ b/src/polyrenderer/drawers/screen_triangle.h @@ -60,6 +60,7 @@ struct TriDrawTriangleArgs bool destBgra; ScreenTriangleStepVariables gradientX; ScreenTriangleStepVariables gradientY; + float depthOffset; bool CalculateGradients() { diff --git a/src/polyrenderer/scene/poly_model.cpp b/src/polyrenderer/scene/poly_model.cpp index 40c72d034..2e057709b 100644 --- a/src/polyrenderer/scene/poly_model.cpp +++ b/src/polyrenderer/scene/poly_model.cpp @@ -105,11 +105,13 @@ void PolyModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectT ModelActor = actor; const_cast(objectToWorldMatrix).copy(ObjectToWorld.Matrix); SetTransform(); + PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, true); } void PolyModelRenderer::EndDrawHUDModel(AActor *actor) { ModelActor = nullptr; + PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, false); } void PolyModelRenderer::SetInterpolation(double interpolation) diff --git a/src/swrenderer/things/r_model.cpp b/src/swrenderer/things/r_model.cpp index 24500bad7..a07cd0682 100644 --- a/src/swrenderer/things/r_model.cpp +++ b/src/swrenderer/things/r_model.cpp @@ -155,11 +155,13 @@ namespace swrenderer ModelActor = actor; const_cast(objectToWorldMatrix).copy(ObjectToWorld.Matrix); SetTransform(); + PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, true); } void SWModelRenderer::EndDrawHUDModel(AActor *actor) { ModelActor = nullptr; + PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, false); } void SWModelRenderer::SetInterpolation(double interpolation)