light: very early q2 support. half of the faces seem to be saved without lightmaps for some reason

This commit is contained in:
Eric Wasylishen 2017-10-03 00:33:14 -06:00
parent b52c495574
commit dff71edfe9
5 changed files with 40 additions and 21 deletions

View File

@ -2285,6 +2285,8 @@ LoadBSPFile(char *filename, bspdata_t *bspdata)
lumps = q1header->lumps;
}
bspdata->loadversion = version;
/* check the file version */
logprint("BSP is version %s\n", BSPVersionString(version));
if (!BSPVersionSupported(version))

View File

@ -742,6 +742,7 @@ typedef struct {
typedef struct {
int32_t version;
int32_t loadversion;
int hullcount;
struct {

View File

@ -78,6 +78,6 @@ vec_t GetLightValue(const globalconfig_t &cfg, const light_t *entity, vec_t dist
std::map<int, qvec3f> GetDirectLighting(const globalconfig_t &cfg, raystream_t *rs, const vec3_t origin, const vec3_t normal);
void SetupDirt(globalconfig_t &cfg);
float DirtAtPoint(const globalconfig_t &cfg, raystream_t *rs, const vec3_t point, const vec3_t normal, const modelinfo_t *selfshadow);
void LightFace(const mbsp_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const globalconfig_t &cfg);
void LightFace(bspdata_t *bspdata, bsp2_dface_t *face, facesup_t *facesup, const globalconfig_t &cfg);
#endif /* __LIGHT_LTFACE_H__ */

View File

@ -223,8 +223,9 @@ const modelinfo_t *ModelInfoForFace(const mbsp_t *bsp, int facenum)
static void *
LightThread(void *arg)
{
const mbsp_t *bsp = (const mbsp_t *)arg;
bspdata_t *bspdata = (bspdata_t *)arg;
mbsp_t *bsp = &bspdata->data.mbsp;
#ifdef HAVE_EMBREE
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
// _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
@ -246,24 +247,24 @@ LightThread(void *arg)
}
if (!faces_sup)
LightFace(bsp, f, nullptr, cfg_static);
LightFace(bspdata, f, nullptr, cfg_static);
else if (scaledonly)
{
f->lightofs = -1;
f->styles[0] = 255;
LightFace(bsp, f, faces_sup + facenum, cfg_static);
LightFace(bspdata, f, faces_sup + facenum, cfg_static);
}
else if (faces_sup[facenum].lmscale == face_modelinfo->lightmapscale)
{
LightFace(bsp, f, nullptr, cfg_static);
LightFace(bspdata, f, nullptr, cfg_static);
faces_sup[facenum].lightofs = f->lightofs;
for (int i = 0; i < MAXLIGHTMAPS; i++)
faces_sup[facenum].styles[i] = f->styles[i];
}
else
{
LightFace(bsp, f, nullptr, cfg_static);
LightFace(bsp, f, faces_sup + facenum, cfg_static);
LightFace(bspdata, f, nullptr, cfg_static);
LightFace(bspdata, f, faces_sup + facenum, cfg_static);
}
}
@ -425,7 +426,7 @@ LightWorld(bspdata_t *bspdata, qboolean forcedscale)
info.bsp = bsp;
RunThreadsOn(0, info.all_batches.size(), LightBatchThread, &info);
#else
RunThreadsOn(0, bsp->numfaces, LightThread, bsp);
RunThreadsOn(0, bsp->numfaces, LightThread, bspdata);
#endif
logprint("Lighting Completed.\n\n");

View File

@ -2585,9 +2585,11 @@ BoxBlurImage(const std::vector<qvec4f> &input, int w, int h, int radius)
}
static void
WriteLightmaps(const mbsp_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const lightsurf_t *lightsurf,
WriteLightmaps(bspdata_t *bspdata, bsp2_dface_t *face, facesup_t *facesup, const lightsurf_t *lightsurf,
const lightmapdict_t *lightmaps)
{
mbsp_t *bsp = &bspdata->data.mbsp;
// intermediate collection for sorting lightmaps
std::vector<std::pair<float, const lightmap_t *>> sortable;
@ -2654,6 +2656,11 @@ WriteLightmaps(const mbsp_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const
return;
int size = (lightsurf->texsize[0] + 1) * (lightsurf->texsize[1] + 1);
// q2 support
if (bspdata->loadversion == Q2_BSPVERSION)
size *= 3;
byte *out, *lit, *lux;
GetFileSpace(&out, &lit, &lux, size * numstyles);
if (facesup) {
@ -2702,15 +2709,21 @@ WriteLightmaps(const mbsp_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const
*lit++ = color[1];
*lit++ = color[2];
/* Average the color to get the value to write to the
.bsp lightmap. this avoids issues with some engines
that require the lit and internal lightmap to have the same
intensity. (MarkV, some QW engines)
*/
vec_t light = LightSample_Brightness(color);
if (light < 0) light = 0;
if (light > 255) light = 255;
*out++ = light;
if (bspdata->loadversion == Q2_BSPVERSION) {
*out++ = color[0];
*out++ = color[1];
*out++ = color[2];
} else {
/* Average the color to get the value to write to the
.bsp lightmap. this avoids issues with some engines
that require the lit and internal lightmap to have the same
intensity. (MarkV, some QW engines)
*/
vec_t light = LightSample_Brightness(color);
if (light < 0) light = 0;
if (light > 255) light = 255;
*out++ = light;
}
if (lux) {
vec3_t temp;
@ -2756,8 +2769,10 @@ static void LightFaceShutdown(lightsurf_t *lightsurf)
* ============
*/
void
LightFace(const mbsp_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const globalconfig_t &cfg)
LightFace(bspdata_t *bspdata, bsp2_dface_t *face, facesup_t *facesup, const globalconfig_t &cfg)
{
mbsp_t *bsp = &bspdata->data.mbsp;
/* Find the correct model offset */
const modelinfo_t *modelinfo = ModelInfoForFace(bsp, Face_GetNum(bsp, face));
if (modelinfo == nullptr) {
@ -2889,7 +2904,7 @@ LightFace(const mbsp_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const globa
/* Apply gamma, rangescale, and clamp */
LightFace_ScaleAndClamp(lightsurf, lightmaps);
WriteLightmaps(bsp, face, facesup, lightsurf, lightmaps);
WriteLightmaps(bspdata, face, facesup, lightsurf, lightmaps);
LightFaceShutdown(lightsurf);
}