Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Engine_Master_UPC/DeferredShadingPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ void DeferredShadingPass::prepare(const RenderContext& ctx)
if (m_hasShadowData)
{
m_shadowCBAddress = ctx.shadowData->shadowCBAddress;
m_shadowMapSRV = ctx.shadowData->shadowMapSRV;
m_cascadeShadowMapSRV = ctx.shadowData->cascadeShadowMapSRV;
}
else
{
m_shadowCBAddress = 0;
m_shadowMapSRV = {};
m_cascadeShadowMapSRV = {};
}

m_renderSurface = &ctx.renderSurface;
Expand Down Expand Up @@ -234,10 +234,10 @@ void DeferredShadingPass::apply(ID3D12GraphicsCommandList4* commandList)

commandList->SetGraphicsRootDescriptorTable(6, app->getModuleDescriptors()->getHeap(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER).getGPUHandle(ModuleDescriptors::SampleType::LINEAR_WRAP));

if (m_hasShadowData && m_shadowCBAddress != 0 && m_shadowMapSRV.ptr != 0)
if (m_hasShadowData && m_shadowCBAddress != 0 && m_cascadeShadowMapSRV.ptr != 0)
{
commandList->SetGraphicsRootConstantBufferView(7, m_shadowCBAddress);
commandList->SetGraphicsRootDescriptorTable(8, m_shadowMapSRV);
commandList->SetGraphicsRootDescriptorTable(8, m_cascadeShadowMapSRV);
}

if (m_hasSSAOData && m_ssaoSRV.ptr != 0)
Expand Down
2 changes: 1 addition & 1 deletion Engine_Master_UPC/DeferredShadingPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class DeferredShadingPass : public IRenderPass {

// ShadowMap
D3D12_GPU_VIRTUAL_ADDRESS m_shadowCBAddress = 0;
D3D12_GPU_DESCRIPTOR_HANDLE m_shadowMapSRV{};
D3D12_GPU_DESCRIPTOR_HANDLE m_cascadeShadowMapSRV{};
bool m_hasShadowData = false;

// SSAO
Expand Down
76 changes: 76 additions & 0 deletions Engine_Master_UPC/DepthMinMaxInitialComputeShader.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Texture2D<float> inputDepth : register(t0);
RWTexture2D<float2> outputMinMax : register(u0);

cbuffer ReductionParams : register(b0)
{
uint2 inputSize;
uint2 padding;
};

groupshared uint groupMinDepth;
groupshared uint groupMaxDepth;
groupshared uint groupValidCount;

[numthreads(8, 8, 1)]
void main(
uint3 globalIndex : SV_DispatchThreadID,
uint3 localIndex3D : SV_GroupThreadID,
uint3 groupIndex : SV_GroupID)
{
uint localIndex =
localIndex3D.y * 8 + localIndex3D.x;

if (localIndex == 0)
{
groupMinDepth = asuint(1.0f);
groupMaxDepth = asuint(0.0f);
groupValidCount = 0;
}

GroupMemoryBarrierWithGroupSync();

if (globalIndex.x < inputSize.x &&
globalIndex.y < inputSize.y)
{
float depth =
inputDepth.Load(int3(globalIndex.xy, 0));

// The camera depth buffer is cleared to 1.0.
// Clear pixels do not represent visible geometry.
if (depth >= 0.0f && depth < 1.0f)
{
uint depthBits = asuint(depth);

InterlockedMin(
groupMinDepth,
depthBits);

InterlockedMax(
groupMaxDepth,
depthBits);

InterlockedAdd(
groupValidCount,
1);
}
}

GroupMemoryBarrierWithGroupSync();

if (localIndex == 0)
{
if (groupValidCount > 0)
{
outputMinMax[groupIndex.xy] =
float2(
asfloat(groupMinDepth),
asfloat(groupMaxDepth));
}
else
{
// min > max marks a tile without geometry.
outputMinMax[groupIndex.xy] =
float2(1.0f, 0.0f);
}
}
}
75 changes: 75 additions & 0 deletions Engine_Master_UPC/DepthMinMaxReduceComputeShader.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Texture2D<float2> inputMinMax : register(t0);
RWTexture2D<float2> outputMinMax : register(u0);

cbuffer ReductionParams : register(b0)
{
uint2 inputSize;
uint2 padding;
};

groupshared uint groupMinDepth;
groupshared uint groupMaxDepth;
groupshared uint groupValidCount;

[numthreads(8, 8, 1)]
void main(
uint3 globalIndex : SV_DispatchThreadID,
uint3 localIndex3D : SV_GroupThreadID,
uint3 groupIndex : SV_GroupID)
{
uint localIndex =
localIndex3D.y * 8 + localIndex3D.x;

if (localIndex == 0)
{
groupMinDepth = asuint(1.0f);
groupMaxDepth = asuint(0.0f);
groupValidCount = 0;
}

GroupMemoryBarrierWithGroupSync();

if (globalIndex.x < inputSize.x &&
globalIndex.y < inputSize.y)
{
float2 minMaxDepth =
inputMinMax.Load(
int3(globalIndex.xy, 0));

const bool validTile =
minMaxDepth.x <= minMaxDepth.y;

if (validTile)
{
InterlockedMin(
groupMinDepth,
asuint(minMaxDepth.x));

InterlockedMax(
groupMaxDepth,
asuint(minMaxDepth.y));

InterlockedAdd(
groupValidCount,
1);
}
}

GroupMemoryBarrierWithGroupSync();

if (localIndex == 0)
{
if (groupValidCount > 0)
{
outputMinMax[groupIndex.xy] =
float2(
asfloat(groupMinDepth),
asfloat(groupMaxDepth));
}
else
{
outputMinMax[groupIndex.xy] =
float2(1.0f, 0.0f);
}
}
}
Loading