Provisional light culling
This commit is contained in:
@@ -8,7 +8,7 @@ struct ComputeShaderInput
|
||||
uint groupIndex : SV_GroupIndex;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 0, std430)
|
||||
layout(set = 0, binding = 1, std430)
|
||||
cbuffer DispatchParams
|
||||
{
|
||||
uint3 numThreadGroups;
|
||||
|
||||
@@ -8,10 +8,10 @@ import MATERIAL_IMPORT;
|
||||
import PrimitiveSceneData;
|
||||
import MaterialParameter;
|
||||
|
||||
//layout(set = 0, binding = 2)
|
||||
//StructuredBuffer<uint> lightIndexList;
|
||||
//layout(set = 0, binding = 3)
|
||||
//RWTexture2D<uint2> lightGrid;
|
||||
layout(set = INDEX_LIGHT_ENV, binding = 1)
|
||||
StructuredBuffer<uint> lightIndexList;
|
||||
layout(set = INDEX_LIGHT_ENV, binding = 2)
|
||||
RWTexture2D<uint2> lightGrid;
|
||||
|
||||
|
||||
struct VertexStageOutput
|
||||
@@ -56,20 +56,20 @@ float4 fragmentMain(
|
||||
|
||||
float3 result = float3(0, 0, 0);
|
||||
|
||||
for (int i = 0; i < gLightEnv.numDirectionalLights; i++)
|
||||
for (int i = 0; i < gLightEnv[0].numDirectionalLights; i++)
|
||||
{
|
||||
result += gLightEnv.directionalLights[i].illuminate(materialParams, brdf, viewDir);
|
||||
result += gLightEnv[0].directionalLights[i].illuminate(materialParams, brdf, viewDir);
|
||||
}
|
||||
|
||||
uint2 tileIndex = uint2(floor(materialParams.clipPosition.xy) / BLOCK_SIZE);
|
||||
|
||||
//uint startOffset = lightGrid[tileIndex].x;
|
||||
//uint lightCount = lightGrid[tileIndex].y;
|
||||
uint startOffset = lightGrid[tileIndex].x;
|
||||
uint lightCount = lightGrid[tileIndex].y;
|
||||
|
||||
for (int j = 0; j < gLightEnv.numPointLights; ++j)
|
||||
for (int j = 0; j < gLightEnv[0].numPointLights; ++j)
|
||||
{
|
||||
//uint lightIndex = lightIndexList[startOffset + j];
|
||||
PointLight pointLight = gLightEnv.pointLights[j];
|
||||
uint lightIndex = lightIndexList[startOffset + j];
|
||||
PointLight pointLight = gLightEnv[0].pointLights[lightIndex];
|
||||
result += pointLight.illuminate(materialParams, brdf, viewDir);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ struct ComputeShaderInput
|
||||
uint3 dispatchThreadID : SV_DispatchThreadID;
|
||||
uint groupIndex : SV_GroupIndex;
|
||||
};
|
||||
layout(binding = 0)
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 1)
|
||||
cbuffer DispatchParams
|
||||
{
|
||||
uint3 numThreadGroups;
|
||||
@@ -17,23 +17,23 @@ cbuffer DispatchParams
|
||||
uint pad1;
|
||||
}
|
||||
|
||||
layout(binding = 2)
|
||||
RWTexture2D depthTextureVS;
|
||||
layout(binding = 4)
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 2)
|
||||
Texture2D depthTextureVS;
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 3)
|
||||
StructuredBuffer<Frustum> frustums;
|
||||
|
||||
layout(binding = 5)
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 4)
|
||||
RWStructuredBuffer<uint> oLightIndexCounter;
|
||||
layout(binding = 6)
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 5)
|
||||
RWStructuredBuffer<uint> tLightIndexCounter;
|
||||
|
||||
layout(binding = 7)
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 6)
|
||||
RWStructuredBuffer<uint> oLightIndexList;
|
||||
layout(binding = 8)
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 7)
|
||||
RWStructuredBuffer<uint> tLightIndexList;
|
||||
layout(binding = 9)
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 8)
|
||||
RWTexture2D<uint2> oLightGrid;
|
||||
layout(binding = 10)
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 9)
|
||||
RWTexture2D<uint2> tLightGrid;
|
||||
|
||||
groupshared uint uMinDepth;
|
||||
@@ -71,9 +71,10 @@ void tAppendLight(uint lightIndex)
|
||||
}
|
||||
|
||||
[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)]
|
||||
[shader("compute")]
|
||||
void cullLights(ComputeShaderInput in)
|
||||
{
|
||||
int2 texCoord = in.dispatchThreadID.xy;
|
||||
int3 texCoord = int3(in.dispatchThreadID.xy, 0);
|
||||
float fDepth = depthTextureVS.Load(texCoord).r;
|
||||
|
||||
uint uDepth = asuint(fDepth);
|
||||
@@ -101,10 +102,10 @@ void cullLights(ComputeShaderInput in)
|
||||
|
||||
Plane minPlane = {float3(0, 0, -1), -minDepthVS};
|
||||
|
||||
for ( uint i = in.groupIndex; i < lights.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE )
|
||||
for ( uint i = in.groupIndex; i < gLightEnv[0].numPointLights; i += BLOCK_SIZE * BLOCK_SIZE )
|
||||
{
|
||||
PointLight light = lights.pointLights[i];
|
||||
//if(light.insideFrustum(groupFrustum, nearClipVS, maxDepthVS))
|
||||
PointLight light = gLightEnv[0].pointLights[i];
|
||||
//if(gLightEnv.insideFrustum(groupFrustum, nearClipVS, maxDepthVS))
|
||||
{
|
||||
//InterlockedAdd(tLightCount, 1, index);
|
||||
//if(index < 1024)
|
||||
|
||||
@@ -6,24 +6,18 @@ struct ViewParameter
|
||||
{
|
||||
float4x4 viewMatrix;
|
||||
float4x4 projectionMatrix;
|
||||
float4x4 inverseProjection;
|
||||
float2 screenDimensions;
|
||||
float4 cameraPos_WS;
|
||||
}
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 0, std430)
|
||||
ConstantBuffer<ViewParameter> gViewParams;
|
||||
|
||||
struct ScreenToViewParams
|
||||
{
|
||||
float4x4 inverseProjection;
|
||||
float2 screenDimensions;
|
||||
}
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 1, std430)
|
||||
ConstantBuffer<ScreenToViewParams> gScreenToViewParams;
|
||||
|
||||
// Convert clip space coordinates to view space
|
||||
float4 clipToView( float4 clip )
|
||||
{
|
||||
// View space position.
|
||||
float4 view = mul( gScreenToViewParams.inverseProjection, clip );
|
||||
float4 view = mul( gViewParams.inverseProjection, clip );
|
||||
// Perspective projection.
|
||||
view = view / view.w;
|
||||
|
||||
@@ -34,7 +28,7 @@ float4 clipToView( float4 clip )
|
||||
float4 screenToView( float4 screen )
|
||||
{
|
||||
// Convert to normalized texture coordinates
|
||||
float2 texCoord = screen.xy / gScreenToViewParams.screenDimensions;
|
||||
float2 texCoord = screen.xy / gViewParams.screenDimensions;
|
||||
|
||||
// Convert to clip space
|
||||
float4 clip = float4( float2( texCoord.x, -texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w );
|
||||
|
||||
@@ -69,4 +69,4 @@ struct Lights
|
||||
};
|
||||
|
||||
layout(set = INDEX_LIGHT_ENV, binding = 0, std430)
|
||||
ConstantBuffer<Lights> gLightEnv;
|
||||
StructuredBuffer<Lights> gLightEnv;
|
||||
|
||||
Reference in New Issue
Block a user