diff --git a/src/common/engine/startupinfo.h b/src/common/engine/startupinfo.h index 9cf9724fd..5054a4507 100644 --- a/src/common/engine/startupinfo.h +++ b/src/common/engine/startupinfo.h @@ -12,7 +12,7 @@ struct FStartupInfo int Type; int LoadLights = -1; int LoadBrightmaps = -1; - int modern = -1; + int modern = 0; enum { DefaultStartup, diff --git a/src/common/textures/gametexture.cpp b/src/common/textures/gametexture.cpp index d47ffb733..e4e1ac6b2 100644 --- a/src/common/textures/gametexture.cpp +++ b/src/common/textures/gametexture.cpp @@ -149,6 +149,7 @@ void FGameTexture::AddAutoMaterials() { "materials/ao/", &FGameTexture::AmbientOcclusion } }; + if (flags & GTexf_AutoMaterialsAdded) return; // do this only once bool fullname = !!(flags & GTexf_FullNameTexture); FString searchname = GetName(); @@ -177,6 +178,7 @@ void FGameTexture::AddAutoMaterials() } } } + flags |= GTexf_AutoMaterialsAdded; } //=========================================================================== diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index 32a2e40be..e6b3461cf 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -57,12 +57,14 @@ enum EGameTexFlags GTexf_RenderFullbright = 32, // always draw fullbright 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_AutoMaterialsAdded = 256, // AddAutoMaterials has been called on this texture. }; // Refactoring helper to allow piece by piece adjustment of the API class FGameTexture { 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. RefCountedPtr Base; diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index af4bc2c60..c4a1ba9d3 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -114,7 +114,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) if (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) { diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index b561000c4..44467244d 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -1216,6 +1216,7 @@ class GLDefsParser { sc.ScriptMessage("Material definition refers nonexistent texture '%s'\n", sc.String); } + else tex->AddAutoMaterials(); // We need these before setting up the texture. sc.MustGetToken('{'); while (!sc.CheckToken('}')) @@ -1242,14 +1243,12 @@ class GLDefsParser else if (sc.Compare("glossiness")) { sc.MustGetFloat(); - if (tex) - mlay.Glossiness = (float)sc.Float; + mlay.Glossiness = (float)sc.Float; } else if (sc.Compare("specularlevel")) { sc.MustGetFloat(); - if (tex) - mlay.SpecularLevel = (float)sc.Float; + mlay.SpecularLevel = (float)sc.Float; } else if (sc.Compare("speed")) { @@ -1367,12 +1366,12 @@ class GLDefsParser if (usershader.shader.IsNotEmpty()) { int firstUserTexture; - if (mlay.Normal && mlay.Specular) + if ((mlay.Normal || tex->Normal.get()) && (mlay.Specular || tex->Specular.get())) { usershader.shaderType = SHADER_Specular; 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; firstUserTexture = 9; @@ -1523,6 +1522,7 @@ class GLDefsParser sc.MustGetString(); FTextureID no = TexMan.CheckForTexture(sc.String, type); auto tex = TexMan.GetGameTexture(no); + if (tex) tex->AddAutoMaterials(); MaterialLayers mlay = { -1000, -1000 }; sc.MustGetToken('{');