- test skyboxes with dynamic_cast and scale them properly.

This commit is contained in:
Christoph Oelckers 2020-04-18 13:13:57 +02:00
parent 217b80b1fb
commit f7dd16ba16
8 changed files with 57 additions and 50 deletions

View file

@ -44,7 +44,6 @@ FSkyBox::FSkyBox(const char *name)
} }
else previous = nullptr; else previous = nullptr;
faces[0]=faces[1]=faces[2]=faces[3]=faces[4]=faces[5] = nullptr; faces[0]=faces[1]=faces[2]=faces[3]=faces[4]=faces[5] = nullptr;
bSkybox = true;
fliptop = false; fliptop = false;
} }

View file

@ -1,3 +1,42 @@
#pragma once #pragma once
#include "textures.h" #include "textures.h"
//-----------------------------------------------------------------------------
//
// Todo: Get rid of this
// The faces can easily be stored in the material layer array
//
//-----------------------------------------------------------------------------
class FSkyBox : public FImageTexture
{
public:
FGameTexture* previous;
FGameTexture* faces[6]; // the faces need to be full materials as they can have all supported effects.
bool fliptop;
FSkyBox(const char* name);
void SetSize();
bool Is3Face() const
{
return faces[5] == nullptr;
}
bool IsFlipped() const
{
return fliptop;
}
FGameTexture* GetSkyFace(int num) const
{
return faces[num];
}
bool GetSkyFlip() const
{
return fliptop;
}
};

View file

@ -94,7 +94,6 @@ FTexture::FTexture (int lumpnum)
bNoRemap0(false), bMasked(true), bAlphaTexture(false), bHasCanvas(false), bNoRemap0(false), bMasked(true), bAlphaTexture(false), bHasCanvas(false),
Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0)
{ {
bSkybox = false;
bNoCompress = false; bNoCompress = false;
bTranslucent = -1; bTranslucent = -1;
} }

View file

@ -258,7 +258,6 @@ protected:
uint8_t bAlphaTexture : 1; // Texture is an alpha channel without color information uint8_t bAlphaTexture : 1; // Texture is an alpha channel without color information
uint8_t bHasCanvas : 1; // Texture is based off FCanvasTexture uint8_t bHasCanvas : 1; // Texture is based off FCanvasTexture
uint8_t bSkybox : 1; // is a cubic skybox
int8_t bTranslucent : 2; int8_t bTranslucent : 2;
uint16_t Rotations; uint16_t Rotations;
@ -447,35 +446,6 @@ enum
}; };
//-----------------------------------------------------------------------------
//
// Todo: Get rid of this
// The faces can easily be stored in the material layer array
//
//-----------------------------------------------------------------------------
class FSkyBox : public FImageTexture
{
public:
FGameTexture* previous;
FGameTexture* faces[6]; // the faces need to be full materials as they can have all supported effects.
bool fliptop;
FSkyBox(const char* name);
void SetSize();
bool Is3Face() const
{
return faces[5] == nullptr;
}
bool IsFlipped() const
{
return fliptop;
}
};
enum EGameTexFlags enum EGameTexFlags
{ {
GTexf_NoDecals = 1, // Decals should not stick to texture GTexf_NoDecals = 1, // Decals should not stick to texture
@ -644,7 +614,6 @@ public:
bool isUserContent() const; bool isUserContent() const;
int CheckRealHeight() { return xs_RoundToInt(Base->CheckRealHeight() / ScaleY); } int CheckRealHeight() { return xs_RoundToInt(Base->CheckRealHeight() / ScaleY); }
bool isSkybox() const { return Base->bSkybox; }
void SetSize(int x, int y) void SetSize(int x, int y)
{ {
TexelWidth = x; TexelWidth = x;
@ -684,13 +653,6 @@ public:
return Base->GetTranslucency(); return Base->GetTranslucency();
} }
// Since these properties will later piggyback on existing members of FGameTexture, the accessors need to be here.
FGameTexture *GetSkyFace(int num)
{
return (isSkybox() ? static_cast<FSkyBox*>(Base.get())->faces[num] : nullptr);
}
bool GetSkyFlip() { return isSkybox() ? static_cast<FSkyBox*>(Base.get())->fliptop : false; }
int GetClampMode(int clampmode) int GetClampMode(int clampmode)
{ {
if (GetUseType() == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; if (GetUseType() == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER;

View file

@ -78,6 +78,7 @@
#include "s_music.h" #include "s_music.h"
#include "animations.h" #include "animations.h"
#include "texturemanager.h" #include "texturemanager.h"
#include "p_lnspec.h"
extern AActor *SpawnMapThing (int index, FMapThing *mthing, int position); extern AActor *SpawnMapThing (int index, FMapThing *mthing, int position);
@ -188,9 +189,13 @@ static void PrecacheLevel(FLevelLocals *Level)
for (i = Level->sides.Size() - 1; i >= 0; i--) for (i = Level->sides.Size() - 1; i >= 0; i--)
{ {
AddToList(hitlist.Data(), Level->sides[i].GetTexture(side_t::top), FTextureManager::HIT_Wall); auto &sd = Level->sides[i];
AddToList(hitlist.Data(), Level->sides[i].GetTexture(side_t::mid), FTextureManager::HIT_Wall); int hitflag = FTextureManager::HIT_Wall;
AddToList(hitlist.Data(), Level->sides[i].GetTexture(side_t::bottom), FTextureManager::HIT_Wall); // Only precache skyboxes when this is actually used as a sky transfer.
if (sd.linedef->sidedef[0] == &sd && sd.linedef->special == Static_Init && sd.linedef->args[1] == Init_TransferSky) hitflag |= FTextureManager::HIT_Sky;
AddToList(hitlist.Data(), sd.GetTexture(side_t::top), hitflag);
AddToList(hitlist.Data(), sd.GetTexture(side_t::mid), FTextureManager::HIT_Wall);
AddToList(hitlist.Data(), sd.GetTexture(side_t::bottom), hitflag);
} }

View file

@ -8,6 +8,7 @@
#include "hw_renderstate.h" #include "hw_renderstate.h"
#include "hw_material.h" #include "hw_material.h"
class FSkyBox;
struct HWSkyInfo struct HWSkyInfo
{ {
@ -358,7 +359,7 @@ struct HWSkyPortal : public HWPortal
friend struct HWEEHorizonPortal; friend struct HWEEHorizonPortal;
void RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, int row, bool apply = true); void RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, int row, bool apply = true);
void RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FGameTexture * gltex, float x_offset, bool sky2); void RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FSkyBox * gltex, float x_offset, bool sky2);
void RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * tex, float x_offset, float y_offset, bool mirror, int mode); void RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * tex, float x_offset, float y_offset, bool mirror, int mode);
protected: protected:

View file

@ -93,12 +93,13 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture *
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FGameTexture * tex, float x_offset, bool sky2) void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FSkyBox * tex, float x_offset, bool sky2)
{ {
int faces; int faces;
state.EnableModelMatrix(true); state.EnableModelMatrix(true);
state.mModelMatrix.loadIdentity(); state.mModelMatrix.loadIdentity();
state.mModelMatrix.scale(1, 1 / di->Level->info->pixelstretch, 1); // Undo the map's vertical scaling as skyboxes are true cubes.
if (!sky2) if (!sky2)
state.mModelMatrix.rotate(-180.0f+x_offset, di->Level->info->skyrotatevector.X, di->Level->info->skyrotatevector.Z, di->Level->info->skyrotatevector.Y); state.mModelMatrix.rotate(-180.0f+x_offset, di->Level->info->skyrotatevector.X, di->Level->info->skyrotatevector.Z, di->Level->info->skyrotatevector.Y);
@ -171,9 +172,10 @@ 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);
if (origin->texture[0] && origin->texture[0]->isSkybox()) auto skybox = origin->texture[0] ? dynamic_cast<FSkyBox*>(origin->texture[0]->GetTexture()) : nullptr;
if (skybox)
{ {
RenderBox(di, state, origin->skytexno1, origin->texture[0], origin->x_offset[0], origin->sky2); RenderBox(di, state, origin->skytexno1, skybox, origin->x_offset[0], origin->sky2);
} }
else else
{ {

View file

@ -101,12 +101,12 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
for (int i = 0; i<TexMan.NumTextures(); i++) for (int i = 0; i<TexMan.NumTextures(); i++)
{ {
// HIT_Wall must be checked for MBF-style sky transfers. // HIT_Wall must be checked for MBF-style sky transfers.
if (texhitlist[i] & (FTextureManager::HIT_Sky | FTextureManager::HIT_Wall)) if (texhitlist[i] & (FTextureManager::HIT_Sky))
{ {
auto tex = TexMan.GameByIndex(i); auto tex = TexMan.GameByIndex(i);
if (tex->isSkybox()) auto sb = dynamic_cast<FSkyBox*>(tex->GetTexture());
if (sb)
{ {
FSkyBox *sb = static_cast<FSkyBox*>(tex->GetTexture());
for (int i = 0; i<6; i++) for (int i = 0; i<6; i++)
{ {
if (sb->faces[i]) if (sb->faces[i])