diff --git a/src/gl/data/gl_data.cpp b/src/gl/data/gl_data.cpp index 42fc6e96d6..ca3e25ab97 100644 --- a/src/gl/data/gl_data.cpp +++ b/src/gl/data/gl_data.cpp @@ -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(); } //========================================================================== diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index 7e39fd9f8c..fae65d9806 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -763,26 +763,50 @@ 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(reinterpret_cast(&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) { - TArray list; - FString texname = ExtractFileBase(name, false); - TexMan.ListTextures(texname, list); - auto bmtex = TexMan.FindTexture(name, FTexture::TEX_Any, FTextureManager::TEXMAN_TryAny); - for (auto texid : list) + if (strstr(name, searchpath.path) == name) { - bmtex->bMasked = false; - TexMan[texid]->gl_info.Brightmap = bmtex; + TArray list; + FString texname = ExtractFileBase(name, false); + TexMan.ListTextures(texname, list); + auto bmtex = TexMan.FindTexture(name, FTexture::TEX_Any, FTextureManager::TEXMAN_TryAny); + for (auto texid : list) + { + bmtex->bMasked = false; + searchpath.SetTexture(TexMan[texid], bmtex); + } } } }