Skip to content

Commit

Permalink
- made some changes so that material definitions can properly check a…
Browse files Browse the repository at this point in the history
…utomatic 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.
  • Loading branch information
coelckers committed Jun 3, 2020
1 parent 8ab6575 commit 720853c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/common/engine/startupinfo.h
Expand Up @@ -12,7 +12,7 @@ struct FStartupInfo
int Type;
int LoadLights = -1;
int LoadBrightmaps = -1;
int modern = -1;
int modern = 0;
enum
{
DefaultStartup,
Expand Down
2 changes: 2 additions & 0 deletions src/common/textures/gametexture.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -177,6 +178,7 @@ void FGameTexture::AddAutoMaterials()
}
}
}
flags |= GTexf_AutoMaterialsAdded;
}

//===========================================================================
Expand Down
2 changes: 2 additions & 0 deletions src/common/textures/gametexture.h
Expand Up @@ -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<FTexture> Base;
Expand Down
2 changes: 1 addition & 1 deletion src/common/textures/hw_material.cpp
Expand Up @@ -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)
{
Expand Down
12 changes: 6 additions & 6 deletions src/r_data/gldefs.cpp
Expand Up @@ -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('}'))
Expand All @@ -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"))
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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('{');
Expand Down

0 comments on commit 720853c

Please sign in to comment.