- Implement auto textures for materials

This commit is contained in:
Magnus Norddahl 2018-02-21 23:12:46 +01:00
parent 4e7ca68bd6
commit 05827ffcda
2 changed files with 36 additions and 12 deletions

View file

@ -68,7 +68,7 @@ CUSTOM_CVAR(Bool, gl_notexturefill, false, 0)
void gl_CreateSections();
void AddAutoBrightmaps();
void AddAutoMaterials();
//-----------------------------------------------------------------------------
//
@ -364,7 +364,7 @@ void gl_RecalcVertexHeights(vertex_t * v)
void gl_InitData()
{
AdjustSpriteOffsets();
AddAutoBrightmaps();
AddAutoMaterials();
}
//==========================================================================

View file

@ -763,17 +763,40 @@ void gl_ParseBrightmap(FScanner &sc, int deflump)
//==========================================================================
//
//
// Search auto paths for extra material textures
//
//==========================================================================
void AddAutoBrightmaps()
struct AutoTextureSearchPath
{
const char *path;
ptrdiff_t offset;
void SetTexture(FTexture *material, FTexture *texture) const
{
*reinterpret_cast<FTexture**>(reinterpret_cast<uint8_t*>(&material->gl_info) + offset) = texture;
}
};
static AutoTextureSearchPath autosearchpaths[] =
{
{ "brightmaps/auto/", offsetof(FTexture::MiscGLInfo, Brightmap) },
{ "normalmaps/auto/", offsetof(FTexture::MiscGLInfo, Normal) },
{ "specular/auto/", offsetof(FTexture::MiscGLInfo, Specular) },
{ "metallic/auto/", offsetof(FTexture::MiscGLInfo, Metallic) },
{ "roughness/auto/", offsetof(FTexture::MiscGLInfo, Roughness) },
{ "ao/auto/", offsetof(FTexture::MiscGLInfo, AmbientOcclusion) }
};
void AddAutoMaterials()
{
int num = Wads.GetNumLumps();
for (int i = 0; i < num; i++)
{
const char *name = Wads.GetLumpFullName(i);
if (strstr(name, "brightmaps/auto/") == name)
for (const AutoTextureSearchPath &searchpath : autosearchpaths)
{
if (strstr(name, searchpath.path) == name)
{
TArray<FTextureID> list;
FString texname = ExtractFileBase(name, false);
@ -782,7 +805,8 @@ void AddAutoBrightmaps()
for (auto texid : list)
{
bmtex->bMasked = false;
TexMan[texid]->gl_info.Brightmap = bmtex;
searchpath.SetTexture(TexMan[texid], bmtex);
}
}
}
}