Diligent Engine
 
Loading...
Searching...
No Matches
Diligent::DepthRangeCalculator Class Reference

#include <DepthRangeCalculator.hpp>

Classes

struct  ComputeRangeAttribs
 Attributes for ComputeRange() method. More...
 
struct  CreateInfo
 Depth range calculator create info. More...
 

Public Member Functions

 DepthRangeCalculator (const CreateInfo &CI) noexcept(false)
 Constructs a depth range calculator object.
 
bool IsReady () const
 Returns true if the depth range calculator is ready to be used.
 
RefCntAutoPtr< IShaderResourceBindingCreateSRB (ITextureView *pDepthBufferSRV, IBuffer *pCameraAttribs)
 Creates a shader resource binding object to use in ComputeRange() method.
 
void ComputeRange (const ComputeRangeAttribs &Attribs)
 Computes the depth range.
 
IBufferGetDepthRangeBuffer () const
 Returns the depth range buffer.
 
const DepthRange & GetDepthRange (IDeviceContext *pCtx=nullptr)
 Returns the depth range read back to the CPU.
 

Detailed Description

Computes depth range from the scene depth buffer.

The class uses a compute shader to read the depth buffer and compute the near and far depth values. It writes the results to a buffer with the following layout:

struct DepthRange
{
    float SceneNearZ;
    float SceneFarZ;
    float SceneNearDepth;
    float SceneFarDepth;
};
  • SceneNearZ is always less than SceneFarZ.
  • SceneNearDepth is the depth value corresponding to SceneNearZ.
  • SceneFarDepth is the depth value corresponding to SceneFarZ.
  • Note that if reverse depth is used, SceneNearDepth will be greater than SceneFarDepth.
Remarks
SceneNearZ and SceneFarZ must be positive values.

Constructor & Destructor Documentation

◆ DepthRangeCalculator()

Diligent::DepthRangeCalculator::DepthRangeCalculator ( const CreateInfo & CI)

Constructs a depth range calculator object.

Parameters
[in]CICreate info.

In case of failure, an exception is thrown.

Member Function Documentation

◆ ComputeRange()

void Diligent::DepthRangeCalculator::ComputeRange ( const ComputeRangeAttribs & Attribs)

Computes the depth range.

Parameters
[in]AttribsMethod attributes.

The near/far depth values are written to the depth range buffer. If the ReadBackData option was set to true in the CreateInfo structure, the depth range will also be read back to the CPU and can be accessed using the GetDepthRange() method.

Note that the data read back to the CPU is typically a few frames behind the GPU.

◆ GetDepthRange()

const DepthRangeCalculator::DepthRange & Diligent::DepthRangeCalculator::GetDepthRange ( IDeviceContext * pCtx = nullptr)

Returns the depth range read back to the CPU.

Parameters
[in]pCtxIf not null, the function will poll the read back queue for the latest data.
Returns
The depth range read back to the CPU.