- fixed the normals for sloped planes.

This commit is contained in:
Christoph Oelckers 2022-01-11 23:51:02 +01:00
parent f8ffaa4be9
commit f09bbb8b5e
3 changed files with 40 additions and 27 deletions

View file

@ -286,6 +286,7 @@ public:
uint8_t plane;
short slopecount;
FVector2 geoofs;
FVector3 normal;
//int vboheight;
int slopeindex;

View file

@ -116,6 +116,7 @@ void HWFlat::MakeVertices(HWDrawInfo* di)
}
vertindex = ret.second;
vertcount = pIndices->Size();
normal = mesh->normal;
}
else
{
@ -165,6 +166,13 @@ void HWFlat::MakeVertices(HWDrawInfo* di)
if (minofs < 0 && maxofs <= -ONPLANE_THRESHOLD && minofs >= ONPLANE_THRESHOLD) z -= minofs;
}
}
else
{
if (z < di->Viewpoint.Pos.Z) normal = { 0,1,0 };
normal = { 0, -1, 0 };
}
unsigned svi = di->SlopeSpriteVertices.Reserve(4);
auto svp = &di->SlopeSpriteVertices[svi];
@ -178,7 +186,19 @@ void HWFlat::MakeVertices(HWDrawInfo* di)
else svp->SetTexCoord(j == 1 || j == 2 ? 1.f - x : x, j == 2 || j == 3 ? y : 1.f - y);
svp++;
}
if (Sprite->clipdist & TSPR_SLOPESPRITE)
{
FVector3 v1 = {
di->SlopeSpriteVertices[svi + 1].x - di->SlopeSpriteVertices[svi].x,
di->SlopeSpriteVertices[svi + 1].y - di->SlopeSpriteVertices[svi].y,
di->SlopeSpriteVertices[svi + 1].z - di->SlopeSpriteVertices[svi].z };
FVector3 v2 = {
di->SlopeSpriteVertices[svi + 2].x - di->SlopeSpriteVertices[svi].x,
di->SlopeSpriteVertices[svi + 2].y - di->SlopeSpriteVertices[svi].y,
di->SlopeSpriteVertices[svi + 2].z - di->SlopeSpriteVertices[svi].z };
normal = (v1 ^ v2).Unit();
}
for (unsigned i = 0; i < 6; i++)
{
const static unsigned indices[] = { 0, 1, 2, 0, 2, 3 };
@ -210,18 +230,7 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent)
}
#endif
if (!Sprite)
{
TArray<int> *indices;
auto mesh = sectionGeometry.get(&sections[section], plane, geoofs, &indices);
state.SetNormal(mesh->normal);
}
else
{
if (z < di->Viewpoint.Pos.Z) state.SetNormal({ 0,1,0 });
else state.SetNormal({ 0, -1, 0 });
}
state.SetNormal(normal);
SetLightAndFog(di, state, fade, palette, shade, visibility, alpha);
if (translucent)

View file

@ -46,7 +46,7 @@ SectionGeometry sectionGeometry;
//==========================================================================
//
// CalcPlane fixme - this should be stored in the sector, not be recalculated each frame.
//
//
//==========================================================================
@ -54,31 +54,34 @@ static FVector3 CalcNormal(sectortype* sector, int plane)
{
FVector3 pt[3];
if (plane == 0 && !(sector->floorstat & CSTAT_SECTOR_SLOPE)) return { 0.f, 1.f, 0.f };
if (plane == 1 && !(sector->ceilingstat & CSTAT_SECTOR_SLOPE)) return { 0.f, -1.f, 0.f };
auto wal = sector->firstWall();
auto wal2 = wal->point2Wall();
pt[0] = { (float)WallStartX(wal), (float)WallStartY(wal), 0 };
pt[1] = { (float)WallEndX(wal), (float)WallEndY(wal), 0 };
PlanesAtPoint(sector, wal->pos.X, wal->pos.Y, plane ? &pt[0].Z : nullptr, plane? nullptr : &pt[0].Z);
PlanesAtPoint(sector, wal2->pos.X, wal2->pos.Y, plane ? &pt[1].Z : nullptr, plane ? nullptr : &pt[1].Z);
pt[0] = { (float)WallStartX(wal), 0.f, (float)WallStartY(wal)};
pt[1] = { (float)WallStartX(wal2), 0.f, (float)WallStartY(wal2)};
PlanesAtPoint(sector, wal->pos.X, wal->pos.Y, plane ? &pt[0].Z : nullptr, plane? nullptr : &pt[0].Y);
PlanesAtPoint(sector, wal2->pos.X, wal2->pos.Y, plane ? &pt[1].Z : nullptr, plane ? nullptr : &pt[1].Y);
if (pt[0].X == pt[1].X)
{
if (pt[0].Y == pt[1].Y) return { 0.f, 0.f, plane ? -1.f : 1.f };
if (pt[0].Z == pt[1].Z) return { 0.f, plane ? -1.f : 1.f, 0.f };
pt[2].X = pt[0].X + 4;
pt[2].Y = pt[0].Y;
pt[2].Z = pt[0].Z;
}
else
{
pt[2].X = pt[0].X;
pt[2].Y = pt[0].Y + 4;
pt[2].Z = pt[0].Z + 4;
}
PlanesAtPoint(sector, pt[2].X * 16, pt[2].Y * 16, plane ? &pt[2].Z : nullptr, plane ? nullptr : &pt[2].Z);
PlanesAtPoint(sector, pt[2].X * 16, pt[2].Z * -16, plane ? &pt[2].Z : nullptr, plane ? nullptr : &pt[2].Y);
auto normal = (pt[2] - pt[0]) ^ (pt[1] - pt[0]);
if ((pt[2].Z < 0 && !plane) || (pt[2].Z > 0 && plane)) return -pt[2];
return pt[2];
auto normal = ((pt[2] - pt[0]) ^ (pt[1] - pt[0])).Unit();
if ((normal.Y < 0 && !plane) || (normal.Y > 0 && plane)) return -normal;
return normal;
}
//==========================================================================
@ -364,7 +367,7 @@ bool SectionGeometry::ValidateSection(Section* section, int plane)
sec->firstWall()->point2Wall()->pos == sdata.poscompare2[0] &&
!(section->dirty & EDirty::FloorDirty) && sdata.planes[plane].vertices.Size() ) return true;
section->dirty &= EDirty::FloorDirty;
section->dirty &= ~EDirty::FloorDirty;
}
else
{
@ -453,9 +456,9 @@ void SectionGeometry::CreatePlaneMesh(Section* section, int plane, const FVector
PlanesAtPoint(sectorp, (pt.X * 16), (pt.Y * -16), plane ? &pt.Z : nullptr, !plane ? &pt.Z : nullptr);
tc = uvcalc.GetUV(int(pt.X * 16.), int(pt.Y * -16.), pt.Z);
}
entry.normal = CalcNormal(sectorp, plane);
sectorp->setfloorz(fz, true);
sectorp->setceilingz(cz, true);
entry.normal = CalcNormal(sectorp, plane);
}
//==========================================================================