From: havoc Date: Tue, 12 Sep 2006 07:22:40 +0000 (+0000) Subject: changed deluxemapping detection code to deal with odd bsp files produced by q3map2... X-Git-Tag: xonotic-v0.1.0preview~3805 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=30187beda434cb1aa6f89e91e869facb525ac7a1;p=xonotic%2Fdarkplaces.git changed deluxemapping detection code to deal with odd bsp files produced by q3map2 that contain two lightmaps but the second one is completely unused and blank and thus not suitable as a deluxemap, this fixes black (or very dim) surfaces in some small maps when GLSL is enabled git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6584 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/model_brush.c b/model_brush.c index f860198c..960c1c83 100644 --- a/model_brush.c +++ b/model_brush.c @@ -4608,6 +4608,7 @@ static void Mod_Q3BSP_LoadLightmaps(lump_t *l) q3dlightmap_t *in; rtexture_t **out; int i, count; + unsigned char *c; if (!l->filelen) return; @@ -4620,6 +4621,36 @@ static void Mod_Q3BSP_LoadLightmaps(lump_t *l) loadmodel->brushq3.data_lightmaps = out; loadmodel->brushq3.num_lightmaps = count; + // deluxemapped q3bsp files have an even number of lightmaps, and surfaces + // always index even numbered ones (0, 2, 4, ...), the odd numbered + // lightmaps are the deluxemaps (light direction textures), so if we + // encounter any odd numbered lightmaps it is not a deluxemapped bsp, it + // is also not a deluxemapped bsp if it has an odd number of lightmaps or + // less than 2 + loadmodel->brushq3.deluxemapping = true; + loadmodel->brushq3.deluxemapping_modelspace = true; + if (count < 2 || (count & 1)) + loadmodel->brushq3.deluxemapping = false; + + // q3map2 sometimes (or always?) makes a second blank lightmap for no + // reason when only one lightmap is used, which can throw off the + // deluxemapping detection method, so check 2-lightmap bsp's specifically + // to see if the second lightmap is blank, if so it is not deluxemapped. + if (count == 2) + { + c = in[count - 1].rgb; + for (i = 0;i < 128*128*3;i++) + if (c[i]) + break; + if (i == 128*128*3) + { + // all pixels in the unused lightmap were black... + loadmodel->brushq3.deluxemapping = false; + } + } + + // further deluxemapping detection is done in Mod_Q3BSP_LoadFaces + for (i = 0;i < count;i++, in++, out++) *out = R_LoadTexture2D(loadmodel->texturepool, va("lightmap%04i", i), 128, 128, in->rgb, TEXTYPE_RGB, TEXF_FORCELINEAR | TEXF_PRECACHE, NULL); } @@ -4649,15 +4680,8 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l) loadmodel->data_surfaces = out; loadmodel->num_surfaces = count; - // deluxemapped q3bsp files have an even number of lightmaps, and surfaces - // always index even numbered ones (0, 2, 4, ...), the odd numbered - // lightmaps are the deluxemaps (light direction textures), so if we - // encounter any odd numbered lightmaps it is not a deluxemapped bsp, it - // is also not a deluxemapped bsp if it has an odd number of lightmaps or - // less than 2 - loadmodel->brushq3.deluxemapping = true; - loadmodel->brushq3.deluxemapping_modelspace = true; - if (loadmodel->brushq3.num_lightmaps >= 2 && !(loadmodel->brushq3.num_lightmaps & 1)) + // now that we have surfaces to look at, see if any of them index an odd numbered lightmap, if so this is not a deluxemapped bsp file + if (loadmodel->brushq3.deluxemapping) { for (i = 0;i < count;i++) { @@ -4669,8 +4693,6 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l) } } } - else - loadmodel->brushq3.deluxemapping = false; Con_DPrintf("%s is %sdeluxemapped\n", loadmodel->name, loadmodel->brushq3.deluxemapping ? "" : "not "); i = 0;