diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index de0f22e162..cf8392e8bb 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -657,6 +657,7 @@ struct sector_t float GlowHeight; FTextureID Texture; TextureManipulation TextureFx; + uint16_t LightmapSampleDistance; }; @@ -1204,6 +1205,7 @@ struct side_t TextureManipulation TextureFx; PalEntry SpecialColors[2]; PalEntry AdditiveColor; + uint16_t LightmapSampleDistance; void InitFrom(const part &other) @@ -1491,6 +1493,8 @@ struct line_t : public linebase_t int healthgroup; // [ZZ] this is the "destructible object" id int linenum; + uint16_t LightmapSampleDistance[3]; // Used only as storage during map loading. + void setAlpha(double a) { alpha = a; diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index aad91c5e4d..d23f30839c 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -2938,6 +2938,42 @@ void MapLoader::CalcIndices() // //========================================================================== +void MapLoader::InitLevelMesh() +{ + Level->SunColor = FVector3(1.f, 1.f, 1.f); + Level->SunDirection = FVector3(0.45f, 0.3f, 0.9f); + + // Propagate sample distance where it isn't yet set + for (auto& line : Level->lines) + { + if (line.LightmapSampleDistance[0] || line.LightmapSampleDistance[1] || line.LightmapSampleDistance[2]) + { + for (int i = 0; i < 2; ++i) + { + if (auto sidedef = line.sidedef[i]) + { + for (int j = 0; j < 3; ++j) + { + if (!sidedef->textures[j].LightmapSampleDistance) + { + sidedef->textures[j].LightmapSampleDistance = line.LightmapSampleDistance[j]; + } + } + } + } + } + } + + Level->levelMesh = new DoomLevelMesh(*Level); + Level->lightmaps = true; +} + +//========================================================================== +// +// +// +//========================================================================== + void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position) { const int *oldvertextable = nullptr; @@ -3204,12 +3240,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position) SpawnThings(position); - // TODO read from ZDRayInfoThing - Level->SunColor = FVector3(1.f, 1.f, 1.f); - Level->SunDirection = FVector3(0.45f, 0.3f, 0.9f); - - Level->levelMesh = new DoomLevelMesh(*Level); - Level->lightmaps = true; + InitLevelMesh(); for (int i = 0; i < MAXPLAYERS; ++i) { diff --git a/src/maploader/maploader.h b/src/maploader/maploader.h index 79beb6aeea..a151fb3088 100644 --- a/src/maploader/maploader.h +++ b/src/maploader/maploader.h @@ -304,6 +304,8 @@ public: void SetSlopes(); void CopySlopes(); + void InitLevelMesh(); + void LoadLevel(MapData *map, const char *lumpname, int position); MapLoader(FLevelLocals *lev) diff --git a/src/maploader/udmf.cpp b/src/maploader/udmf.cpp index d02ee237e2..2d646bad87 100644 --- a/src/maploader/udmf.cpp +++ b/src/maploader/udmf.cpp @@ -1129,10 +1129,22 @@ public: break; case NAME_lm_sampledist_line: + CHECK_N(Zd | Zdt) + for (int i = 0; i < 3; ++i) + if (!ld->LightmapSampleDistance[i]) + ld->LightmapSampleDistance[i] = CheckInt(key); + break; case NAME_lm_sampledist_top: + CHECK_N(Zd | Zdt) + ld->LightmapSampleDistance[side_t::top] = CheckInt(key); + break; case NAME_lm_sampledist_mid: + CHECK_N(Zd | Zdt) + ld->LightmapSampleDistance[side_t::mid] = CheckInt(key); + break; case NAME_lm_sampledist_bot: CHECK_N(Zd | Zdt) + ld->LightmapSampleDistance[side_t::bottom] = CheckInt(key); break; default: @@ -1477,12 +1489,27 @@ public: sd->Flags |= WALLF_EXTCOLOR; break; + CHECK_N(Zd | Zdt) + break; + case NAME_lm_sampledist_line: + CHECK_N(Zd | Zdt) + for (int i = 0; i < 3; ++i) + if (!sd->textures[i].LightmapSampleDistance) + sd->textures[i].LightmapSampleDistance = CheckInt(key); + break; case NAME_lm_sampledist_top: + CHECK_N(Zd | Zdt) + sd->textures[side_t::top].LightmapSampleDistance = CheckInt(key); + break; case NAME_lm_sampledist_mid: + CHECK_N(Zd | Zdt) + sd->textures[side_t::mid].LightmapSampleDistance = CheckInt(key); + break; case NAME_lm_sampledist_bot: CHECK_N(Zd | Zdt) - break; + sd->textures[side_t::bottom].LightmapSampleDistance = CheckInt(key); + break; default: if (strnicmp("user_", key.GetChars(), 5)) @@ -1992,9 +2019,17 @@ public: sec->health3dgroup = CheckInt(key); break; + CHECK_N(Zd | Zdt) + break; + case NAME_lm_sampledist_floor: + CHECK_N(Zd | Zdt) + sec->planes[sector_t::floor].LightmapSampleDistance = CheckInt(key); + break; + case NAME_lm_sampledist_ceiling: CHECK_N(Zd | Zdt) + sec->planes[sector_t::ceiling].LightmapSampleDistance = CheckInt(key); break; default: diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index cf6c9c17da..7b844773f0 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -287,6 +287,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) surf.Type = ST_MIDDLESIDE; surf.typeIndex = typeIndex; surf.bSky = front->GetTexture(sector_t::floor) == skyflatnum || front->GetTexture(sector_t::ceiling) == skyflatnum; + surf.sampleDimension = side->textures[side_t::mid].LightmapSampleDistance; FVector3 verts[4]; verts[0].X = verts[2].X = v1.X; @@ -334,6 +335,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) surf.typeIndex = typeIndex; surf.ControlSector = xfloor->model; surf.bSky = false; + surf.sampleDimension = side->textures[side_t::mid].LightmapSampleDistance; FVector3 verts[4]; verts[0].X = verts[2].X = v2.X; @@ -394,6 +396,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) surf.Type = ST_LOWERSIDE; surf.typeIndex = typeIndex; surf.bSky = false; + surf.sampleDimension = side->textures[side_t::bottom].LightmapSampleDistance; surf.ControlSector = nullptr; Surfaces.Push(surf); @@ -432,6 +435,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) surf.Type = ST_UPPERSIDE; surf.typeIndex = typeIndex; surf.bSky = bSky; + surf.sampleDimension = side->textures[side_t::top].LightmapSampleDistance; surf.ControlSector = nullptr; Surfaces.Push(surf); @@ -469,6 +473,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side) surf.plane = ToPlane(verts[0], verts[1], verts[2]); surf.Type = ST_MIDDLESIDE; surf.typeIndex = typeIndex; + surf.sampleDimension = side->textures[side_t::mid].LightmapSampleDistance; surf.ControlSector = nullptr; Surfaces.Push(surf); @@ -508,6 +513,7 @@ void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub, surf.Type = ST_FLOOR; surf.typeIndex = typeIndex; + surf.sampleDimension = sector->planes[sector_t::floor].LightmapSampleDistance; surf.ControlSector = is3DFloor ? sector : nullptr; surf.plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, -(float)plane.D); @@ -547,6 +553,7 @@ void DoomLevelMesh::CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub surf.Type = ST_CEILING; surf.typeIndex = typeIndex; + surf.sampleDimension = sector->planes[sector_t::ceiling].LightmapSampleDistance; surf.ControlSector = is3DFloor ? sector : nullptr; surf.plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, -(float)plane.D);