Fixing basepass light culling data
This commit is contained in:
@@ -5,11 +5,9 @@ import MaterialParameter;
|
|||||||
|
|
||||||
struct LightCullingData
|
struct LightCullingData
|
||||||
{
|
{
|
||||||
RWStructuredBuffer<uint> oLightIndexList;
|
RWStructuredBuffer<uint> lightIndexList;
|
||||||
RWStructuredBuffer<uint> tLightIndexList;
|
|
||||||
|
|
||||||
RWTexture2D<uint2> oLightGrid;
|
RWTexture2D<uint2> lightGrid;
|
||||||
RWTexture2D<uint2> tLightGrid;
|
|
||||||
};
|
};
|
||||||
layout(set=5)
|
layout(set=5)
|
||||||
ParameterBlock<LightCullingData> pLightCullingData;
|
ParameterBlock<LightCullingData> pLightCullingData;
|
||||||
@@ -21,8 +19,8 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
|||||||
MaterialParameter materialParams = params.getMaterialParameter();
|
MaterialParameter materialParams = params.getMaterialParameter();
|
||||||
let brdf = pMaterial.prepare(materialParams);
|
let brdf = pMaterial.prepare(materialParams);
|
||||||
uint2 tileIndex = uint2(floor(params.position_CS.xy / BLOCK_SIZE));
|
uint2 tileIndex = uint2(floor(params.position_CS.xy / BLOCK_SIZE));
|
||||||
uint startOffset = pLightCullingData.oLightGrid[tileIndex].x;
|
uint startOffset = pLightCullingData.lightGrid[tileIndex].x;
|
||||||
uint lightCount = pLightCullingData.oLightGrid[tileIndex].y;
|
uint lightCount = pLightCullingData.lightGrid[tileIndex].y;
|
||||||
float3 result = float3(0, 0, 0);
|
float3 result = float3(0, 0, 0);
|
||||||
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
|
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
|
||||||
{
|
{
|
||||||
@@ -30,7 +28,7 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
|||||||
}
|
}
|
||||||
for(uint i = 0; i < lightCount; ++i)
|
for(uint i = 0; i < lightCount; ++i)
|
||||||
{
|
{
|
||||||
uint lightIndex = pLightCullingData.oLightIndexList[startOffset + lightCount];
|
uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
|
||||||
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf);
|
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf);
|
||||||
}
|
}
|
||||||
return float4(result, 1.0f);
|
return float4(result, 1.0f);
|
||||||
|
|||||||
@@ -13,23 +13,18 @@ struct ComputeShaderInput
|
|||||||
[shader("compute")]
|
[shader("compute")]
|
||||||
void computeFrustums(ComputeShaderInput in)
|
void computeFrustums(ComputeShaderInput in)
|
||||||
{
|
{
|
||||||
const float3 topLeft = float3(-1, -1, -1);
|
float3 origin = float3(0, 0, 0);
|
||||||
const float3 topRight = float3(1, -1, -1);
|
|
||||||
const float3 bottomLeft = float3(-1, 1, -1);
|
|
||||||
const float3 origin = float3(0, 0, 0);
|
|
||||||
float3 xStep = (topRight - topLeft) / pDispatchParams.numThreads.x;
|
|
||||||
float3 yStep = (bottomLeft - topLeft) / pDispatchParams.numThreads.y;
|
|
||||||
float3 corners[4] = {
|
float3 corners[4] = {
|
||||||
topLeft + (in.dispatchThreadID.x + 0) * xStep + (in.dispatchThreadID.y + 0) * yStep,
|
screenToClip(float3(float2(in.dispatchThreadID.x + 0, in.dispatchThreadID.y + 0) * BLOCK_SIZE, -1.0f)),
|
||||||
topLeft + (in.dispatchThreadID.x + 1) * xStep + (in.dispatchThreadID.y + 0) * yStep,
|
screenToClip(float3(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y + 0) * BLOCK_SIZE, -1.0f)),
|
||||||
topLeft + (in.dispatchThreadID.x + 0) * xStep + (in.dispatchThreadID.y + 1) * yStep,
|
screenToClip(float3(float2(in.dispatchThreadID.x + 0, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f)),
|
||||||
topLeft + (in.dispatchThreadID.x + 1) * xStep + (in.dispatchThreadID.y + 1) * yStep
|
screenToClip(float3(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f))
|
||||||
};
|
};
|
||||||
Frustum frustum;
|
Frustum frustum;
|
||||||
frustum.sides[0] = computePlane(origin, corners[0], corners[2]);
|
frustum.sides[0] = computePlane(origin, corners[2], corners[1]);
|
||||||
frustum.sides[1] = computePlane(origin, corners[3], corners[1]);
|
frustum.sides[1] = computePlane(origin, corners[1], corners[3]);
|
||||||
frustum.sides[2] = computePlane(origin, corners[1], corners[0]);
|
frustum.sides[2] = computePlane(origin, corners[0], corners[1]);
|
||||||
frustum.sides[3] = computePlane(origin, corners[2], corners[3]);
|
frustum.sides[3] = computePlane(origin, corners[3], corners[2]);
|
||||||
if(in.dispatchThreadID.x < pDispatchParams.numThreads.x && in.dispatchThreadID.y < pDispatchParams.numThreads.y)
|
if(in.dispatchThreadID.x < pDispatchParams.numThreads.x && in.dispatchThreadID.y < pDispatchParams.numThreads.y)
|
||||||
{
|
{
|
||||||
uint index = in.dispatchThreadID.x + (in.dispatchThreadID.y * pDispatchParams.numThreads.x);
|
uint index = in.dispatchThreadID.x + (in.dispatchThreadID.y * pDispatchParams.numThreads.x);
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ void cullLights(ComputeShaderInput in)
|
|||||||
{
|
{
|
||||||
PointLight light = pLightEnv.pointLights[i];
|
PointLight light = pLightEnv.pointLights[i];
|
||||||
float3 lightClip = light.getClipPosition();
|
float3 lightClip = light.getClipPosition();
|
||||||
//TODO: why doesn't this check go through?
|
|
||||||
if(light.insideFrustum(groupFrustum, lightClip, nearClip, maxDepth))
|
if(light.insideFrustum(groupFrustum, lightClip, nearClip, maxDepth))
|
||||||
{
|
{
|
||||||
tAppendLight(i);
|
tAppendLight(i);
|
||||||
|
|||||||
@@ -12,15 +12,12 @@ struct ViewParameter
|
|||||||
layout(set = 0)
|
layout(set = 0)
|
||||||
ParameterBlock<ViewParameter> pViewParams;
|
ParameterBlock<ViewParameter> pViewParams;
|
||||||
|
|
||||||
|
float3 screenToClip(float3 screen)
|
||||||
// Convert screen space coordinates to view space.
|
|
||||||
float4 screenToClip( float4 screen )
|
|
||||||
{
|
{
|
||||||
// Convert to normalized texture coordinates
|
|
||||||
float2 texCoord = screen.xy / pViewParams.screenDimensions;
|
float2 texCoord = screen.xy / pViewParams.screenDimensions;
|
||||||
|
|
||||||
// Convert to clip space
|
// Convert to clip space
|
||||||
return float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w );
|
return float3( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Plane
|
struct Plane
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ struct PointLight : ILightEnv
|
|||||||
float3 lightDir_TS = mul(params.tbn, lightDir_WS);
|
float3 lightDir_TS = mul(params.tbn, lightDir_WS);
|
||||||
float d = length(lightDir_TS);
|
float d = length(lightDir_TS);
|
||||||
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);
|
||||||
}
|
}
|
||||||
float3 getClipPosition()
|
float3 getClipPosition()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ struct GraphicsInitializer
|
|||||||
: applicationName("SeeleEngine")
|
: applicationName("SeeleEngine")
|
||||||
, engineName("SeeleEngine")
|
, engineName("SeeleEngine")
|
||||||
, windowLayoutFile(nullptr)
|
, windowLayoutFile(nullptr)
|
||||||
, layers{}
|
, layers{"VK_LAYER_LUNARG_monitor"}
|
||||||
, instanceExtensions{}
|
, instanceExtensions{}
|
||||||
, deviceExtensions{"VK_KHR_swapchain"}
|
, deviceExtensions{"VK_KHR_swapchain"}
|
||||||
, windowHandle(nullptr)
|
, windowHandle(nullptr)
|
||||||
|
|||||||
@@ -21,23 +21,6 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
|
|||||||
: RenderPass(graphics, scene)
|
: RenderPass(graphics, scene)
|
||||||
, descriptorSets(6)
|
, descriptorSets(6)
|
||||||
{
|
{
|
||||||
basePassLayout = graphics->createPipelineLayout();
|
|
||||||
|
|
||||||
basePassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout);
|
|
||||||
basePassLayout->addDescriptorLayout(INDEX_LIGHT_ENV, scene->getLightEnvironment()->getDescriptorLayout());
|
|
||||||
|
|
||||||
lightCullingLayout = graphics->createDescriptorLayout("BasePassLightCulling");
|
|
||||||
// oLightIndexList
|
|
||||||
lightCullingLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
|
||||||
// tLightIndexList
|
|
||||||
lightCullingLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
|
||||||
// oLightGrid
|
|
||||||
lightCullingLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
|
|
||||||
// tLightGrid
|
|
||||||
lightCullingLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
|
|
||||||
lightCullingLayout->create();
|
|
||||||
|
|
||||||
basePassLayout->addDescriptorLayout(INDEX_LIGHT_CULLING, lightCullingLayout);
|
|
||||||
if (graphics->supportMeshShading())
|
if (graphics->supportMeshShading())
|
||||||
{
|
{
|
||||||
graphics->getShaderCompiler()->registerRenderPass("BasePass", "MeshletBasePass", true, true, "BasePass", true, true, "MeshletBasePass");
|
graphics->getShaderCompiler()->registerRenderPass("BasePass", "MeshletBasePass", true, true, "BasePass", true, true, "MeshletBasePass");
|
||||||
@@ -57,6 +40,8 @@ void BasePass::beginFrame(const Component::Camera& cam)
|
|||||||
RenderPass::beginFrame(cam);
|
RenderPass::beginFrame(cam);
|
||||||
|
|
||||||
lightCullingLayout->reset();
|
lightCullingLayout->reset();
|
||||||
|
opaqueCulling = lightCullingLayout->allocateDescriptorSet();
|
||||||
|
transparentCulling = lightCullingLayout->allocateDescriptorSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasePass::render()
|
void BasePass::render()
|
||||||
@@ -79,13 +64,14 @@ void BasePass::render()
|
|||||||
|
|
||||||
descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet;
|
descriptorSets[INDEX_VIEW_PARAMS] = viewParamsSet;
|
||||||
descriptorSets[INDEX_LIGHT_ENV] = scene->getLightEnvironment()->getDescriptorSet();
|
descriptorSets[INDEX_LIGHT_ENV] = scene->getLightEnvironment()->getDescriptorSet();
|
||||||
descriptorSets[INDEX_LIGHT_CULLING] = lightCullingLayout->allocateDescriptorSet();
|
|
||||||
|
|
||||||
descriptorSets[INDEX_LIGHT_CULLING]->updateBuffer(0, oLightIndexList);
|
opaqueCulling->updateBuffer(0, oLightIndexList);
|
||||||
descriptorSets[INDEX_LIGHT_CULLING]->updateBuffer(1, tLightIndexList);
|
opaqueCulling->updateTexture(1, oLightGrid);
|
||||||
descriptorSets[INDEX_LIGHT_CULLING]->updateTexture(2, oLightGrid);
|
transparentCulling->updateBuffer(0, tLightIndexList);
|
||||||
descriptorSets[INDEX_LIGHT_CULLING]->updateTexture(3, tLightGrid);
|
transparentCulling->updateTexture(1, tLightGrid);
|
||||||
descriptorSets[INDEX_LIGHT_CULLING]->writeChanges();
|
opaqueCulling->writeChanges();
|
||||||
|
transparentCulling->writeChanges();
|
||||||
|
descriptorSets[INDEX_LIGHT_CULLING] = opaqueCulling;
|
||||||
|
|
||||||
Gfx::ShaderPermutation permutation;
|
Gfx::ShaderPermutation permutation;
|
||||||
if (graphics->supportMeshShading())
|
if (graphics->supportMeshShading())
|
||||||
@@ -154,7 +140,6 @@ void BasePass::render()
|
|||||||
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
|
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
|
||||||
command->bindPipeline(pipeline);
|
command->bindPipeline(pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptorSets[INDEX_VERTEX_DATA] = vertexData->getVertexDataSet();
|
descriptorSets[INDEX_VERTEX_DATA] = vertexData->getVertexDataSet();
|
||||||
for (const auto& [_, instance] : materialData.instances)
|
for (const auto& [_, instance] : materialData.instances)
|
||||||
{
|
{
|
||||||
@@ -193,6 +178,19 @@ void BasePass::endFrame()
|
|||||||
|
|
||||||
void BasePass::publishOutputs()
|
void BasePass::publishOutputs()
|
||||||
{
|
{
|
||||||
|
basePassLayout = graphics->createPipelineLayout();
|
||||||
|
|
||||||
|
basePassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout);
|
||||||
|
basePassLayout->addDescriptorLayout(INDEX_LIGHT_ENV, scene->getLightEnvironment()->getDescriptorLayout());
|
||||||
|
|
||||||
|
lightCullingLayout = graphics->createDescriptorLayout("BasePassLightCulling");
|
||||||
|
// oLightIndexList
|
||||||
|
lightCullingLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
|
// oLightGrid
|
||||||
|
lightCullingLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
|
||||||
|
lightCullingLayout->create();
|
||||||
|
|
||||||
|
basePassLayout->addDescriptorLayout(INDEX_LIGHT_CULLING, lightCullingLayout);
|
||||||
colorAttachment = Gfx::RenderTargetAttachment(viewport,
|
colorAttachment = Gfx::RenderTargetAttachment(viewport,
|
||||||
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||||
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ private:
|
|||||||
Gfx::PTexture2D oLightGrid;
|
Gfx::PTexture2D oLightGrid;
|
||||||
Gfx::PTexture2D tLightGrid;
|
Gfx::PTexture2D tLightGrid;
|
||||||
|
|
||||||
|
Gfx::PDescriptorSet opaqueCulling;
|
||||||
|
Gfx::PDescriptorSet transparentCulling;
|
||||||
Array<Gfx::PDescriptorSet> descriptorSets;
|
Array<Gfx::PDescriptorSet> descriptorSets;
|
||||||
PCameraActor source;
|
PCameraActor source;
|
||||||
Gfx::OPipelineLayout basePassLayout;
|
Gfx::OPipelineLayout basePassLayout;
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ void LightCullingPass::publishOutputs()
|
|||||||
.size = (uint32)sizeof(uint32)
|
.size = (uint32)sizeof(uint32)
|
||||||
* dispatchParams.numThreadGroups.x
|
* dispatchParams.numThreadGroups.x
|
||||||
* dispatchParams.numThreadGroups.y
|
* dispatchParams.numThreadGroups.y
|
||||||
* dispatchParams.numThreadGroups.z * 200,
|
* dispatchParams.numThreadGroups.z * 1024 * 16,
|
||||||
.data = nullptr,
|
.data = nullptr,
|
||||||
.owner = Gfx::QueueType::COMPUTE
|
.owner = Gfx::QueueType::COMPUTE
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user