light: very early q2 support. half of the faces seem to be saved without lightmaps for some reason
This commit is contained in:
parent
b52c495574
commit
dff71edfe9
|
|
@ -2285,6 +2285,8 @@ LoadBSPFile(char *filename, bspdata_t *bspdata)
|
||||||
lumps = q1header->lumps;
|
lumps = q1header->lumps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bspdata->loadversion = version;
|
||||||
|
|
||||||
/* check the file version */
|
/* check the file version */
|
||||||
logprint("BSP is version %s\n", BSPVersionString(version));
|
logprint("BSP is version %s\n", BSPVersionString(version));
|
||||||
if (!BSPVersionSupported(version))
|
if (!BSPVersionSupported(version))
|
||||||
|
|
|
||||||
|
|
@ -742,6 +742,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t version;
|
int32_t version;
|
||||||
|
int32_t loadversion;
|
||||||
int hullcount;
|
int hullcount;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
|
||||||
|
|
@ -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);
|
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);
|
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);
|
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__ */
|
#endif /* __LIGHT_LTFACE_H__ */
|
||||||
|
|
|
||||||
|
|
@ -223,8 +223,9 @@ const modelinfo_t *ModelInfoForFace(const mbsp_t *bsp, int facenum)
|
||||||
static void *
|
static void *
|
||||||
LightThread(void *arg)
|
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
|
#ifdef HAVE_EMBREE
|
||||||
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
|
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
|
||||||
// _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
|
// _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
|
||||||
|
|
@ -246,24 +247,24 @@ LightThread(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!faces_sup)
|
if (!faces_sup)
|
||||||
LightFace(bsp, f, nullptr, cfg_static);
|
LightFace(bspdata, f, nullptr, cfg_static);
|
||||||
else if (scaledonly)
|
else if (scaledonly)
|
||||||
{
|
{
|
||||||
f->lightofs = -1;
|
f->lightofs = -1;
|
||||||
f->styles[0] = 255;
|
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)
|
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;
|
faces_sup[facenum].lightofs = f->lightofs;
|
||||||
for (int i = 0; i < MAXLIGHTMAPS; i++)
|
for (int i = 0; i < MAXLIGHTMAPS; i++)
|
||||||
faces_sup[facenum].styles[i] = f->styles[i];
|
faces_sup[facenum].styles[i] = f->styles[i];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LightFace(bsp, f, nullptr, cfg_static);
|
LightFace(bspdata, f, nullptr, cfg_static);
|
||||||
LightFace(bsp, f, faces_sup + facenum, cfg_static);
|
LightFace(bspdata, f, faces_sup + facenum, cfg_static);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -425,7 +426,7 @@ LightWorld(bspdata_t *bspdata, qboolean forcedscale)
|
||||||
info.bsp = bsp;
|
info.bsp = bsp;
|
||||||
RunThreadsOn(0, info.all_batches.size(), LightBatchThread, &info);
|
RunThreadsOn(0, info.all_batches.size(), LightBatchThread, &info);
|
||||||
#else
|
#else
|
||||||
RunThreadsOn(0, bsp->numfaces, LightThread, bsp);
|
RunThreadsOn(0, bsp->numfaces, LightThread, bspdata);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
logprint("Lighting Completed.\n\n");
|
logprint("Lighting Completed.\n\n");
|
||||||
|
|
|
||||||
|
|
@ -2585,9 +2585,11 @@ BoxBlurImage(const std::vector<qvec4f> &input, int w, int h, int radius)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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)
|
const lightmapdict_t *lightmaps)
|
||||||
{
|
{
|
||||||
|
mbsp_t *bsp = &bspdata->data.mbsp;
|
||||||
|
|
||||||
// intermediate collection for sorting lightmaps
|
// intermediate collection for sorting lightmaps
|
||||||
std::vector<std::pair<float, const lightmap_t *>> sortable;
|
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;
|
return;
|
||||||
|
|
||||||
int size = (lightsurf->texsize[0] + 1) * (lightsurf->texsize[1] + 1);
|
int size = (lightsurf->texsize[0] + 1) * (lightsurf->texsize[1] + 1);
|
||||||
|
|
||||||
|
// q2 support
|
||||||
|
if (bspdata->loadversion == Q2_BSPVERSION)
|
||||||
|
size *= 3;
|
||||||
|
|
||||||
byte *out, *lit, *lux;
|
byte *out, *lit, *lux;
|
||||||
GetFileSpace(&out, &lit, &lux, size * numstyles);
|
GetFileSpace(&out, &lit, &lux, size * numstyles);
|
||||||
if (facesup) {
|
if (facesup) {
|
||||||
|
|
@ -2702,15 +2709,21 @@ WriteLightmaps(const mbsp_t *bsp, bsp2_dface_t *face, facesup_t *facesup, const
|
||||||
*lit++ = color[1];
|
*lit++ = color[1];
|
||||||
*lit++ = color[2];
|
*lit++ = color[2];
|
||||||
|
|
||||||
/* Average the color to get the value to write to the
|
if (bspdata->loadversion == Q2_BSPVERSION) {
|
||||||
.bsp lightmap. this avoids issues with some engines
|
*out++ = color[0];
|
||||||
that require the lit and internal lightmap to have the same
|
*out++ = color[1];
|
||||||
intensity. (MarkV, some QW engines)
|
*out++ = color[2];
|
||||||
*/
|
} else {
|
||||||
vec_t light = LightSample_Brightness(color);
|
/* Average the color to get the value to write to the
|
||||||
if (light < 0) light = 0;
|
.bsp lightmap. this avoids issues with some engines
|
||||||
if (light > 255) light = 255;
|
that require the lit and internal lightmap to have the same
|
||||||
*out++ = light;
|
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) {
|
if (lux) {
|
||||||
vec3_t temp;
|
vec3_t temp;
|
||||||
|
|
@ -2756,8 +2769,10 @@ static void LightFaceShutdown(lightsurf_t *lightsurf)
|
||||||
* ============
|
* ============
|
||||||
*/
|
*/
|
||||||
void
|
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 */
|
/* Find the correct model offset */
|
||||||
const modelinfo_t *modelinfo = ModelInfoForFace(bsp, Face_GetNum(bsp, face));
|
const modelinfo_t *modelinfo = ModelInfoForFace(bsp, Face_GetNum(bsp, face));
|
||||||
if (modelinfo == nullptr) {
|
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 */
|
/* Apply gamma, rangescale, and clamp */
|
||||||
LightFace_ScaleAndClamp(lightsurf, lightmaps);
|
LightFace_ScaleAndClamp(lightsurf, lightmaps);
|
||||||
|
|
||||||
WriteLightmaps(bsp, face, facesup, lightsurf, lightmaps);
|
WriteLightmaps(bspdata, face, facesup, lightsurf, lightmaps);
|
||||||
|
|
||||||
LightFaceShutdown(lightsurf);
|
LightFaceShutdown(lightsurf);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue