- made some changes so that material definitions can properly check automatic layers when determining their material type.

Most importantly this means that any texture with a custom material definition needs to load its automatic layers before applying the definition.
This commit is contained in:
Christoph Oelckers 2020-06-03 21:15:32 +02:00
parent 8ab6575bd1
commit 720853cff8
5 changed files with 12 additions and 8 deletions

View file

@ -12,7 +12,7 @@ struct FStartupInfo
int Type; int Type;
int LoadLights = -1; int LoadLights = -1;
int LoadBrightmaps = -1; int LoadBrightmaps = -1;
int modern = -1; int modern = 0;
enum enum
{ {
DefaultStartup, DefaultStartup,

View file

@ -149,6 +149,7 @@ void FGameTexture::AddAutoMaterials()
{ "materials/ao/", &FGameTexture::AmbientOcclusion } { "materials/ao/", &FGameTexture::AmbientOcclusion }
}; };
if (flags & GTexf_AutoMaterialsAdded) return; // do this only once
bool fullname = !!(flags & GTexf_FullNameTexture); bool fullname = !!(flags & GTexf_FullNameTexture);
FString searchname = GetName(); FString searchname = GetName();
@ -177,6 +178,7 @@ void FGameTexture::AddAutoMaterials()
} }
} }
} }
flags |= GTexf_AutoMaterialsAdded;
} }
//=========================================================================== //===========================================================================

View file

@ -57,12 +57,14 @@ enum EGameTexFlags
GTexf_RenderFullbright = 32, // always draw fullbright GTexf_RenderFullbright = 32, // always draw fullbright
GTexf_DisableFullbrightSprites = 64, // This texture will not be displayed as fullbright sprite GTexf_DisableFullbrightSprites = 64, // This texture will not be displayed as fullbright sprite
GTexf_BrightmapChecked = 128, // Check for a colormap-based brightmap was already done. GTexf_BrightmapChecked = 128, // Check for a colormap-based brightmap was already done.
GTexf_AutoMaterialsAdded = 256, // AddAutoMaterials has been called on this texture.
}; };
// Refactoring helper to allow piece by piece adjustment of the API // Refactoring helper to allow piece by piece adjustment of the API
class FGameTexture class FGameTexture
{ {
friend class FMaterial; friend class FMaterial;
friend class GLDefsParser; // this needs access to set up the texture properly
// Material layers. These are shared so reference counting is used. // Material layers. These are shared so reference counting is used.
RefCountedPtr<FTexture> Base; RefCountedPtr<FTexture> Base;

View file

@ -114,7 +114,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
if (index >= FIRST_USER_SHADER) if (index >= FIRST_USER_SHADER)
{ {
const UserShaderDesc &usershader = usershaders[index - 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 if (usershader.shaderType == mShaderIndex) // Only apply user shader if it matches the expected material
{ {
for (auto &texture : tx->CustomShaderTextures) for (auto &texture : tx->CustomShaderTextures)
{ {

View file

@ -1216,6 +1216,7 @@ class GLDefsParser
{ {
sc.ScriptMessage("Material definition refers nonexistent texture '%s'\n", sc.String); sc.ScriptMessage("Material definition refers nonexistent texture '%s'\n", sc.String);
} }
else tex->AddAutoMaterials(); // We need these before setting up the texture.
sc.MustGetToken('{'); sc.MustGetToken('{');
while (!sc.CheckToken('}')) while (!sc.CheckToken('}'))
@ -1242,14 +1243,12 @@ class GLDefsParser
else if (sc.Compare("glossiness")) else if (sc.Compare("glossiness"))
{ {
sc.MustGetFloat(); sc.MustGetFloat();
if (tex) mlay.Glossiness = (float)sc.Float;
mlay.Glossiness = (float)sc.Float;
} }
else if (sc.Compare("specularlevel")) else if (sc.Compare("specularlevel"))
{ {
sc.MustGetFloat(); sc.MustGetFloat();
if (tex) mlay.SpecularLevel = (float)sc.Float;
mlay.SpecularLevel = (float)sc.Float;
} }
else if (sc.Compare("speed")) else if (sc.Compare("speed"))
{ {
@ -1367,12 +1366,12 @@ class GLDefsParser
if (usershader.shader.IsNotEmpty()) if (usershader.shader.IsNotEmpty())
{ {
int firstUserTexture; int firstUserTexture;
if (mlay.Normal && mlay.Specular) if ((mlay.Normal || tex->Normal.get()) && (mlay.Specular || tex->Specular.get()))
{ {
usershader.shaderType = SHADER_Specular; usershader.shaderType = SHADER_Specular;
firstUserTexture = 7; firstUserTexture = 7;
} }
else if (mlay.Normal && mlay.Metallic && mlay.Roughness && mlay.AmbientOcclusion) else if ((mlay.Normal || tex->Normal.get()) && (mlay.Metallic || tex->Metallic.get()) && (mlay.Roughness || tex->Roughness.get()) && (mlay.AmbientOcclusion || tex->AmbientOcclusion.get()))
{ {
usershader.shaderType = SHADER_PBR; usershader.shaderType = SHADER_PBR;
firstUserTexture = 9; firstUserTexture = 9;
@ -1523,6 +1522,7 @@ class GLDefsParser
sc.MustGetString(); sc.MustGetString();
FTextureID no = TexMan.CheckForTexture(sc.String, type); FTextureID no = TexMan.CheckForTexture(sc.String, type);
auto tex = TexMan.GetGameTexture(no); auto tex = TexMan.GetGameTexture(no);
if (tex) tex->AddAutoMaterials();
MaterialLayers mlay = { -1000, -1000 }; MaterialLayers mlay = { -1000, -1000 };
sc.MustGetToken('{'); sc.MustGetToken('{');