diff --git a/source/core/rendering/scene/hw_clipper.cpp b/source/core/rendering/scene/hw_clipper.cpp index 0b9c74e91..13476a747 100644 --- a/source/core/rendering/scene/hw_clipper.cpp +++ b/source/core/rendering/scene/hw_clipper.cpp @@ -38,6 +38,7 @@ #include "hw_clipper.h" #include "basics.h" #include "build.h" +#include "printf.h" unsigned Clipper::starttime; @@ -380,5 +381,10 @@ binangle Clipper::PointToAngle(const vec2_t& pos) #endif } - - +void Clipper::DumpClipper() +{ + for (auto node = cliphead; node; node = node->next) + { + Printf("Range from %f to %f\n", bamang(node->start).asdeg(), bamang(node->end).asdeg()); + } +} diff --git a/source/core/rendering/scene/hw_clipper.h b/source/core/rendering/scene/hw_clipper.h index 728d09290..e19a01136 100644 --- a/source/core/rendering/scene/hw_clipper.h +++ b/source/core/rendering/scene/hw_clipper.h @@ -141,6 +141,8 @@ public: { return blocked; } + + void DumpClipper(); binangle PointToAngle(const vec2_t& point); diff --git a/source/core/rendering/scene/hw_drawinfo.cpp b/source/core/rendering/scene/hw_drawinfo.cpp index 148389706..8ca11a85e 100644 --- a/source/core/rendering/scene/hw_drawinfo.cpp +++ b/source/core/rendering/scene/hw_drawinfo.cpp @@ -143,7 +143,8 @@ void HWDrawInfo::StartScene(FRenderViewpoint& parentvp, HWViewpointUniforms* uni VPUniforms.mClipLine.X = -10000000.0f; VPUniforms.mShadowmapFilter = gl_shadowmap_filter; } - mClipper->SetViewpoint({viewx, viewy}); + vec2_t view = { int(Viewpoint.Pos.X * 16), int(Viewpoint.Pos.Y * -16) }; + mClipper->SetViewpoint(view); ClearBuffers(); @@ -309,10 +310,6 @@ void HWDrawInfo::CreateScene() mDrawer.Init(this, mClipper, view); mDrawer.RenderScene(vp.SectNum); - // And now the crappy hacks that have to be done to avoid rendering anomalies. - // These cannot be multithreaded when the time comes because all these depend - // on the global 'validcount' variable. - screen->mLights->Unmap(); screen->mVertexData->Unmap(); diff --git a/source/core/rendering/scene/hw_drawinfo.h b/source/core/rendering/scene/hw_drawinfo.h index 3ddd9b4b2..e49e240cb 100644 --- a/source/core/rendering/scene/hw_drawinfo.h +++ b/source/core/rendering/scene/hw_drawinfo.h @@ -107,7 +107,6 @@ struct HWDrawInfo TArray Decals[2]; // the second slot is for mirrors which get rendered in a separate pass. // This is needed by the BSP traverser. - fixed_t viewx, viewy; // since the nodes are still fixed point, keeping the view position also fixed point for node traversal is faster. bool multithread; private: diff --git a/source/core/rendering/scene/hw_drawlistadd.cpp b/source/core/rendering/scene/hw_drawlistadd.cpp index 5f3e76bbe..22958c07c 100644 --- a/source/core/rendering/scene/hw_drawlistadd.cpp +++ b/source/core/rendering/scene/hw_drawlistadd.cpp @@ -71,7 +71,6 @@ void HWDrawInfo::AddWall(HWWall *wall) void HWDrawInfo::AddMirrorSurface(HWWall *w) { -#if 0 w->type = RENDERWALL_MIRRORSURFACE; auto newwall = drawlists[GLDL_TRANSLUCENTBORDER].NewWall(); *newwall = *w; @@ -94,7 +93,6 @@ void HWDrawInfo::AddMirrorSurface(HWWall *w) newwall->ProcessDecals(this); #endif newwall->dynlightindex = -1; // the environment map should not be affected by lights - only the decals. -#endif } //========================================================================== diff --git a/source/core/rendering/scene/hw_portal.cpp b/source/core/rendering/scene/hw_portal.cpp index f70bc35ab..53c3b48e4 100644 --- a/source/core/rendering/scene/hw_portal.cpp +++ b/source/core/rendering/scene/hw_portal.cpp @@ -403,12 +403,15 @@ void HWScenePortalBase::ClearClipper(HWDrawInfo *di, Clipper *clipper) clipper->Clear(); + auto& vp = di->Viewpoint; + vec2_t view = { int(vp.Pos.X * 16), int(vp.Pos.Y * -16) }; + // Set the clipper to the minimal visible area clipper->SafeAddClipRange(bamang(0), bamang(0xffffffff)); for (unsigned int i = 0; i < lines.Size(); i++) { - binangle startang = q16ang(gethiq16angle(lines[i].seg->x - di->viewx, lines[i].seg->y - di->viewy)); - binangle endang = q16ang(gethiq16angle(wall[lines[i].seg->point2].x - di->viewx, wall[lines[i].seg->point2].y - di->viewy)); + binangle startang = q16ang(gethiq16angle(lines[i].seg->x - view.x, lines[i].seg->y - view.y)); + binangle endang = q16ang(gethiq16angle(wall[lines[i].seg->point2].x - view.x, wall[lines[i].seg->point2].y - view.y)); if (endang.asbam() - startang.asbam() >= ANGLE_180) { @@ -533,25 +536,29 @@ bool HWMirrorPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clippe di->mClipPortal = this; - int x = line->x, dx = wall[line->point2].x - x; - int y = line->y, dy = wall[line->point2].y - y; + int x = line->x; + int y = line->y; + int dx = wall[line->point2].x - x; + int dy = wall[line->point2].y - y; // this can overflow so use 64 bit math. const int64_t j = int64_t(dx) * dx + int64_t(dy) * dy; if (j == 0) return false; - int64_t i = ((int64_t(di->viewx) - x) * dx + (int64_t(di->viewy) - y) * dy) << 1; + vec2_t view = { int(vp.Pos.X * 16), int(vp.Pos.Y * -16) }; - int newx = int((x << 1) + Scale(dx, i, j) - di->viewx); - int newy = int((y << 1) + Scale(dy, i, j) - di->viewy); - int newan = ((gethiq16angle(dx, dy) << 1) - vp.RotAngle) & 0x7FFFFFF; + int64_t i = ((int64_t(view.x) - x) * dx + (int64_t(view.y) - y) * dy) << 1; + + int newx = int((x << 1) + Scale(dx, i, j) - view.x); + int newy = int((y << 1) + Scale(dy, i, j) - view.y); + int newan = ((gethiq16angle(dx, dy) << 1) - bamang(vp.RotAngle).asq16()) & 0x7FFFFFF; vp.RotAngle = q16ang(newan).asbam(); - di->viewx = newx; - di->viewy = newy; + vp.SectNum = line->sector; vp.Pos.X = newx / 16.f; vp.Pos.Y = newy / -16.f; + vp.HWAngles.Yaw = -90.f + q16ang(newan).asdeg(); int oldstat = 0; if (vp.CameraSprite) diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index df01576da..d9bf8faf9 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -164,6 +164,8 @@ void HWWall::RenderMirrorSurface(HWDrawInfo *di, FRenderState &state) // Use sphere mapping for this state.SetEffect(EFF_SPHEREMAP); SetLightAndFog(state); + state.SetColor(PalEntry(25, globalr >> 1, globalg >> 1, globalb >> 1)); + state.SetRenderStyle(STYLE_Add); state.AlphaFunc(Alpha_Greater, 0);