Lighting is broken again
This commit is contained in:
@@ -26,9 +26,6 @@ void computeFrustums(ComputeShaderInput in)
|
|||||||
topLeft + (in.dispatchThreadID.x + 1) * xStep + (in.dispatchThreadID.y + 1) * yStep
|
topLeft + (in.dispatchThreadID.x + 1) * xStep + (in.dispatchThreadID.y + 1) * yStep
|
||||||
};
|
};
|
||||||
Frustum frustum;
|
Frustum frustum;
|
||||||
frustum.basePlane.n = float3(0, 0, -1);
|
|
||||||
frustum.basePlane.d = 0;
|
|
||||||
|
|
||||||
frustum.sides[0] = computePlane(origin, corners[0], corners[2]);
|
frustum.sides[0] = computePlane(origin, corners[0], corners[2]);
|
||||||
frustum.sides[1] = computePlane(origin, corners[3], corners[1]);
|
frustum.sides[1] = computePlane(origin, corners[3], corners[1]);
|
||||||
frustum.sides[2] = computePlane(origin, corners[1], corners[0]);
|
frustum.sides[2] = computePlane(origin, corners[1], corners[0]);
|
||||||
|
|||||||
@@ -98,12 +98,12 @@ 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();
|
float3 lightClip = light.getClipPosition();
|
||||||
//TODO: why doesn't this check go through?
|
//TODO: why doesn't this check go through?
|
||||||
if(light.insideFrustum(groupFrustum, nearClipVS, maxDepthVS))
|
if(light.insideFrustum(groupFrustum, lightClip, nearClipVS, maxDepthVS))
|
||||||
{
|
{
|
||||||
tAppendLight(i);
|
tAppendLight(i);
|
||||||
if(!light.insidePlane(minPlane))
|
if(!light.insidePlane(minPlane, lightClip))
|
||||||
{
|
{
|
||||||
oAppendLight(i);
|
oAppendLight(i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,9 +39,6 @@ void taskMain(
|
|||||||
// Bottom
|
// Bottom
|
||||||
viewFrustum.sides[3].n = float3(0, 1, 0);
|
viewFrustum.sides[3].n = float3(0, 1, 0);
|
||||||
viewFrustum.sides[3].d = -1;
|
viewFrustum.sides[3].d = -1;
|
||||||
// Base
|
|
||||||
viewFrustum.basePlane.n = float3(0, 0, -1);
|
|
||||||
viewFrustum.basePlane.d = 0;
|
|
||||||
}
|
}
|
||||||
GroupMemoryBarrierWithGroupSync();
|
GroupMemoryBarrierWithGroupSync();
|
||||||
MeshData mesh = pScene.meshData[groupID];
|
MeshData mesh = pScene.meshData[groupID];
|
||||||
|
|||||||
@@ -19,9 +19,13 @@ struct AABB
|
|||||||
corners[7] = mul(transform, float4(max.x, max.y, max.z, 1.0f));
|
corners[7] = mul(transform, float4(max.x, max.y, max.z, 1.0f));
|
||||||
for(int i = 0; i < 8; ++i)
|
for(int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
if(frustum.pointInside(corners[i].xyz / corners[i].w))
|
float3 adjusted = corners[i].xyz / corners[i].w;
|
||||||
|
if(adjusted.z > 0)
|
||||||
{
|
{
|
||||||
return true;
|
if(frustum.pointInside(adjusted))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -36,13 +36,8 @@ struct Plane
|
|||||||
struct Frustum
|
struct Frustum
|
||||||
{
|
{
|
||||||
Plane sides[4];
|
Plane sides[4];
|
||||||
Plane basePlane;
|
|
||||||
bool pointInside(float3 point)
|
bool pointInside(float3 point)
|
||||||
{
|
{
|
||||||
if (!basePlane.pointInside(point))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for(int p = 0; p < 4; ++p)
|
for(int p = 0; p < 4; ++p)
|
||||||
{
|
{
|
||||||
if(!sides[p].pointInside(point))
|
if(!sides[p].pointInside(point))
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ 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)
|
||||||
{
|
{
|
||||||
@@ -33,33 +32,32 @@ 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()
|
float3 getClipPosition()
|
||||||
{
|
{
|
||||||
position_CS = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, position_WS));
|
float4 position_CS = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, position_WS));
|
||||||
|
return position_CS.xyz / position_CS.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool insidePlane(Plane plane)
|
bool insidePlane(Plane plane, float3 position_CS)
|
||||||
{
|
{
|
||||||
float3 edge_CS = position_CS + plane.n * colorRange.w;
|
return dot(plane.n, position_CS) - plane.d < -colorRange.w;
|
||||||
return plane.pointInside(edge_CS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool insideFrustum(Frustum frustum, float nearClipVS, float maxDepthVS)
|
bool insideFrustum(Frustum frustum, float3 position_CS, float minDepth, float maxDepth)
|
||||||
{
|
{
|
||||||
float3 center_CS = clipPos.xyz / clipPos.w;
|
bool result = true;
|
||||||
if(insidePlane(frustum.basePlane, center_CS))
|
if(position_CS.z - colorRange.w > minDepth || position_CS.z + colorRange.w < maxDepth)
|
||||||
{
|
{
|
||||||
return true;
|
result = false;
|
||||||
}
|
}
|
||||||
uint result = 0;
|
for(int i = 0; i < 4 && result; ++i)
|
||||||
for(int i = 0; i < 4; ++i)
|
|
||||||
{
|
{
|
||||||
if(insidePlane(frustum.sides[i], center_CS))
|
if(insidePlane(frustum.sides[i], position_CS))
|
||||||
{
|
{
|
||||||
result++;
|
result = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result > 0;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ struct VertexAttributes
|
|||||||
float4 worldPos = mul(transformMatrix, modelPos);
|
float4 worldPos = mul(transformMatrix, modelPos);
|
||||||
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
|
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
|
||||||
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
|
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
|
||||||
float3 tangent_WS = mul(float3x3(transformMatrix), normalize(tangent_MS));
|
float3 tangent_WS = mul(float3x3(transformMatrix), tangent_MS);
|
||||||
float3 biTangent_WS = mul(float3x3(transformMatrix), normalize(biTangent_MS));
|
float3 biTangent_WS = mul(float3x3(transformMatrix), biTangent_MS);
|
||||||
float3 normal_WS = mul(float3x3(transformMatrix), normalize(normal_MS));
|
float3 normal_WS = mul(float3x3(transformMatrix), normal_MS);
|
||||||
FragmentParameter result;
|
FragmentParameter result;
|
||||||
result.viewDir_WS = pViewParams.cameraPos_WS.xyz - worldPos.xyz;
|
result.viewDir_WS = pViewParams.cameraPos_WS.xyz - worldPos.xyz;
|
||||||
result.normal_WS = normal_WS;
|
result.normal_WS = normal_WS;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ void LightCullingPass::beginFrame(const Component::Camera& cam)
|
|||||||
DataSource counterReset = {
|
DataSource counterReset = {
|
||||||
.size = sizeof(uint32),
|
.size = sizeof(uint32),
|
||||||
.data = (uint8*)&reset,
|
.data = (uint8*)&reset,
|
||||||
|
.owner = Gfx::QueueType::COMPUTE
|
||||||
};
|
};
|
||||||
oLightIndexCounter->updateContents(counterReset);
|
oLightIndexCounter->updateContents(counterReset);
|
||||||
tLightIndexCounter->updateContents(counterReset);
|
tLightIndexCounter->updateContents(counterReset);
|
||||||
@@ -46,9 +47,6 @@ void LightCullingPass::beginFrame(const Component::Camera& cam)
|
|||||||
|
|
||||||
cullingDescriptorLayout->reset();
|
cullingDescriptorLayout->reset();
|
||||||
cullingDescriptorSet = cullingDescriptorLayout->allocateDescriptorSet();
|
cullingDescriptorSet = cullingDescriptorLayout->allocateDescriptorSet();
|
||||||
|
|
||||||
//std::cout << "LightCulling beginFrame()" << std::endl;
|
|
||||||
//co_return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightCullingPass::render()
|
void LightCullingPass::render()
|
||||||
@@ -72,14 +70,10 @@ void LightCullingPass::render()
|
|||||||
Array<Gfx::PComputeCommand> commands = {computeCommand};
|
Array<Gfx::PComputeCommand> commands = {computeCommand};
|
||||||
//std::cout << "Execute" << std::endl;
|
//std::cout << "Execute" << std::endl;
|
||||||
graphics->executeCommands(commands);
|
graphics->executeCommands(commands);
|
||||||
//std::cout << "LightCulling render()" << std::endl;
|
|
||||||
//co_return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightCullingPass::endFrame()
|
void LightCullingPass::endFrame()
|
||||||
{
|
{
|
||||||
//std::cout << "LightCulling endFrame()" << std::endl;
|
|
||||||
//co_return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightCullingPass::publishOutputs()
|
void LightCullingPass::publishOutputs()
|
||||||
@@ -94,10 +88,17 @@ void LightCullingPass::publishOutputs()
|
|||||||
.sourceData = {
|
.sourceData = {
|
||||||
.size = sizeof(DispatchParams),
|
.size = sizeof(DispatchParams),
|
||||||
.data = (uint8*)&dispatchParams,
|
.data = (uint8*)&dispatchParams,
|
||||||
|
.owner = Gfx::QueueType::COMPUTE
|
||||||
},
|
},
|
||||||
.dynamic = false,
|
.dynamic = false,
|
||||||
|
.name = "DispatchParams",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
|
||||||
|
dispatchParamsSet->updateBuffer(0, dispatchParamsBuffer);
|
||||||
|
dispatchParamsSet->updateBuffer(1, frustumBuffer);
|
||||||
|
dispatchParamsSet->writeChanges();
|
||||||
|
|
||||||
cullingDescriptorLayout = graphics->createDescriptorLayout("CullingLayout");
|
cullingDescriptorLayout = graphics->createDescriptorLayout("CullingLayout");
|
||||||
|
|
||||||
//DepthTexture
|
//DepthTexture
|
||||||
@@ -226,20 +227,24 @@ void LightCullingPass::setupFrustums()
|
|||||||
.sourceData = {
|
.sourceData = {
|
||||||
.size = sizeof(DispatchParams),
|
.size = sizeof(DispatchParams),
|
||||||
.data = (uint8*) & dispatchParams,
|
.data = (uint8*) & dispatchParams,
|
||||||
|
.owner = Gfx::QueueType::COMPUTE
|
||||||
},
|
},
|
||||||
.dynamic = false,
|
.dynamic = false,
|
||||||
|
.name = "FrustumDispatch"
|
||||||
});
|
});
|
||||||
|
|
||||||
frustumBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
frustumBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||||
.sourceData = {
|
.sourceData = {
|
||||||
.size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z,
|
.size = sizeof(Frustum) * numThreads.x * numThreads.y * numThreads.z,
|
||||||
.data = nullptr,
|
.data = nullptr,
|
||||||
|
.owner = Gfx::QueueType::COMPUTE
|
||||||
},
|
},
|
||||||
.numElements = numThreads.x * numThreads.y * numThreads.z,
|
.numElements = numThreads.x * numThreads.y * numThreads.z,
|
||||||
.dynamic = false,
|
.dynamic = false,
|
||||||
|
.name = "FrustumBuffer"
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
|
Gfx::PDescriptorSet dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
|
||||||
dispatchParamsSet->updateBuffer(0, frustumDispatchParamsBuffer);
|
dispatchParamsSet->updateBuffer(0, frustumDispatchParamsBuffer);
|
||||||
dispatchParamsSet->updateBuffer(1, frustumBuffer);
|
dispatchParamsSet->updateBuffer(1, frustumBuffer);
|
||||||
dispatchParamsSet->writeChanges();
|
dispatchParamsSet->writeChanges();
|
||||||
|
|||||||
@@ -47,17 +47,20 @@ Buffer::Buffer(PGraphics graphics,
|
|||||||
{
|
{
|
||||||
vmaCreateBuffer(graphics->getAllocator(), &info, &allocInfo, &buffers[i].buffer, &buffers[i].allocation, &buffers[i].info);
|
vmaCreateBuffer(graphics->getAllocator(), &info, &allocInfo, &buffers[i].buffer, &buffers[i].allocation, &buffers[i].info);
|
||||||
vmaGetAllocationMemoryProperties(graphics->getAllocator(), buffers[i].allocation, &buffers[i].properties);
|
vmaGetAllocationMemoryProperties(graphics->getAllocator(), buffers[i].allocation, &buffers[i].properties);
|
||||||
|
//std::cout << "Create buffer " << std::hex << (uint64)buffers[i].buffer << std::dec;
|
||||||
if (!name.empty())
|
if (!name.empty())
|
||||||
{
|
{
|
||||||
VkDebugMarkerObjectNameInfoEXT nameInfo = {
|
VkDebugUtilsObjectNameInfoEXT nameInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT,
|
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.objectType = VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT,
|
.objectType = VK_OBJECT_TYPE_BUFFER,
|
||||||
.object = (uint64)buffers[i].buffer,
|
.objectHandle = (uint64)buffers[i].buffer,
|
||||||
.pObjectName = this->name.c_str()
|
.pObjectName = this->name.c_str()
|
||||||
};
|
};
|
||||||
//graphics->vkDebugMarkerSetObjectNameEXT(&nameInfo);
|
graphics->vkSetDebugUtilsObjectNameEXT(&nameInfo);
|
||||||
|
//std::cout << ": " << name;
|
||||||
}
|
}
|
||||||
|
//std::cout << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -293,9 +293,9 @@ void Graphics::vkCmdDrawMeshTasksEXT(VkCommandBuffer handle, uint32 groupX, uint
|
|||||||
cmdDrawMeshTasks(handle, groupX, groupY, groupZ);
|
cmdDrawMeshTasks(handle, groupX, groupY, groupZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::vkDebugMarkerSetObjectNameEXT(VkDebugMarkerObjectNameInfoEXT* info)
|
void Graphics::vkSetDebugUtilsObjectNameEXT(VkDebugUtilsObjectNameInfoEXT* info)
|
||||||
{
|
{
|
||||||
VK_CHECK(cmdDebugMarkerSetObjectName(handle, info));
|
VK_CHECK(setDebugUtilsObjectName(handle, info));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -484,7 +484,7 @@ void Graphics::pickPhysicalDevice()
|
|||||||
{
|
{
|
||||||
if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0)
|
if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0)
|
||||||
{
|
{
|
||||||
meshShadingEnabled = true;
|
//meshShadingEnabled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -637,6 +637,6 @@ void Graphics::createDevice(GraphicsInitializer initializer)
|
|||||||
queueMapping.graphicsFamily = queues[graphicsQueue]->getFamilyIndex();
|
queueMapping.graphicsFamily = queues[graphicsQueue]->getFamilyIndex();
|
||||||
queueMapping.computeFamily = queues[computeQueue]->getFamilyIndex();
|
queueMapping.computeFamily = queues[computeQueue]->getFamilyIndex();
|
||||||
queueMapping.transferFamily = queues[transferQueue]->getFamilyIndex();
|
queueMapping.transferFamily = queues[transferQueue]->getFamilyIndex();
|
||||||
cmdDebugMarkerSetObjectName = (PFN_vkDebugMarkerSetObjectNameEXT)vkGetInstanceProcAddr(instance, "vkDebugMarkerSetObjectNameEXT");
|
setDebugUtilsObjectName = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(instance, "vkSetDebugUtilsObjectNameEXT");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,11 +70,11 @@ public:
|
|||||||
virtual void resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) override;
|
virtual void resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) override;
|
||||||
|
|
||||||
void vkCmdDrawMeshTasksEXT(VkCommandBuffer handle, uint32 groupX, uint32 groupY, uint32 groupZ);
|
void vkCmdDrawMeshTasksEXT(VkCommandBuffer handle, uint32 groupX, uint32 groupY, uint32 groupZ);
|
||||||
void vkDebugMarkerSetObjectNameEXT(VkDebugMarkerObjectNameInfoEXT* info);
|
void vkSetDebugUtilsObjectNameEXT(VkDebugUtilsObjectNameInfoEXT* info);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PFN_vkCmdDrawMeshTasksEXT cmdDrawMeshTasks;
|
PFN_vkCmdDrawMeshTasksEXT cmdDrawMeshTasks;
|
||||||
PFN_vkDebugMarkerSetObjectNameEXT cmdDebugMarkerSetObjectName;
|
PFN_vkSetDebugUtilsObjectNameEXT setDebugUtilsObjectName;
|
||||||
Array<const char *> getRequiredExtensions();
|
Array<const char *> getRequiredExtensions();
|
||||||
void initInstance(GraphicsInitializer initInfo);
|
void initInstance(GraphicsInitializer initInfo);
|
||||||
void setupDebugCallback();
|
void setupDebugCallback();
|
||||||
|
|||||||
Reference in New Issue
Block a user