More light culling changes

This commit is contained in:
Dynamitos
2024-02-02 11:39:40 +01:00
parent 829c4937c0
commit 97d96a6bc1
2 changed files with 13 additions and 8 deletions
+4 -3
View File
@@ -11,7 +11,7 @@ struct ComputeShaderInput
}; };
struct CullingParams struct CullingParams
{ {
Texture2D depthTextureVS; Texture2D depthTexture;
globallycoherent RWStructuredBuffer<uint> oLightIndexCounter; globallycoherent RWStructuredBuffer<uint> oLightIndexCounter;
globallycoherent RWStructuredBuffer<uint> tLightIndexCounter; globallycoherent RWStructuredBuffer<uint> tLightIndexCounter;
@@ -67,7 +67,7 @@ void tAppendLight(uint lightIndex)
void cullLights(ComputeShaderInput in) void cullLights(ComputeShaderInput in)
{ {
int2 texCoord = int2(in.dispatchThreadID.xy); 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); uint uDepth = asuint(fDepth);
if(in.groupIndex == 0) 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 ) for ( uint i = in.groupIndex; i < pLightEnv.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE )
{ {
PointLight light = pLightEnv.pointLights[i]; PointLight light = pLightEnv.pointLights[i];
light.updatePosition();
//TODO: why doesn't this check go through? //TODO: why doesn't this check go through?
if(light.insideFrustum(groupFrustum, nearClipVS)) if(light.insideFrustum(groupFrustum, nearClipVS, maxDepthVS))
{ {
tAppendLight(i); tAppendLight(i);
if(!light.insidePlane(minPlane)) if(!light.insidePlane(minPlane))
+9 -5
View File
@@ -23,6 +23,7 @@ struct PointLight : ILightEnv
{ {
float4 position_WS; float4 position_WS;
float4 colorRange; float4 colorRange;
float4 position_CS;
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf) float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
{ {
@@ -32,16 +33,19 @@ struct PointLight : ILightEnv
float illuminance = max(1 - d / colorRange.w, 0); float illuminance = max(1 - d / colorRange.w, 0);
return illuminance * brdf.evaluate(params.tbn, params.viewDir_TS, normalize(lightDir_TS), colorRange.xyz); return illuminance * brdf.evaluate(params.tbn, params.viewDir_TS, normalize(lightDir_TS), colorRange.xyz);
} }
void updatePosition()
bool insidePlane(Plane plane, float3 center_CS)
{ {
float3 position_CS = center_CS + plane.n * colorRange.w; position_CS = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, position_WS));
return plane.pointInside(position_CS); }
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) 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; float3 center_CS = clipPos.xyz / clipPos.w;
if(insidePlane(frustum.basePlane, center_CS)) if(insidePlane(frustum.basePlane, center_CS))
{ {