From 97d96a6bc13813bf129110f19d301ffe1298828d Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Fri, 2 Feb 2024 11:39:40 +0100 Subject: [PATCH] More light culling changes --- res/shaders/LightCulling.slang | 7 ++++--- res/shaders/lib/LightEnv.slang | 14 +++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/res/shaders/LightCulling.slang b/res/shaders/LightCulling.slang index 58c3899..d56001c 100644 --- a/res/shaders/LightCulling.slang +++ b/res/shaders/LightCulling.slang @@ -11,7 +11,7 @@ struct ComputeShaderInput }; struct CullingParams { - Texture2D depthTextureVS; + Texture2D depthTexture; globallycoherent RWStructuredBuffer oLightIndexCounter; globallycoherent RWStructuredBuffer tLightIndexCounter; @@ -67,7 +67,7 @@ void tAppendLight(uint lightIndex) void cullLights(ComputeShaderInput in) { int2 texCoord = int2(in.dispatchThreadID.xy); - float fDepth = pCullingParams.depthTextureVS.Load(int3(texCoord, 0)).r; + float fDepth = pCullingParams.depthTexture.Load(int3(texCoord, 0)).r; uint uDepth = asuint(fDepth); if(in.groupIndex == 0) @@ -98,8 +98,9 @@ void cullLights(ComputeShaderInput in) for ( uint i = in.groupIndex; i < pLightEnv.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE ) { PointLight light = pLightEnv.pointLights[i]; + light.updatePosition(); //TODO: why doesn't this check go through? - if(light.insideFrustum(groupFrustum, nearClipVS)) + if(light.insideFrustum(groupFrustum, nearClipVS, maxDepthVS)) { tAppendLight(i); if(!light.insidePlane(minPlane)) diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index 756e626..337e84a 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -23,6 +23,7 @@ struct PointLight : ILightEnv { float4 position_WS; float4 colorRange; + float4 position_CS; float3 illuminate(LightingParameter params, B brdf) { @@ -32,16 +33,19 @@ struct PointLight : ILightEnv float illuminance = max(1 - d / colorRange.w, 0); return illuminance * brdf.evaluate(params.tbn, params.viewDir_TS, normalize(lightDir_TS), colorRange.xyz); } - - bool insidePlane(Plane plane, float3 center_CS) + void updatePosition() { - float3 position_CS = center_CS + plane.n * colorRange.w; - return plane.pointInside(position_CS); + position_CS = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, position_WS)); + } + + bool insidePlane(Plane plane) + { + float3 edge_CS = position_CS + plane.n * colorRange.w; + return plane.pointInside(edge_CS); } bool insideFrustum(Frustum frustum, float nearClipVS, float maxDepthVS) { - float4 clipPos = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, position_WS)); float3 center_CS = clipPos.xyz / clipPos.w; if(insidePlane(frustum.basePlane, center_CS)) {