- finally got mirrors working.

This commit is contained in:
Christoph Oelckers 2021-03-23 21:23:49 +01:00
parent c681fa6699
commit 087da46522
7 changed files with 31 additions and 20 deletions

View file

@ -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());
}
}

View file

@ -141,6 +141,8 @@ public:
{
return blocked;
}
void DumpClipper();
binangle PointToAngle(const vec2_t& point);

View file

@ -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();

View file

@ -107,7 +107,6 @@ struct HWDrawInfo
TArray<HWDecal *> 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:

View file

@ -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
}
//==========================================================================

View file

@ -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)

View file

@ -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);