Accept LIGHTING_E5BGR9 bspx lumps in case there's no rgb8 lump.

Converts to rgb8 for now, so still only uses ldr lighting.
This commit is contained in:
Shpoike 2018-10-16 20:38:41 +01:00
parent 4d0d324479
commit 68ae3bfee7

View file

@ -523,7 +523,7 @@ static void Q1BSPX_Setup(qmodel_t *mod, char *filebase, unsigned int filelen, lu
i = LittleLong(h->numlumps); i = LittleLong(h->numlumps);
/*verify the header*/ /*verify the header*/
if (!strncmp(h->id, "BSPX", 4) || if (strncmp(h->id, "BSPX", 4) ||
i < 0 || i < 0 ||
offs + sizeof(*h) + sizeof(h->lumps[0])*(i-1) > filelen) offs + sizeof(*h) + sizeof(h->lumps[0])*(i-1) > filelen)
return; return;
@ -928,6 +928,31 @@ void Mod_LoadLighting (lump_t *l)
if (loadmodel->lightdata && bspxsize == l->filelen*3) if (loadmodel->lightdata && bspxsize == l->filelen*3)
Con_DPrintf("bspx lighting loaded\n"); Con_DPrintf("bspx lighting loaded\n");
else else
{
in = Q1BSPX_FindLump("LIGHTING_E5BGR9", &bspxsize);
if (in && bspxsize == l->filelen*4)
{ //we don't really support hdr lighting, but we downgrade it to ldr whenever there's no rgb data.
//FIXME: don't convert this stuff here. upload the data to the gpu with GL_EXT_shared_exponent (core in gl3)
loadmodel->lightdata = (byte *) Hunk_AllocName ( l->filelen*3, litfilename);
out = loadmodel->lightdata;
Con_DPrintf("bspx hdr->ldr lighting loaded\n");
for (i = 0;i < l->filelen;i++, in+=4)
{
static const float rgb9e5tab[32] = { //multipliers for the 9-bit mantissa, according to the biased mantissa
//aka: pow(2, biasedexponent - bias-bits) where bias is 15 and bits is 9
1.0/(1<<24), 1.0/(1<<23), 1.0/(1<<22), 1.0/(1<<21), 1.0/(1<<20), 1.0/(1<<19), 1.0/(1<<18), 1.0/(1<<17),
1.0/(1<<16), 1.0/(1<<15), 1.0/(1<<14), 1.0/(1<<13), 1.0/(1<<12), 1.0/(1<<11), 1.0/(1<<10), 1.0/(1<<9),
1.0/(1<<8), 1.0/(1<<7), 1.0/(1<<6), 1.0/(1<<5), 1.0/(1<<4), 1.0/(1<<3), 1.0/(1<<2), 1.0/(1<<1),
1.0, 1.0*(1<<1), 1.0*(1<<2), 1.0*(1<<3), 1.0*(1<<4), 1.0*(1<<5), 1.0*(1<<6), 1.0*(1<<7),
};
unsigned int e5bgr9 = *(unsigned int*)in;
float e = rgb9e5tab[e5bgr9>>27] * (1<<7); //we're converting to a scale that holds overbrights, so 1->128, its 2->255ish
*out++ = q_min(255, e*((e5bgr9>> 0)&0x1ff)); //red
*out++ = q_min(255, e*((e5bgr9>> 9)&0x1ff)); //green
*out++ = q_min(255, e*((e5bgr9>>18)&0x1ff)); //blue
}
}
else
{ {
loadmodel->lightdata = (byte *) Hunk_AllocName ( l->filelen*3, litfilename); loadmodel->lightdata = (byte *) Hunk_AllocName ( l->filelen*3, litfilename);
in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
@ -941,6 +966,7 @@ void Mod_LoadLighting (lump_t *l)
*out++ = d; *out++ = d;
} }
} }
}
} }