- moved the shader properties to FGameTexture.

This commit is contained in:
Christoph Oelckers 2020-04-18 09:41:55 +02:00
parent e60d758287
commit d812801707
3 changed files with 26 additions and 29 deletions

View file

@ -109,9 +109,10 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
mTextureLayers.Push(placeholder->GetTexture());
}
if (imgtex->shaderindex >= FIRST_USER_SHADER)
auto index = tx->GetShaderIndex();
if (index >= FIRST_USER_SHADER)
{
const UserShaderDesc &usershader = usershaders[imgtex->shaderindex - FIRST_USER_SHADER];
const UserShaderDesc &usershader = usershaders[index - FIRST_USER_SHADER];
if (usershader.shaderType == mShaderIndex) // Only apply user shader if it matches the expected material
{
for (auto &texture : tx->CustomShaderTextures)
@ -119,7 +120,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
if (texture == nullptr) continue;
mTextureLayers.Push(texture.get());
}
mShaderIndex = tx->GetShaderIndex();
mShaderIndex = index;
}
}
}

View file

@ -107,8 +107,6 @@ FTexture::FTexture (int lumpnum)
FTexture::~FTexture ()
{
if (areas != nullptr) delete[] areas;
areas = nullptr;
}
//===========================================================================
@ -281,12 +279,12 @@ void FTexture::GetGlowColor(float *data)
//
//===========================================================================
int FTexture::GetAreas(FloatRect** pAreas) const
int FGameTexture::GetAreas(FloatRect** pAreas) const
{
if (shaderindex == SHADER_Default) // texture splitting can only be done if there's no attached effects
{
*pAreas = areas;
return areacount;
*pAreas = Base->areas;
return Base->areacount;
}
else
{
@ -314,8 +312,8 @@ bool FTexture::FindHoles(const unsigned char * buffer, int w, int h)
if (areacount) return false;
areacount = -1; //whatever happens next, it shouldn't be done twice!
// large textures are excluded for performance reasons
if (h>512) return false;
// large textures and non-images are excluded for performance reasons
if (h>512 || !GetImage()) return false;
startdraw = -1;
lendraw = 0;
@ -366,7 +364,7 @@ bool FTexture::FindHoles(const unsigned char * buffer, int w, int h)
if (gapc > 0)
{
FloatRect * rcs = new FloatRect[gapc];
FloatRect* rcs = (FloatRect*)ImageArena.Alloc(gapc * sizeof(FloatRect)); // allocate this on the image arena
for (x = 0; x < gapc; x++)
{

View file

@ -283,12 +283,6 @@ protected:
int GlowHeight = 128;
PalEntry GlowColor = 0;
float Glossiness = 10.f;
float SpecularLevel = 0.1f;
float shaderspeed = 1.f;
int shaderindex = 0;
public:
IHardwareTexture* GetHardwareTexture(int translation, int scaleflags);
@ -307,7 +301,6 @@ public:
bool isCanvas() const { return bHasCanvas; }
int isWarped() const { return bWarped; }
int GetRotations() const { return Rotations; }
float GetShaderSpeed() const { return shaderspeed; }
void SetRotations(int rot) { Rotations = int16_t(rot); }
void SetNoDecals(bool on) { bNoDecals = on; }
@ -324,7 +317,6 @@ public:
bool isFullbright() const { return bFullbright; }
bool FindHoles(const unsigned char * buffer, int w, int h);
int GetSourceLump() const { return SourceLump; }
void SetSpeed(float fac) { shaderspeed = fac; }
bool UseWorldPanning() const { return bWorldPanning; }
void SetWorldPanning(bool on) { bWorldPanning = on; }
@ -548,6 +540,12 @@ class FGameTexture
ISoftwareTexture* SoftwareTexture = nullptr;
FMaterial* Material[4] = { };
// Material properties
float Glossiness = 10.f;
float SpecularLevel = 0.1f;
float shaderspeed = 1.f;
int shaderindex = 0;
public:
FGameTexture(FTexture* wrap, const char *name);
~FGameTexture();
@ -600,8 +598,6 @@ public:
void SetNoDecals(bool on) { Base->bNoDecals = on; }
void SetTranslucent(bool on) { Base->bTranslucent = on; }
void SetUseType(ETextureType type) { UseType = type; }
int GetShaderIndex() const { return Base->shaderindex; }
float GetShaderSpeed() const { return Base->GetShaderSpeed(); }
uint16_t GetRotations() const { return Base->GetRotations(); }
void SetRotations(int index) { Base->SetRotations(index); }
void SetSkyOffset(int ofs) { Base->SetSkyOffset(ofs); }
@ -621,13 +617,15 @@ public:
return Material[num];
}
void SetShaderSpeed(float speed) { Base->shaderspeed = speed; }
void SetShaderIndex(int index) { Base->shaderindex = index; }
int GetShaderIndex() const { return shaderindex; }
float GetShaderSpeed() const { return shaderspeed; }
void SetShaderSpeed(float speed) { shaderspeed = speed; }
void SetShaderIndex(int index) { shaderindex = index; }
void SetShaderLayers(MaterialLayers& lay)
{
// Only update layers that have something defind.
if (lay.Glossiness > -1000) Base->Glossiness = lay.Glossiness;
if (lay.SpecularLevel > -1000) Base->SpecularLevel = lay.SpecularLevel;
if (lay.Glossiness > -1000) Glossiness = lay.Glossiness;
if (lay.SpecularLevel > -1000) SpecularLevel = lay.SpecularLevel;
if (lay.Brightmap) Brightmap = lay.Brightmap->GetTexture();
if (lay.Normal) Normal = lay.Normal->GetTexture();
if (lay.Specular) Specular = lay.Specular->GetTexture();
@ -639,8 +637,8 @@ public:
if (lay.CustomShaderTextures[i]) CustomShaderTextures[i] = lay.CustomShaderTextures[i]->GetTexture();
}
}
float GetGlossiness() const { return Base->Glossiness; }
float GetSpecularLevel() const { return Base->SpecularLevel; }
float GetGlossiness() const { return Glossiness; }
float GetSpecularLevel() const { return SpecularLevel; }
void CopySize(FGameTexture* BaseTexture)
{
@ -693,7 +691,7 @@ public:
}
const SpritePositioningInfo& GetSpritePositioning(int which) { if (spi == nullptr) SetupSpriteData(); return spi[which]; }
int GetAreas(FloatRect** pAreas) const { return Base->GetAreas(pAreas); }
int GetAreas(FloatRect** pAreas) const;
bool GetTranslucency()
{
@ -711,7 +709,7 @@ public:
{
if (GetUseType() == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER;
else if (isHardwareCanvas()) clampmode = CLAMP_CAMTEX;
else if ((isWarped() || Base->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE;
else if ((isWarped() || shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE;
return clampmode;
}
};