From ce6e1e1e472e3b6cef3892007aa6f1170d0f9aec Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 2 Dec 2016 13:24:53 +0100 Subject: [PATCH] Fully hook up sprite clipping by subsector --- src/r_poly_portal.cpp | 17 ++++------------- src/r_poly_sprite.cpp | 20 +++++++++++++------- src/r_poly_sprite.h | 2 +- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/r_poly_portal.cpp b/src/r_poly_portal.cpp index 7d8c385dd..1047164cb 100644 --- a/src/r_poly_portal.cpp +++ b/src/r_poly_portal.cpp @@ -150,18 +150,9 @@ void RenderPolyPortal::RenderSprite(AActor *thing, double sortDistance, DVector2 DVector2 mid = left * (1.0 - t) + right * t; double tmid = t1 * (1.0 - t) + t2 * t; - if (sideLeft == 0) - { - RenderSprite(thing, sortDistance, mid, right, tmid, t2, bsp->children[sideRight]); - right = mid; - t2 = tmid; - } - else - { - RenderSprite(thing, sortDistance, left, mid, t1, tmid, bsp->children[sideRight]); - left = mid; - t1 = tmid; - } + RenderSprite(thing, sortDistance, mid, right, tmid, t2, bsp->children[sideRight]); + right = mid; + t2 = tmid; } node = bsp->children[sideLeft]; } @@ -346,7 +337,7 @@ void RenderPolyPortal::RenderTranslucent(int portalDepth) else { RenderPolySprite spr; - spr.Render(WorldToClip, PortalPlane, obj.thing, obj.sub, obj.subsectorDepth, StencilValue + 1); + spr.Render(WorldToClip, PortalPlane, obj.thing, obj.sub, obj.subsectorDepth, StencilValue + 1, obj.SpriteLeft, obj.SpriteRight); } } } diff --git a/src/r_poly_sprite.cpp b/src/r_poly_sprite.cpp index 5d4a9ba6c..c17bc5909 100644 --- a/src/r_poly_sprite.cpp +++ b/src/r_poly_sprite.cpp @@ -63,10 +63,10 @@ bool RenderPolySprite::GetLine(AActor *thing, DVector2 &left, DVector2 &right) return true; } -void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue) +void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, float t1, float t2) { - DVector2 points[2]; - if (!GetLine(thing, points[0], points[1])) + DVector2 line[2]; + if (!GetLine(thing, line[0], line[1])) return; DVector3 pos = thing->InterpolatedPosition(r_TicFracF); @@ -108,10 +108,16 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla std::pair offsets[4] = { - { 0.0f, 1.0f }, - { 1.0f, 1.0f }, - { 1.0f, 0.0f }, - { 0.0f, 0.0f }, + { t1, 1.0f }, + { t2, 1.0f }, + { t2, 0.0f }, + { t1, 0.0f }, + }; + + DVector2 points[2] = + { + line[0] * (1.0 - t1) + line[1] * t1, + line[0] * (1.0 - t2) + line[1] * t2 }; for (int i = 0; i < 4; i++) diff --git a/src/r_poly_sprite.h b/src/r_poly_sprite.h index 8ce9caffd..085845e50 100644 --- a/src/r_poly_sprite.h +++ b/src/r_poly_sprite.h @@ -29,7 +29,7 @@ class Vec4f; class RenderPolySprite { public: - void Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue); + void Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, float t1, float t2); static bool GetLine(AActor *thing, DVector2 &left, DVector2 &right); static bool IsThingCulled(AActor *thing);