From d8d1742d0a55c27f5900a02dc225d64c4723fb8c Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 19 Jan 2025 15:34:39 +0100 Subject: [PATCH] Add lm_bounce and lm_ao to ZDRayInfo Make vktool ignore the existing lightmap lump Ignore the lightmapper cvars in vktool --- .../rendering/hwrenderer/data/hw_levelmesh.h | 2 ++ src/common/rendering/vulkan/vk_lightmapper.cpp | 18 ++++++++++++------ src/g_levellocals.h | 6 ++++-- src/maploader/maploader.cpp | 6 ++++-- src/maploader/udmf.cpp | 8 ++++++++ src/namedef_custom.h | 2 ++ src/rendering/hwrenderer/doom_levelmesh.cpp | 2 ++ 7 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/common/rendering/hwrenderer/data/hw_levelmesh.h b/src/common/rendering/hwrenderer/data/hw_levelmesh.h index 4859572e7..b66e0b544 100644 --- a/src/common/rendering/hwrenderer/data/hw_levelmesh.h +++ b/src/common/rendering/hwrenderer/data/hw_levelmesh.h @@ -136,6 +136,8 @@ public: FVector3 SunDirection = FVector3(0.0f, 0.0f, -1.0f); FVector3 SunColor = FVector3(0.0f, 0.0f, 0.0f); float SunIntensity = 1.0f; + bool AmbientOcclusion = true; + bool LightBounce = true; TArray Portals; diff --git a/src/common/rendering/vulkan/vk_lightmapper.cpp b/src/common/rendering/vulkan/vk_lightmapper.cpp index 163869a32..824f1b97c 100644 --- a/src/common/rendering/vulkan/vk_lightmapper.cpp +++ b/src/common/rendering/vulkan/vk_lightmapper.cpp @@ -26,9 +26,9 @@ CVAR(Int, lm_max_updates, 128, CVAR_NOSAVE); CVAR(Float, lm_scale, 1.0, CVAR_NOSAVE); CVAR(Bool, lm_sunlight, true, CVAR_ARCHIVE); CVAR(Bool, lm_blur, true, CVAR_ARCHIVE); -CVAR(Bool, lm_ao, false, CVAR_NOSAVE); +CVAR(Bool, lm_ao, true, CVAR_ARCHIVE); CVAR(Bool, lm_softshadows, true, CVAR_ARCHIVE); -CVAR(Bool, lm_bounce, false, CVAR_NOSAVE); +CVAR(Bool, lm_bounce, true, CVAR_ARCHIVE); CVAR(Bool, lm_dynamic, true, CVAR_ARCHIVE); VkLightmapper::VkLightmapper(VulkanRenderDevice* fb) : fb(fb) @@ -592,14 +592,20 @@ void VkLightmapper::CreateShaders() int VkLightmapper::GetRaytracePipelineIndex() { + // When running as the baking tool we don't care about the CVAR or hardware preferences and only want to act on what the map specified. + bool userSoftshadows = RunningAsTool || (lm_softshadows && useRayQuery); + bool userAO = RunningAsTool || (lm_ao && useRayQuery); + bool userSunlight = RunningAsTool || lm_sunlight; + bool userBounce = RunningAsTool || lm_bounce; + int index = 0; - if (lm_softshadows && useRayQuery) + if (userSoftshadows) index |= 1; - if (lm_ao && useRayQuery) + if (mesh->AmbientOcclusion && userAO) index |= 2; - if (lm_sunlight && mesh->SunColor != FVector3(0.0f, 0.0f, 0.0f)) + if (mesh->SunColor != FVector3(0.0f, 0.0f, 0.0f) && userSunlight) index |= 4; - if (lm_bounce) + if (mesh->LightBounce && userBounce) index |= 8; return index; } diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 82191a832..0b2788706 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -475,8 +475,10 @@ public: TArray LightmapTiles; FVector3 SunDirection; FVector3 SunColor; - float SunIntensity; - uint16_t LightmapSampleDistance; + float SunIntensity = false; + uint16_t LightmapSampleDistance = 0; + bool LightBounce = false; + bool AmbientOcclusion = false; // Portal information. FDisplacementTable Displacements; diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index 4f60160b5..0fefa4ca1 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -2964,7 +2964,7 @@ void MapLoader::InitLevelMesh(MapData* map) } } - if (map->Size(ML_LIGHTMAP)) + if (map->Size(ML_LIGHTMAP) && !RunningAsTool) { // Arbitrary ZDRay limit. This will break lightmap lump loading if not enforced. Level->LightmapSampleDistance = std::clamp((int)Level->LightmapSampleDistance, LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MIN, LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MAX); @@ -3025,7 +3025,7 @@ void MapLoader::InitLevelMesh(MapData* map) bool MapLoader::LoadLightmap(MapData* map) { - if (!Level->lightmaps || !map->Size(ML_LIGHTMAP) || ignorelightmaplump) + if (RunningAsTool || !Level->lightmaps || !map->Size(ML_LIGHTMAP) || ignorelightmaplump) return false; FileReader fr; @@ -3205,6 +3205,8 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position) Level->SunIntensity = gameinfo.defaultSunIntensity; Level->LightmapSampleDistance = gameinfo.defaultLightmapSampleDistance; Level->lightmaps = gameinfo.forceEnableLightmaps; + Level->LightBounce = true; + Level->AmbientOcclusion = true; // note: most of this ordering is important ForceNodeBuild = gennodes; diff --git a/src/maploader/udmf.cpp b/src/maploader/udmf.cpp index 9aeee6ce9..6cbbdc13b 100644 --- a/src/maploader/udmf.cpp +++ b/src/maploader/udmf.cpp @@ -844,6 +844,14 @@ public: Level->LightmapSampleDistance = CheckInt(key); break; + case NAME_lm_bounce: + Level->LightBounce = CheckBool(key); + break; + + case NAME_lm_ao: + Level->AmbientOcclusion = CheckBool(key); + break; + default: CHECK_N(Zd | Zdt) if (0 == strnicmp("user_", key.GetChars(), 5)) diff --git a/src/namedef_custom.h b/src/namedef_custom.h index 0410a27e5..097a9d78c 100644 --- a/src/namedef_custom.h +++ b/src/namedef_custom.h @@ -870,6 +870,8 @@ xx(lm_sampledist_ceiling) xx(lm_dynamic) xx(lm_suncolor) xx(lm_sunintensity) +xx(lm_bounce) +xx(lm_ao) // Light keywords xx(light_softshadowradius) diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index db1941d13..85923c88a 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -211,6 +211,8 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals& doomMap) SunDirection = doomMap.SunDirection; SunIntensity = doomMap.SunIntensity; Lightmap.SampleDistance = doomMap.LightmapSampleDistance; + LightBounce = doomMap.LightBounce; + AmbientOcclusion = doomMap.AmbientOcclusion; // HWWall and HWFlat still looks at r_viewpoint when doing calculations, // but we aren't rendering a specific viewpoint when this function gets called