Add depth test for point/spot lights rendering to optimize far lights rendering
This commit is contained in:
@@ -100,26 +100,28 @@ bool LightPass::setupResources()
|
||||
psDesc = GPUPipelineState::Description::DefaultNoDepth;
|
||||
psDesc.BlendMode = BlendingMode::Add;
|
||||
psDesc.BlendMode.RenderTargetWriteMask = BlendingMode::ColorWrite::RGB;
|
||||
psDesc.CullMode = CullMode::Normal;
|
||||
psDesc.VS = shader->GetVS("VS_Model");
|
||||
if (_psLightPointNormal.Create(psDesc, shader, "PS_Point"))
|
||||
return true;
|
||||
psDesc.CullMode = CullMode::Inverted;
|
||||
if (_psLightPointInverted.Create(psDesc, shader, "PS_Point"))
|
||||
return true;
|
||||
psDesc.CullMode = CullMode::Normal;
|
||||
psDesc.DepthTestEnable = true;
|
||||
if (_psLightPointNormal.Create(psDesc, shader, "PS_Point"))
|
||||
return true;
|
||||
}
|
||||
if (!_psLightSpotNormal.IsValid() || !_psLightSpotInverted.IsValid())
|
||||
{
|
||||
psDesc = GPUPipelineState::Description::DefaultNoDepth;
|
||||
psDesc.BlendMode = BlendingMode::Add;
|
||||
psDesc.BlendMode.RenderTargetWriteMask = BlendingMode::ColorWrite::RGB;
|
||||
psDesc.CullMode = CullMode::Normal;
|
||||
psDesc.VS = shader->GetVS("VS_Model");
|
||||
if (_psLightSpotNormal.Create(psDesc, shader, "PS_Spot"))
|
||||
return true;
|
||||
psDesc.CullMode = CullMode::Inverted;
|
||||
if (_psLightSpotInverted.Create(psDesc, shader, "PS_Spot"))
|
||||
return true;
|
||||
psDesc.CullMode = CullMode::Normal;
|
||||
psDesc.DepthTestEnable = true;
|
||||
if (_psLightSpotNormal.Create(psDesc, shader, "PS_Spot"))
|
||||
return true;
|
||||
}
|
||||
if (!_psLightSkyNormal->IsValid() || !_psLightSkyInverted->IsValid())
|
||||
{
|
||||
@@ -203,7 +205,9 @@ void LightPass::RenderLight(RenderContext& renderContext, GPUTextureView* lightB
|
||||
PerFrame perFrame;
|
||||
|
||||
// Bind output
|
||||
context->SetRenderTarget(lightBuffer);
|
||||
GPUTexture* depthBuffer = renderContext.Buffers->DepthBuffer;
|
||||
GPUTextureView* depthBufferHandle = depthBuffer->GetDescription().Flags & GPUTextureFlags::ReadOnlyDepthView ? depthBuffer->ViewReadOnlyDepth() : nullptr;
|
||||
context->SetRenderTarget(depthBufferHandle, lightBuffer);
|
||||
|
||||
// Set per frame data
|
||||
GBufferPass::SetInputs(renderContext.View, perFrame.GBuffer);
|
||||
@@ -221,7 +225,7 @@ void LightPass::RenderLight(RenderContext& renderContext, GPUTextureView* lightB
|
||||
context->BindSR(0, renderContext.Buffers->GBuffer0);
|
||||
context->BindSR(1, renderContext.Buffers->GBuffer1);
|
||||
context->BindSR(2, renderContext.Buffers->GBuffer2);
|
||||
context->BindSR(3, renderContext.Buffers->DepthBuffer);
|
||||
context->BindSR(3, depthBuffer);
|
||||
context->BindSR(4, renderContext.Buffers->GBuffer3);
|
||||
|
||||
// Check if debug lights
|
||||
@@ -270,7 +274,7 @@ void LightPass::RenderLight(RenderContext& renderContext, GPUTextureView* lightB
|
||||
ShadowsPass::Instance()->RenderShadow(renderContext, light, shadowMaskView);
|
||||
|
||||
// Bind output
|
||||
context->SetRenderTarget(lightBuffer);
|
||||
context->SetRenderTarget(depthBufferHandle, lightBuffer);
|
||||
|
||||
// Set shadow mask
|
||||
context->BindSR(5, shadowMaskView);
|
||||
@@ -325,7 +329,7 @@ void LightPass::RenderLight(RenderContext& renderContext, GPUTextureView* lightB
|
||||
ShadowsPass::Instance()->RenderShadow(renderContext, light, shadowMaskView);
|
||||
|
||||
// Bind output
|
||||
context->SetRenderTarget(lightBuffer);
|
||||
context->SetRenderTarget(depthBufferHandle, lightBuffer);
|
||||
|
||||
// Set shadow mask
|
||||
context->BindSR(5, shadowMaskView);
|
||||
@@ -366,7 +370,7 @@ void LightPass::RenderLight(RenderContext& renderContext, GPUTextureView* lightB
|
||||
ShadowsPass::Instance()->RenderShadow(renderContext, light, lightIndex, shadowMaskView);
|
||||
|
||||
// Bind output
|
||||
context->SetRenderTarget(lightBuffer);
|
||||
context->SetRenderTarget(depthBufferHandle, lightBuffer);
|
||||
|
||||
// Set shadow mask
|
||||
context->BindSR(5, shadowMaskView);
|
||||
|
||||
Reference in New Issue
Block a user