From c2808809b733d1e9059c129983244d1001f2bce6 Mon Sep 17 00:00:00 2001 From: nashmuhandes Date: Sun, 22 Dec 2024 00:04:10 +0800 Subject: [PATCH] Add customizable sunlight intensity (both to ZDRayInfo and ZScript) --- .../rendering/hwrenderer/data/hw_levelmesh.h | 1 + src/common/rendering/vulkan/vk_levelmesh.cpp | 2 +- src/common/rendering/vulkan/vk_lightmapper.cpp | 2 +- src/g_levellocals.h | 1 + src/gamedata/gi.cpp | 2 ++ src/gamedata/gi.h | 1 + src/maploader/maploader.cpp | 1 + src/maploader/udmf.cpp | 4 ++++ src/namedef_custom.h | 1 + src/p_saveg.cpp | 4 +++- src/rendering/hwrenderer/doom_levelmesh.cpp | 14 ++++++++++++++ wadsrc/static/zscript/doombase.zs | 5 +++++ 12 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/common/rendering/hwrenderer/data/hw_levelmesh.h b/src/common/rendering/hwrenderer/data/hw_levelmesh.h index ab09ee1a6..da26fe2a4 100644 --- a/src/common/rendering/hwrenderer/data/hw_levelmesh.h +++ b/src/common/rendering/hwrenderer/data/hw_levelmesh.h @@ -135,6 +135,7 @@ public: // Map defaults FVector3 SunDirection = FVector3(0.0f, 0.0f, -1.0f); FVector3 SunColor = FVector3(0.0f, 0.0f, 0.0f); + float SunIntensity = 1.0f; TArray Portals; diff --git a/src/common/rendering/vulkan/vk_levelmesh.cpp b/src/common/rendering/vulkan/vk_levelmesh.cpp index 7217f5fb4..5409d717c 100644 --- a/src/common/rendering/vulkan/vk_levelmesh.cpp +++ b/src/common/rendering/vulkan/vk_levelmesh.cpp @@ -547,7 +547,7 @@ void VkLevelMesh::RaytraceScene(const VkRenderPassKey& renderPassKey, VulkanComm pushconstants.ProjY = f; pushconstants.SunDir = FVector3(Mesh->SunDirection.X, Mesh->SunDirection.Z, Mesh->SunDirection.Y); pushconstants.SunColor = Mesh->SunColor; - pushconstants.SunIntensity = 1.0f; + pushconstants.SunIntensity = Mesh->SunIntensity; commands->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, Viewer.PipelineLayout.get(), 0, Viewer.DescriptorSet.get()); commands->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, Viewer.PipelineLayout.get(), 1, fb->GetDescriptorSetManager()->GetBindlessSet()); diff --git a/src/common/rendering/vulkan/vk_lightmapper.cpp b/src/common/rendering/vulkan/vk_lightmapper.cpp index 051c6eb86..88c8c65ac 100644 --- a/src/common/rendering/vulkan/vk_lightmapper.cpp +++ b/src/common/rendering/vulkan/vk_lightmapper.cpp @@ -246,7 +246,7 @@ void VkLightmapper::UploadUniforms() Uniforms values = {}; values.SunDir = SwapYZ(mesh->SunDirection); values.SunColor = mesh->SunColor; - values.SunIntensity = 1.0f; + values.SunIntensity = mesh->SunIntensity; uniforms.Uniforms = (uint8_t*)uniforms.TransferBuffer->Map(0, uniforms.NumStructs * uniforms.StructStride); *reinterpret_cast(uniforms.Uniforms + uniforms.StructStride * uniforms.Index) = values; diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 9ae2997eb..82191a832 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -475,6 +475,7 @@ public: TArray LightmapTiles; FVector3 SunDirection; FVector3 SunColor; + float SunIntensity; uint16_t LightmapSampleDistance; // Portal information. diff --git a/src/gamedata/gi.cpp b/src/gamedata/gi.cpp index 26bb91b44..d68224a2d 100644 --- a/src/gamedata/gi.cpp +++ b/src/gamedata/gi.cpp @@ -82,6 +82,7 @@ DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, mHideParTimes) DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, forceEnableLightmaps) DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, defaultSunColor) DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, defaultSunDirection) +DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, defaultSunIntensity) DEFINE_FIELD_X(GameInfoStruct, gameinfo_t, defaultLightmapSampleDistance) const char *GameNames[17] = @@ -484,6 +485,7 @@ void FMapInfoParser::ParseGameInfo() GAMEINFOKEY_BOOL(forceEnableLightmaps, "forceenablelightmaps") GAMEINFOKEY_THREEDOUBLES(defaultSunColor, "defaultsuncolor") GAMEINFOKEY_THREEDOUBLES(defaultSunDirection, "defaultSunDirection") + GAMEINFOKEY_FLOAT(defaultSunIntensity, "defaultSunIntensity") else { DPrintf(DMSG_ERROR, "Unknown GAMEINFO key \"%s\" found in %s:%i\n", nextKey.GetChars(), sc.ScriptName.GetChars(), sc.Line); diff --git a/src/gamedata/gi.h b/src/gamedata/gi.h index 437cf77e2..ef9cfb585 100644 --- a/src/gamedata/gi.h +++ b/src/gamedata/gi.h @@ -220,6 +220,7 @@ struct gameinfo_t bool forceEnableLightmaps = false; FVector3 defaultSunColor = FVector3(1.f, 1.f, 1.f); FVector3 defaultSunDirection = FVector3(0.45f, 0.3f, 0.9f); + float defaultSunIntensity = 1.f; int defaultLightmapSampleDistance = 8; const char *GetFinalePage(unsigned int num) const; diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index bf7f3be57..4f60160b5 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -3202,6 +3202,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position) // Reset defaults for lightmapping Level->SunColor = gameinfo.defaultSunColor; Level->SunDirection = gameinfo.defaultSunDirection; + Level->SunIntensity = gameinfo.defaultSunIntensity; Level->LightmapSampleDistance = gameinfo.defaultLightmapSampleDistance; Level->lightmaps = gameinfo.forceEnableLightmaps; diff --git a/src/maploader/udmf.cpp b/src/maploader/udmf.cpp index d2a415340..e6cd8b105 100644 --- a/src/maploader/udmf.cpp +++ b/src/maploader/udmf.cpp @@ -824,6 +824,10 @@ public: Level->SunColor = FVector3(float((n >> 16) & 0xFF) / 0xFF, float((n >> 8) & 0xFF) / 0xFF, float(n & 0xFF) / 0xFF); } break; + case NAME_lm_sunintensity: + CHECK_N(Zd | Zdt) + Level->SunIntensity = CheckFloat(key); + break; case NAME_lm_sampledist: CHECK_N(Zd | Zdt) if (CheckInt(key) < LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MIN || CheckInt(key) > LIGHTMAP_GLOBAL_SAMPLE_DISTANCE_MAX) diff --git a/src/namedef_custom.h b/src/namedef_custom.h index 661de6665..32a88a055 100644 --- a/src/namedef_custom.h +++ b/src/namedef_custom.h @@ -868,6 +868,7 @@ xx(lm_sampledist_floor) xx(lm_sampledist_ceiling) xx(lm_dynamic) xx(lm_suncolor) +xx(lm_sunintensity) // Light keywords xx(light_softshadowradius) diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index b975e3398..b409d7bab 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -993,7 +993,8 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload) ("interpolator", interpolator) ("frozenstate", frozenstate) ("suncolor", SunColor) - ("sundirection", SunDirection); + ("sundirection", SunDirection) + ("sunintensity", SunIntensity); // Hub transitions must keep the current total time @@ -1007,6 +1008,7 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload) levelMesh->SunColor = SunColor; levelMesh->SunDirection = SunDirection; + levelMesh->SunIntensity = SunIntensity; } Behaviors.SerializeModuleStates(arc); diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 300d4bf53..aaa634c4d 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -223,6 +223,7 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals& doomMap) SunColor = doomMap.SunColor; // TODO keep only one copy? SunDirection = doomMap.SunDirection; + SunIntensity = doomMap.SunIntensity; Lightmap.SampleDistance = doomMap.LightmapSampleDistance; // HWWall and HWFlat still looks at r_viewpoint when doing calculations, @@ -2300,3 +2301,16 @@ DEFINE_ACTION_FUNCTION(_Lightmap, SetSunColor) return 0; } +DEFINE_ACTION_FUNCTION(_Lightmap, SetSunIntensity) +{ + PARAM_PROLOGUE; + PARAM_FLOAT(i); + + if (level.levelMesh) + { + level.SunIntensity = i; + level.levelMesh->SunIntensity = i; + } + return 0; +} + diff --git a/wadsrc/static/zscript/doombase.zs b/wadsrc/static/zscript/doombase.zs index 2d3d5a132..8a0e42101 100644 --- a/wadsrc/static/zscript/doombase.zs +++ b/wadsrc/static/zscript/doombase.zs @@ -112,6 +112,7 @@ extend struct GameInfoStruct native bool forceEnableLightmaps; native FVector3 defaultSunColor; native FVector3 defaultSunDirection; + native float defaultSunIntensity; native int defaultLightmapSampleDistance; } @@ -827,4 +828,8 @@ struct Lightmap // Can go above 1.0 (call Invalidate()) // Calling this does NOT recalculate the lightmap. native static void SetSunColor(Vector3 color); + + // Multiplier for the sun's intensity (or brightness) + // Calling this does NOT recalculate the lightmap. + native static void SetSunIntensity(double intensity); }; \ No newline at end of file