- initial sky fixes.

This commit is contained in:
Christoph Oelckers 2021-03-22 16:02:52 +01:00
parent e884a418f8
commit 096ce5e025
7 changed files with 109 additions and 74 deletions

View file

@ -63,13 +63,6 @@
#include "v_video.h" #include "v_video.h"
#include "hwrenderer/data/buffers.h" #include "hwrenderer/data/buffers.h"
// 57 world units roughly represent one sky texel for the glTranslate call.
enum
{
skyoffsetfactor = 57
};
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// Shamelessly lifted from Doomsday (written by Jaakko Keränen) // Shamelessly lifted from Doomsday (written by Jaakko Keränen)
@ -369,7 +362,7 @@ void FSkyVertexBuffer::SetupMatrices(FGameTexture *tex, float x_offset, float y_
else else
{ {
modelMatrix.translate(0.f, (-40 + texskyoffset) * skyoffsetfactor, 0.f); modelMatrix.translate(0.f, (-40 + texskyoffset) * skyoffsetfactor, 0.f);
modelMatrix.scale(1.f, 1.2f * 1.17f, 1.f); modelMatrix.scale(1.f, 0.8f * 1.17f, 1.f);
} }
textureMatrix.loadIdentity(); textureMatrix.loadIdentity();
textureMatrix.scale(mirror ? -xscale : xscale, yscale, 1.f); textureMatrix.scale(mirror ? -xscale : xscale, yscale, 1.f);
@ -393,21 +386,19 @@ void FSkyVertexBuffer::RenderRow(FRenderState& state, EDrawType prim, int row, b
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FSkyVertexBuffer::RenderDome(FRenderState& state, FGameTexture* tex, float x_offset, float y_offset, bool mirror, int mode, bool tiled) void FSkyVertexBuffer::RenderDome(FRenderState& state, FGameTexture* tex, int mode)
{ {
if (tex) if (tex)
{ {
state.SetMaterial(tex, UF_Texture, 0, CLAMP_NONE, 0, -1); state.SetMaterial(tex, UF_Texture, 0, CLAMP_NONE, 0, -1);
state.EnableModelMatrix(true); state.EnableModelMatrix(true);
state.EnableTextureMatrix(true); state.EnableTextureMatrix(true);
SetupMatrices(tex, x_offset, y_offset, mirror, mode, state.mModelMatrix, state.mTextureMatrix, tiled);
} }
int rc = mRows + 1; int rc = mRows + 1;
// The caps only get drawn for the main layer but not for the overlay. // The caps only get drawn for the main layer but not for the overlay.
if (mode == FSkyVertexBuffer::SKYMODE_MAINLAYER && tex != NULL) if (mode == FSkyVertexBuffer::SKYMODE_MAINLAYER && tex != nullptr)
{ {
auto& col = R_GetSkyCapColor(tex); auto& col = R_GetSkyCapColor(tex);
state.SetObjectColor(col.first); state.SetObjectColor(col.first);
@ -430,6 +421,22 @@ void FSkyVertexBuffer::RenderDome(FRenderState& state, FGameTexture* tex, float
} }
//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------
void FSkyVertexBuffer::RenderDome(FRenderState& state, FGameTexture* tex, float x_offset, float y_offset, bool mirror, int mode, bool tiled, float xscale, float yscale)
{
if (tex)
{
SetupMatrices(tex, x_offset, y_offset, mirror, mode, state.mModelMatrix, state.mTextureMatrix, tiled, xscale, yscale);
}
RenderDome(state, tex, mode);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// //

View file

@ -11,6 +11,12 @@ class IVertexBuffer;
struct HWSkyPortal; struct HWSkyPortal;
struct HWDrawInfo; struct HWDrawInfo;
// 57 world units roughly represent one sky texel for the glTranslate call.
enum
{
skyoffsetfactor = 57
};
struct FSkyVertex struct FSkyVertex
{ {
float x, y, z, u, v; float x, y, z, u, v;
@ -84,7 +90,8 @@ public:
} }
void RenderRow(FRenderState& state, EDrawType prim, int row, bool apply = true); void RenderRow(FRenderState& state, EDrawType prim, int row, bool apply = true);
void RenderDome(FRenderState& state, FGameTexture* tex, float x_offset, float y_offset, bool mirror, int mode, bool tiled); void RenderDome(FRenderState& state, FGameTexture* tex, int mode);
void RenderDome(FRenderState& state, FGameTexture* tex, float x_offset, float y_offset, bool mirror, int mode, bool tiled, float xscale = 0, float yscale = 0);
void RenderBox(FRenderState& state, FSkyBox* tex, float x_offset, bool sky2, float stretch, const FVector3& skyrotatevector, const FVector3& skyrotatevector2); void RenderBox(FRenderState& state, FSkyBox* tex, float x_offset, bool sky2, float stretch, const FVector3& skyrotatevector, const FVector3& skyrotatevector2);
}; };

View file

@ -120,9 +120,23 @@ void BunchDrawer::DeleteBunch(int index)
bool BunchDrawer::CheckClip(walltype* wal) bool BunchDrawer::CheckClip(walltype* wal)
{ {
#ifdef _DEBUG
if (wal - wall == 843 || wal - wall == 847)
{
int a = 0;
}
#endif
auto pt2 = &wall[wal->point2]; auto pt2 = &wall[wal->point2];
sectortype* backsector = &sector[wal->nextsector]; sectortype* backsector = &sector[wal->nextsector];
sectortype* frontsector = &sector[wall[wal->nextwall].nextsector]; sectortype* frontsector = &sector[wall[wal->nextwall].nextsector];
// if one plane is sky on both sides, the line must not clip.
if (frontsector->ceilingstat & backsector->ceilingstat & CSTAT_SECTOR_SKY) return false;
if (frontsector->floorstat & backsector->floorstat & CSTAT_SECTOR_SKY) return false;
float bs_floorheight1; float bs_floorheight1;
float bs_floorheight2; float bs_floorheight2;
float bs_ceilingheight1; float bs_ceilingheight1;
@ -145,22 +159,18 @@ bool BunchDrawer::CheckClip(walltype* wal)
if (bs_ceilingheight1 <= fs_floorheight1 && bs_ceilingheight2 <= fs_floorheight2) if (bs_ceilingheight1 <= fs_floorheight1 && bs_ceilingheight2 <= fs_floorheight2)
{ {
// backsector's ceiling is below frontsector's floor. // backsector's ceiling is below frontsector's floor.
if (frontsector->ceilingstat & backsector->ceilingstat & CSTAT_SECTOR_SKY) return false;
return true; return true;
} }
if (fs_ceilingheight1 <= bs_floorheight1 && fs_ceilingheight2 <= bs_floorheight2) if (fs_ceilingheight1 <= bs_floorheight1 && fs_ceilingheight2 <= bs_floorheight2)
{ {
// backsector's floor is above frontsector's ceiling // backsector's floor is above frontsector's ceiling
if (frontsector->floorstat & backsector->floorstat & CSTAT_SECTOR_SKY) return false;
return true; return true;
} }
if (bs_ceilingheight1 <= bs_floorheight1 && bs_ceilingheight2 <= bs_floorheight2) if (bs_ceilingheight1 <= bs_floorheight1 && bs_ceilingheight2 <= bs_floorheight2)
{ {
// backsector is closed // backsector is closed
if (frontsector->ceilingstat & backsector->ceilingstat & CSTAT_SECTOR_SKY) return false;
if (frontsector->floorstat & backsector->floorstat & CSTAT_SECTOR_SKY) return false;
return true; return true;
} }

View file

@ -177,12 +177,6 @@ public:
spritetype* teleport; // SW's teleport-views spritetype* teleport; // SW's teleport-views
}; };
// these are not the same as ytop and ybottom!!!
float zceil[2];
float zfloor[2];
unsigned int vertindex; unsigned int vertindex;
unsigned int vertcount; unsigned int vertcount;
@ -202,9 +196,9 @@ public:
void SkyPlane(HWDrawInfo *di, sectortype *sector, int plane, bool allowmirror); void SkyPlane(HWDrawInfo *di, sectortype *sector, int plane, bool allowmirror);
void SkyLine(HWDrawInfo *di, sectortype *sec, walltype *line); void SkyLine(HWDrawInfo *di, sectortype *sec, walltype *line);
void SkyNormal(HWDrawInfo* di, sectortype* fs, FVector2& v1, FVector2& v2); void SkyNormal(HWDrawInfo* di, sectortype* fs, FVector2& v1, FVector2& v2, float fch1, float fch2, float ffh1, float ffh2);
void SkyTop(HWDrawInfo* di, walltype* seg, sectortype* fs, sectortype* bs, FVector2& v1, FVector2& v2); void SkyTop(HWDrawInfo* di, walltype* seg, sectortype* fs, sectortype* bs, FVector2& v1, FVector2& v2, float fch1, float fch2);
void SkyBottom(HWDrawInfo* di, walltype* seg, sectortype* fs, sectortype* bs, FVector2& v1, FVector2& v2); void SkyBottom(HWDrawInfo* di, walltype* seg, sectortype* fs, sectortype* bs, FVector2& v1, FVector2& v2, float ffh1, float ffh2);
bool DoHorizon(HWDrawInfo *di, walltype * seg,sectortype * fs, DVector2& v1, DVector2& v2); bool DoHorizon(HWDrawInfo *di, walltype * seg,sectortype * fs, DVector2& v1, DVector2& v2);

View file

@ -63,7 +63,7 @@ void initSkyInfo(HWDrawInfo *di, HWSkyInfo* sky, sectortype* sector, int plane,
// dapyscale is not relvant for a sky dome. // dapyscale is not relvant for a sky dome.
sky->y_scale = FixedToFloat(daptileyscale); sky->y_scale = FixedToFloat(daptileyscale);
sky->y_offset = FixedToFloat(dapyoffs) + ypanning * (float)ti * (1.f / 256.f); sky->y_offset = dapyoffs*2 + (ypanning * ti / 64.f);
sky->x_offset = xpanning / (1 << (realskybits - dapskybits)); sky->x_offset = xpanning / (1 << (realskybits - dapskybits));
sky->fadecolor = FadeColor; sky->fadecolor = FadeColor;
sky->shade = 0;// clamp(plane == plane_ceiling ? sector->ceilingshade : sector->floorshade, 0, numshades - 1); sky->shade = 0;// clamp(plane == plane_ceiling ? sector->ceilingshade : sector->floorshade, 0, numshades - 1);
@ -113,17 +113,23 @@ void HWWall::SkyPlane(HWDrawInfo *di, sectortype *sector, int plane, bool allowr
// //
//========================================================================== //==========================================================================
void HWWall::SkyNormal(HWDrawInfo* di, sectortype* fs, FVector2& v1, FVector2& v2) void HWWall::SkyNormal(HWDrawInfo* di, sectortype* fs, FVector2& v1, FVector2& v2, float fch1, float fch2, float ffh1, float ffh2)
{ {
ztop[0] = ztop[1] = 32768.0f; if (fs->ceilingstat & CSTAT_SECTOR_SKY)
zbottom[0] = zceil[0]; {
zbottom[1] = zceil[1]; ztop[0] = ztop[1] = 32768.0f;
SkyPlane(di, fs, plane_ceiling, true); zbottom[0] = fch1;
zbottom[1] = fch2;
SkyPlane(di, fs, plane_ceiling, true);
}
ztop[0] = zfloor[0]; if (fs->floorstat & CSTAT_SECTOR_SKY)
ztop[1] = zfloor[1]; {
zbottom[0] = zbottom[1] = -32768.0f; ztop[0] = ffh1;
SkyPlane(di, fs, plane_floor, true); ztop[1] = ffh2;
zbottom[0] = zbottom[1] = -32768.0f;
SkyPlane(di, fs, plane_floor, true);
}
} }
//========================================================================== //==========================================================================
@ -132,7 +138,7 @@ void HWWall::SkyNormal(HWDrawInfo* di, sectortype* fs, FVector2& v1, FVector2& v
// //
//========================================================================== //==========================================================================
void HWWall::SkyTop(HWDrawInfo *di, walltype * seg,sectortype * fs,sectortype * bs, FVector2& v1, FVector2& v2) void HWWall::SkyTop(HWDrawInfo *di, walltype * seg,sectortype * fs,sectortype * bs, FVector2& v1, FVector2& v2, float fch1, float fch2)
{ {
if (fs->portalflags == PORTAL_SECTOR_CEILING || fs->portalflags == PORTAL_SECTOR_CEILING_REFLECT) if (fs->portalflags == PORTAL_SECTOR_CEILING || fs->portalflags == PORTAL_SECTOR_CEILING_REFLECT)
{ {
@ -155,30 +161,26 @@ void HWWall::SkyTop(HWDrawInfo *di, walltype * seg,sectortype * fs,sectortype *
return; return;
} }
} }
// stacked sectors
ztop[0] = ztop[1] = 32768.0f;
PlanesAtPoint(fs, v1.X*16.f, v1.Y*-16.f, &zbottom[0], nullptr);
PlanesAtPoint(fs, v2.X * 16.f, v2.Y * -16.f, &zbottom[1], nullptr);
} }
else if (fs->ceilingstat & CSTAT_SECTOR_SKY) else if (fs->ceilingstat & CSTAT_SECTOR_SKY)
{ {
float c1, c2, f1, f2;
PlanesAtPoint(bs, v1.X * 16.f, v1.Y * -16.f, &c1, &f1);
PlanesAtPoint(bs, v2.X * 16.f, v2.Y * -16.f, &c2, &f2);
if (bs->ceilingstat & CSTAT_SECTOR_SKY) if (bs->ceilingstat & CSTAT_SECTOR_SKY)
{ {
float c1, c2, f1, f2;
PlanesAtPoint(bs, v1.X * 16.f, v1.Y * -16.f, &c1, &f1);
PlanesAtPoint(bs, v2.X * 16.f, v2.Y * -16.f, &c2, &f2);
// if the back sector is closed the sky must be drawn! // if the back sector is closed the sky must be drawn!
if (c1 > f1 || c2 > f2) return; if (c1 > f1 || c2 > f2) return;
} }
ztop[0]=ztop[1]=32768.0f; flags |= HWF_SKYHACK; // mid textures on such lines need special treatment!
zbottom[0] = c1;
zbottom[1] = c2;
flags|=HWF_SKYHACK; // mid textures on such lines need special treatment!
} }
else return;
ztop[0] = ztop[1] = 32768.0f;
zbottom[0] = fch1;
zbottom[1] = fch2;
SkyPlane(di, fs, plane_ceiling, true); SkyPlane(di, fs, plane_ceiling, true);
} }
@ -189,7 +191,7 @@ void HWWall::SkyTop(HWDrawInfo *di, walltype * seg,sectortype * fs,sectortype *
// //
//========================================================================== //==========================================================================
void HWWall::SkyBottom(HWDrawInfo *di, walltype * seg,sectortype * fs,sectortype * bs, FVector2& v1, FVector2& v2) void HWWall::SkyBottom(HWDrawInfo *di, walltype * seg,sectortype * fs,sectortype * bs, FVector2& v1, FVector2& v2, float ffh1, float ffh2)
{ {
if (fs->portalflags == PORTAL_SECTOR_FLOOR || fs->portalflags == PORTAL_SECTOR_FLOOR_REFLECT) if (fs->portalflags == PORTAL_SECTOR_FLOOR || fs->portalflags == PORTAL_SECTOR_FLOOR_REFLECT)
{ {
@ -213,29 +215,25 @@ void HWWall::SkyBottom(HWDrawInfo *di, walltype * seg,sectortype * fs,sectortype
} }
} }
// stacked sectors // stacked sectors
zbottom[0] = zbottom[1] = -32768.0f;
PlanesAtPoint(fs, v1.X * 16.f, v1.Y * -16.f, nullptr, &ztop[0]);
PlanesAtPoint(fs, v2.X * 16.f, v2.Y * -16.f, nullptr, &ztop[0]);
} }
else if (fs->ceilingstat & CSTAT_SECTOR_SKY) else if (fs->floorstat & CSTAT_SECTOR_SKY)
{ {
float c1, c2, f1, f2; float c1, c2, f1, f2;
PlanesAtPoint(bs, v1.X * 16.f, v1.Y * -16.f, &c1, &f1); PlanesAtPoint(bs, v1.X * 16.f, v1.Y * -16.f, &c1, &f1);
PlanesAtPoint(bs, v2.X * 16.f, v2.Y * -16.f, &c2, &f2); PlanesAtPoint(bs, v2.X * 16.f, v2.Y * -16.f, &c2, &f2);
if (bs->ceilingstat & CSTAT_SECTOR_SKY) if (bs->floorstat & CSTAT_SECTOR_SKY)
{ {
// if the back sector is closed the sky must be drawn! // if the back sector is closed the sky must be drawn!
if (c1 > f1 || c2 > f2) return; if (c1 > f1 || c2 > f2) return;
} }
zbottom[0] = zbottom[1] = -32768.0f;
zbottom[0] = f1;
zbottom[1] = f2;
flags |= HWF_SKYHACK; // mid textures on such lines need special treatment! flags |= HWF_SKYHACK; // mid textures on such lines need special treatment!
} }
else return;
zbottom[0] = zbottom[1] = -32768.0f;
ztop[0] = ffh1;
ztop[1] = ffh2;
SkyPlane(di, fs, plane_floor, true); SkyPlane(di, fs, plane_floor, true);
} }

View file

@ -26,6 +26,7 @@
#include "hw_renderstate.h" #include "hw_renderstate.h"
#include "skyboxtexture.h" #include "skyboxtexture.h"
CVAR(Float, skyoffsettest, 0, 0)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// //
@ -51,6 +52,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
di->SetupView(state, 0, 0, 0, !!(mState->MirrorFlag & 1), !!(mState->PlaneMirrorFlag & 1)); di->SetupView(state, 0, 0, 0, !!(mState->MirrorFlag & 1), !!(mState->PlaneMirrorFlag & 1));
state.SetVertexBuffer(vertexBuffer); state.SetVertexBuffer(vertexBuffer);
state.SetTextureMode(TM_OPAQUE);
auto skybox = origin->texture ? dynamic_cast<FSkyBox*>(origin->texture->GetTexture()) : nullptr; auto skybox = origin->texture ? dynamic_cast<FSkyBox*>(origin->texture->GetTexture()) : nullptr;
if (skybox) if (skybox)
{ {
@ -58,10 +60,23 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
} }
else else
{ {
state.SetTextureMode(TM_OPAQUE); auto tex = origin->texture;
vertexBuffer->RenderDome(state, origin->texture, origin->x_offset, origin->y_offset, false, FSkyVertexBuffer::SKYMODE_MAINLAYER, false); float texw = tex->GetDisplayWidth();
state.SetTextureMode(TM_NORMAL); float texh = tex->GetDisplayHeight();
auto& modelMatrix = state.mModelMatrix;
auto& textureMatrix = state.mTextureMatrix;
auto texskyoffset = tex->GetSkyOffset() + origin->y_offset + skyoffsettest;
modelMatrix.loadIdentity();
modelMatrix.rotate(-180.0f + origin->x_offset, 0.f, 1.f, 0.f);
modelMatrix.translate(0.f, (-40 + texskyoffset) * skyoffsetfactor, 0.f);
//modelMatrix.scale(1.f, 0.8f * 1.17f, 1.f);
textureMatrix.loadIdentity();
textureMatrix.scale(-1.f, 0.5, 1.f);
textureMatrix.translate(1.f, 0/*origin->y_offset / texh*/, 1.f);
vertexBuffer->RenderDome(state, origin->texture, FSkyVertexBuffer::SKYMODE_MAINLAYER);
} }
state.SetTextureMode(TM_NORMAL);
if (origin->fadecolor & 0xffffff) if (origin->fadecolor & 0xffffff)
{ {
PalEntry FadeColor = origin->fadecolor; PalEntry FadeColor = origin->fadecolor;

View file

@ -880,9 +880,9 @@ void HWWall::DoMidTexture(HWDrawInfo* di, walltype* wal,
// //
// //
//========================================================================== //==========================================================================
void HWWall::Process(HWDrawInfo *di, walltype *wal, sectortype* frontsector, sectortype* backsector) void HWWall::Process(HWDrawInfo* di, walltype* wal, sectortype* frontsector, sectortype* backsector)
{ {
auto backwall = wal->nextwall >= 0 && wal->nextwall < numwalls? &wall[wal->nextwall] : nullptr; auto backwall = wal->nextwall >= 0 && wal->nextwall < numwalls ? &wall[wal->nextwall] : nullptr;
auto p2wall = &wall[wal->point2]; auto p2wall = &wall[wal->point2];
float fch1; float fch1;
@ -896,8 +896,9 @@ void HWWall::Process(HWDrawInfo *di, walltype *wal, sectortype* frontsector, sec
PlanesAtPoint(frontsector, wal->x, wal->y, &fch1, &ffh1); PlanesAtPoint(frontsector, wal->x, wal->y, &fch1, &ffh1);
PlanesAtPoint(frontsector, p2wall->x, p2wall->y, &fch2, &ffh2); PlanesAtPoint(frontsector, p2wall->x, p2wall->y, &fch2, &ffh2);
#ifdef _DEBUG #ifdef _DEBUG
if (wal - wall == 7591) if (wal - wall == 843)
{ {
int a = 0; int a = 0;
} }
@ -950,10 +951,10 @@ void HWWall::Process(HWDrawInfo *di, walltype *wal, sectortype* frontsector, sec
else if (seg->portalflags == PORTAL_WALL_TO_SPRITE) ptype = PORTALTYPE_LINETOSPRITE; else if (seg->portalflags == PORTAL_WALL_TO_SPRITE) ptype = PORTALTYPE_LINETOSPRITE;
if (ptype != -1) if (ptype != -1)
{ {
ztop[0] = zceil[0]; ztop[0] = fch1;
ztop[1] = zceil[1]; ztop[1] = fch2;
zbottom[0] = zfloor[0]; zbottom[0] = ffh1;
zbottom[1] = zfloor[1]; zbottom[1] = ffh2;
PutPortal(di, ptype, -1); PutPortal(di, ptype, -1);
return; return;
} }
@ -963,7 +964,7 @@ void HWWall::Process(HWDrawInfo *di, walltype *wal, sectortype* frontsector, sec
if (!backsector || !backwall) if (!backsector || !backwall)
{ {
// sector's sky // sector's sky
SkyNormal(di, frontsector, v1, v2); SkyNormal(di, frontsector, v1, v2, fch1, fch2, ffh1, ffh2);
// normal texture // normal texture
@ -987,8 +988,11 @@ void HWWall::Process(HWDrawInfo *di, walltype *wal, sectortype* frontsector, sec
float zalign = 0.f; float zalign = 0.f;
SkyTop(di, wal, frontsector, backsector, v1, v2); if (fch1 > ffh1 || fch2 > ffh2)
SkyBottom(di, wal, frontsector, backsector, v1, v2); {
SkyTop(di, wal, frontsector, backsector, v1, v2, fch1, fch2);
SkyBottom(di, wal, frontsector, backsector, v1, v2, ffh1, ffh2);
}
// upper texture // upper texture
if (!(frontsector->ceilingstat & backsector->ceilingstat & CSTAT_SECTOR_SKY)) if (!(frontsector->ceilingstat & backsector->ceilingstat & CSTAT_SECTOR_SKY))