- Improve wall texture coordinates in softpoly

This commit is contained in:
Magnus Norddahl 2017-05-06 15:48:04 +02:00
parent ce0547aacb
commit aca628acaf
2 changed files with 63 additions and 43 deletions

View file

@ -88,9 +88,12 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const PolyClipPlan
if (line->sidedef) if (line->sidedef)
{ {
wall.SetCoords(line->v1->fPos(), line->v2->fPos(), frontceilz1, frontfloorz1, frontceilz2, frontfloorz2); wall.SetCoords(line->v1->fPos(), line->v2->fPos(), frontceilz1, frontfloorz1, frontceilz2, frontfloorz2);
wall.TopZ = frontceilz1; wall.TopZ1 = frontceilz1;
wall.BottomZ = frontfloorz1; wall.TopZ2 = frontceilz2;
wall.UnpeggedCeil = frontceilz1; wall.BottomZ1 = frontfloorz1;
wall.BottomZ2 = frontfloorz2;
wall.UnpeggedCeil1 = frontceilz1;
wall.UnpeggedCeil2 = frontceilz2;
wall.Texpart = side_t::mid; wall.Texpart = side_t::mid;
wall.Polyportal = polyportal; wall.Polyportal = polyportal;
wall.Render(worldToClip, clipPlane, cull); wall.Render(worldToClip, clipPlane, cull);
@ -125,9 +128,12 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const PolyClipPlan
if ((topceilz1 > topfloorz1 || topceilz2 > topfloorz2) && line->sidedef && !bothSkyCeiling) if ((topceilz1 > topfloorz1 || topceilz2 > topfloorz2) && line->sidedef && !bothSkyCeiling)
{ {
wall.SetCoords(line->v1->fPos(), line->v2->fPos(), topceilz1, topfloorz1, topceilz2, topfloorz2); wall.SetCoords(line->v1->fPos(), line->v2->fPos(), topceilz1, topfloorz1, topceilz2, topfloorz2);
wall.TopZ = topceilz1; wall.TopZ1 = topceilz1;
wall.BottomZ = topfloorz1; wall.TopZ2 = topceilz2;
wall.UnpeggedCeil = topceilz1; wall.BottomZ1 = topfloorz1;
wall.BottomZ2 = topfloorz2;
wall.UnpeggedCeil1 = topceilz1;
wall.UnpeggedCeil2 = topceilz2;
wall.Texpart = side_t::top; wall.Texpart = side_t::top;
wall.Render(worldToClip, clipPlane, cull); wall.Render(worldToClip, clipPlane, cull);
} }
@ -135,9 +141,12 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const PolyClipPlan
if ((bottomfloorz1 < bottomceilz1 || bottomfloorz2 < bottomceilz2) && line->sidedef && !bothSkyFloor) if ((bottomfloorz1 < bottomceilz1 || bottomfloorz2 < bottomceilz2) && line->sidedef && !bothSkyFloor)
{ {
wall.SetCoords(line->v1->fPos(), line->v2->fPos(), bottomceilz1, bottomfloorz1, bottomceilz2, bottomfloorz2); wall.SetCoords(line->v1->fPos(), line->v2->fPos(), bottomceilz1, bottomfloorz1, bottomceilz2, bottomfloorz2);
wall.TopZ = bottomceilz1; wall.TopZ1 = bottomceilz1;
wall.BottomZ = bottomfloorz2; wall.TopZ2 = bottomceilz2;
wall.UnpeggedCeil = topceilz1; wall.BottomZ1 = bottomfloorz1;
wall.BottomZ2 = bottomfloorz2;
wall.UnpeggedCeil1 = topceilz1;
wall.UnpeggedCeil2 = topceilz2;
wall.Texpart = side_t::bottom; wall.Texpart = side_t::bottom;
wall.Render(worldToClip, clipPlane, cull); wall.Render(worldToClip, clipPlane, cull);
} }
@ -145,9 +154,12 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const PolyClipPlan
if (line->sidedef) if (line->sidedef)
{ {
wall.SetCoords(line->v1->fPos(), line->v2->fPos(), middleceilz1, middlefloorz1, middleceilz2, middlefloorz2); wall.SetCoords(line->v1->fPos(), line->v2->fPos(), middleceilz1, middlefloorz1, middleceilz2, middlefloorz2);
wall.TopZ = middleceilz1; wall.TopZ1 = middleceilz1;
wall.BottomZ = middlefloorz1; wall.TopZ2 = middleceilz2;
wall.UnpeggedCeil = topceilz1; wall.BottomZ1 = middlefloorz1;
wall.BottomZ2 = middlefloorz2;
wall.UnpeggedCeil1 = topceilz1;
wall.UnpeggedCeil2 = topceilz2;
wall.Texpart = side_t::mid; wall.Texpart = side_t::mid;
wall.Masked = true; wall.Masked = true;
@ -181,9 +193,12 @@ void RenderPolyWall::Render3DFloorLine(const TriMatrix &worldToClip, const PolyC
wall.SubsectorDepth = subsectorDepth; wall.SubsectorDepth = subsectorDepth;
wall.StencilValue = stencilValue; wall.StencilValue = stencilValue;
wall.SetCoords(line->v1->fPos(), line->v2->fPos(), frontceilz1, frontfloorz1, frontceilz2, frontfloorz2); wall.SetCoords(line->v1->fPos(), line->v2->fPos(), frontceilz1, frontfloorz1, frontceilz2, frontfloorz2);
wall.TopZ = frontceilz1; wall.TopZ1 = frontceilz1;
wall.BottomZ = frontfloorz1; wall.TopZ2 = frontceilz2;
wall.UnpeggedCeil = frontceilz1; wall.BottomZ1 = frontfloorz1;
wall.BottomZ2 = frontfloorz2;
wall.UnpeggedCeil1 = frontceilz1;
wall.UnpeggedCeil2 = frontceilz2;
wall.Texpart = side_t::mid; wall.Texpart = side_t::mid;
wall.Render(worldToClip, clipPlane, cull); wall.Render(worldToClip, clipPlane, cull);
} }
@ -229,15 +244,17 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const PolyClipPlane &c
if (tex) if (tex)
{ {
PolyWallTextureCoords texcoords(tex, LineSeg, Line, Side, Texpart, TopZ, BottomZ, UnpeggedCeil); PolyWallTextureCoordsU texcoordsU(tex, LineSeg, Line, Side, Texpart);
vertices[0].u = (float)texcoords.u1; PolyWallTextureCoordsV texcoordsVLeft(tex, Line, Side, Texpart, TopZ1, BottomZ1, UnpeggedCeil1);
vertices[0].v = (float)texcoords.v1; PolyWallTextureCoordsV texcoordsVRght(tex, Line, Side, Texpart, TopZ2, BottomZ2, UnpeggedCeil2);
vertices[1].u = (float)texcoords.u2; vertices[0].u = (float)texcoordsU.u1;
vertices[1].v = (float)texcoords.v1; vertices[0].v = (float)texcoordsVLeft.v1;
vertices[2].u = (float)texcoords.u2; vertices[1].u = (float)texcoordsU.u2;
vertices[2].v = (float)texcoords.v2; vertices[1].v = (float)texcoordsVRght.v1;
vertices[3].u = (float)texcoords.u1; vertices[2].u = (float)texcoordsU.u2;
vertices[3].v = (float)texcoords.v2; vertices[2].v = (float)texcoordsVRght.v2;
vertices[3].u = (float)texcoordsU.u1;
vertices[3].v = (float)texcoordsVLeft.v2;
} }
// Masked walls clamp to the 0-1 range (no texture repeat) // Masked walls clamp to the 0-1 range (no texture repeat)
@ -356,13 +373,7 @@ int RenderPolyWall::GetLightLevel()
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
PolyWallTextureCoords::PolyWallTextureCoords(FTexture *tex, const seg_t *lineseg, const line_t *line, const side_t *side, side_t::ETexpart texpart, double topz, double bottomz, double unpeggedceil) PolyWallTextureCoordsU::PolyWallTextureCoordsU(FTexture *tex, const seg_t *lineseg, const line_t *line, const side_t *side, side_t::ETexpart texpart)
{
CalcU(tex, lineseg, line, side, texpart);
CalcV(tex, line, side, texpart, topz, bottomz, unpeggedceil);
}
void PolyWallTextureCoords::CalcU(FTexture *tex, const seg_t *lineseg, const line_t *line, const side_t *side, side_t::ETexpart texpart)
{ {
double lineLength = side->TexelLength; double lineLength = side->TexelLength;
double lineStart = 0.0; double lineStart = 0.0;
@ -384,7 +395,9 @@ void PolyWallTextureCoords::CalcU(FTexture *tex, const seg_t *lineseg, const lin
u2 /= texWidth; u2 /= texWidth;
} }
void PolyWallTextureCoords::CalcV(FTexture *tex, const line_t *line, const side_t *side, side_t::ETexpart texpart, double topz, double bottomz, double unpeggedceil) /////////////////////////////////////////////////////////////////////////////
PolyWallTextureCoordsV::PolyWallTextureCoordsV(FTexture *tex, const line_t *line, const side_t *side, side_t::ETexpart texpart, double topz, double bottomz, double unpeggedceil)
{ {
double vscale = side->GetTextureYScale(texpart) * tex->Scale.Y; double vscale = side->GetTextureYScale(texpart) * tex->Scale.Y;
@ -411,7 +424,7 @@ void PolyWallTextureCoords::CalcV(FTexture *tex, const line_t *line, const side_
v2 /= texHeight; v2 /= texHeight;
} }
void PolyWallTextureCoords::CalcVTopPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double vscale, double yoffset) void PolyWallTextureCoordsV::CalcVTopPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double vscale, double yoffset)
{ {
bool pegged = (line->flags & ML_DONTPEGTOP) == 0; bool pegged = (line->flags & ML_DONTPEGTOP) == 0;
if (pegged) // bottom to top if (pegged) // bottom to top
@ -434,7 +447,7 @@ void PolyWallTextureCoords::CalcVTopPart(FTexture *tex, const line_t *line, cons
} }
} }
void PolyWallTextureCoords::CalcVMidPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double vscale, double yoffset) void PolyWallTextureCoordsV::CalcVMidPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double vscale, double yoffset)
{ {
bool pegged = (line->flags & ML_DONTPEGBOTTOM) == 0; bool pegged = (line->flags & ML_DONTPEGBOTTOM) == 0;
if (pegged) // top to bottom if (pegged) // top to bottom
@ -450,7 +463,7 @@ void PolyWallTextureCoords::CalcVMidPart(FTexture *tex, const line_t *line, cons
} }
} }
void PolyWallTextureCoords::CalcVBottomPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double unpeggedceil, double vscale, double yoffset) void PolyWallTextureCoordsV::CalcVBottomPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double unpeggedceil, double vscale, double yoffset)
{ {
bool pegged = (line->flags & ML_DONTPEGBOTTOM) == 0; bool pegged = (line->flags & ML_DONTPEGBOTTOM) == 0;
if (pegged) // top to bottom if (pegged) // top to bottom

View file

@ -48,9 +48,12 @@ public:
const line_t *Line = nullptr; const line_t *Line = nullptr;
const side_t *Side = nullptr; const side_t *Side = nullptr;
side_t::ETexpart Texpart = side_t::mid; side_t::ETexpart Texpart = side_t::mid;
double TopZ = 0.0; double TopZ1 = 0.0;
double BottomZ = 0.0; double TopZ2 = 0.0;
double UnpeggedCeil = 0.0; double BottomZ1 = 0.0;
double BottomZ2 = 0.0;
double UnpeggedCeil1 = 0.0;
double UnpeggedCeil2 = 0.0;
FSWColormap *Colormap = nullptr; FSWColormap *Colormap = nullptr;
bool Masked = false; bool Masked = false;
uint32_t SubsectorDepth = 0; uint32_t SubsectorDepth = 0;
@ -63,18 +66,22 @@ private:
int GetLightLevel(); int GetLightLevel();
}; };
// Texture coordinates for a wall class PolyWallTextureCoordsU
class PolyWallTextureCoords
{ {
public: public:
PolyWallTextureCoords(FTexture *tex, const seg_t *lineseg, const line_t *line, const side_t *side, side_t::ETexpart texpart, double topz, double bottomz, double unpeggedceil); PolyWallTextureCoordsU(FTexture *tex, const seg_t *lineseg, const line_t *line, const side_t *side, side_t::ETexpart texpart);
double u1, u2; double u1, u2;
};
class PolyWallTextureCoordsV
{
public:
PolyWallTextureCoordsV(FTexture *tex, const line_t *line, const side_t *side, side_t::ETexpart texpart, double topz, double bottomz, double unpeggedceil);
double v1, v2; double v1, v2;
private: private:
void CalcU(FTexture *tex, const seg_t *lineseg, const line_t *line, const side_t *side, side_t::ETexpart texpart);
void CalcV(FTexture *tex, const line_t *line, const side_t *side, side_t::ETexpart texpart, double topz, double bottomz, double unpeggedceil);
void CalcVTopPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double vscale, double yoffset); void CalcVTopPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double vscale, double yoffset);
void CalcVMidPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double vscale, double yoffset); void CalcVMidPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double vscale, double yoffset);
void CalcVBottomPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double unpeggedceil, double vscale, double yoffset); void CalcVBottomPart(FTexture *tex, const line_t *line, const side_t *side, double topz, double bottomz, double unpeggedceil, double vscale, double yoffset);