Skip to content

Commit

Permalink
Add lm_bounce and lm_ao to ZDRayInfo
Browse files Browse the repository at this point in the history
Make vktool ignore the existing lightmap lump
Ignore the lightmapper cvars in vktool
  • Loading branch information
dpjudas committed Jan 19, 2025
1 parent df125c3 commit d8d1742
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/common/rendering/hwrenderer/data/hw_levelmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class LevelMesh
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<LevelMeshPortal> Portals;

Expand Down
18 changes: 12 additions & 6 deletions src/common/rendering/vulkan/vk_lightmapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/g_levellocals.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,10 @@ struct FLevelLocals
TArray<int> 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;
Expand Down
6 changes: 4 additions & 2 deletions src/maploader/maploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/maploader/udmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,14 @@ class UDMFParser : public UDMFParserBase
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))
Expand Down
2 changes: 2 additions & 0 deletions src/namedef_custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/rendering/hwrenderer/doom_levelmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d8d1742

Please sign in to comment.