From ccc5c259ad83d14be9358f9b76fd4272b70aa89c Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 26 Feb 2024 16:15:14 +0100 Subject: [PATCH] Grab the light list from the surfaces in the shader --- src/common/rendering/vulkan/vk_levelmesh.cpp | 2 ++ src/common/rendering/vulkan/vk_levelmesh.h | 6 +++++- src/common/rendering/vulkan/vk_lightmapper.cpp | 2 -- src/common/rendering/vulkan/vk_lightmapper.h | 10 +++++----- .../shaders/lightmap/binding_lightmapper.glsl | 16 ++++++++++------ .../static/shaders/lightmap/frag_raytrace.glsl | 4 ++-- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/common/rendering/vulkan/vk_levelmesh.cpp b/src/common/rendering/vulkan/vk_levelmesh.cpp index c79fcf338..afe76f5ad 100644 --- a/src/common/rendering/vulkan/vk_levelmesh.cpp +++ b/src/common/rendering/vulkan/vk_levelmesh.cpp @@ -595,6 +595,8 @@ void VkLevelMeshUploader::UploadSurfaces() { info.TextureIndex = 0; } + info.LightStart = surface->LightList.Pos; + info.LightEnd = surface->LightList.Pos + surface->LightList.Count; *(surfaces++) = info; } diff --git a/src/common/rendering/vulkan/vk_levelmesh.h b/src/common/rendering/vulkan/vk_levelmesh.h index 84e2302ca..745637419 100644 --- a/src/common/rendering/vulkan/vk_levelmesh.h +++ b/src/common/rendering/vulkan/vk_levelmesh.h @@ -34,7 +34,11 @@ struct SurfaceInfo uint32_t PortalIndex; int32_t TextureIndex; float Alpha; - float Padding; + float Padding0; + uint32_t LightStart; + uint32_t LightEnd; + uint32_t Padding1; + uint32_t Padding2; }; struct PortalInfo diff --git a/src/common/rendering/vulkan/vk_lightmapper.cpp b/src/common/rendering/vulkan/vk_lightmapper.cpp index 068bec389..a67bda89b 100644 --- a/src/common/rendering/vulkan/vk_lightmapper.cpp +++ b/src/common/rendering/vulkan/vk_lightmapper.cpp @@ -195,8 +195,6 @@ void VkLightmapper::Render() { LevelMeshSurface* surface = mesh->GetSurface(surfaceIndex); pc.SurfaceIndex = surfaceIndex; - pc.LightStart = surface->LightList.Pos; - pc.LightEnd = surface->LightList.Pos + surface->LightList.Count; VkDrawIndexedIndirectCommand cmd; cmd.indexCount = surface->MeshLocation.NumElements; diff --git a/src/common/rendering/vulkan/vk_lightmapper.h b/src/common/rendering/vulkan/vk_lightmapper.h index 4be81c65c..cf87c391c 100644 --- a/src/common/rendering/vulkan/vk_lightmapper.h +++ b/src/common/rendering/vulkan/vk_lightmapper.h @@ -20,16 +20,16 @@ struct Uniforms struct LightmapRaytracePC { - uint32_t LightStart; - uint32_t LightEnd; int32_t SurfaceIndex; - int32_t PushPadding1; + int32_t Padding0; + int32_t Padding1; + int32_t Padding2; FVector3 WorldToLocal; float TextureSize; FVector3 ProjLocalToU; - float PushPadding2; + float Padding3; FVector3 ProjLocalToV; - float PushPadding3; + float Padding4; float TileX; float TileY; float TileWidth; diff --git a/wadsrc/static/shaders/lightmap/binding_lightmapper.glsl b/wadsrc/static/shaders/lightmap/binding_lightmapper.glsl index 866134122..bd57caa4f 100644 --- a/wadsrc/static/shaders/lightmap/binding_lightmapper.glsl +++ b/wadsrc/static/shaders/lightmap/binding_lightmapper.glsl @@ -14,7 +14,11 @@ struct SurfaceInfo uint PortalIndex; int TextureIndex; float Alpha; - float Padding; + float Padding0; + uint LightStart; + uint LightEnd; + uint Padding1; + uint Padding2; }; struct PortalInfo @@ -46,16 +50,16 @@ layout(set = 0, binding = 5) buffer PortalBuffer { PortalInfo portals[]; }; struct LightmapRaytracePC { - uint LightStart; - uint LightEnd; int SurfaceIndex; - int PushPadding1; + int Padding0; + int Padding1; + int Padding2; vec3 WorldToLocal; float TextureSize; vec3 ProjLocalToU; - float PushPadding2; + float Padding3; vec3 ProjLocalToV; - float PushPadding3; + float Padding4; float TileX; float TileY; float TileWidth; diff --git a/wadsrc/static/shaders/lightmap/frag_raytrace.glsl b/wadsrc/static/shaders/lightmap/frag_raytrace.glsl index 344b79fb0..0250ab273 100644 --- a/wadsrc/static/shaders/lightmap/frag_raytrace.glsl +++ b/wadsrc/static/shaders/lightmap/frag_raytrace.glsl @@ -15,9 +15,9 @@ layout(location = 0) out vec4 fragcolor; void main() { - uint LightStart = constants[InstanceIndex].LightStart; - uint LightEnd = constants[InstanceIndex].LightEnd; int SurfaceIndex = constants[InstanceIndex].SurfaceIndex; + uint LightStart = surfaces[SurfaceIndex].LightStart; + uint LightEnd = surfaces[SurfaceIndex].LightEnd; vec3 normal = surfaces[SurfaceIndex].Normal; vec3 origin = worldpos + normal * 0.01;