31 for (
U16 i = 0; i < sampleCount; ++i) {
56 _blur[0] = config.FullRes.Blur;
57 _blur[1] = config.HalfRes.Blur;
58 _radius[0] = config.FullRes.Radius;
59 _radius[1] = config.HalfRes.Radius;
60 _power[0] = config.FullRes.Power;
61 _power[1] = config.HalfRes.Power;
62 _bias[0] = config.FullRes.Bias;
63 _bias[1] = config.HalfRes.Bias;
69 std::array<vec4<F32>,
SQUARED(SSAO_NOISE_SIZE)> noiseData;
73 noise.set(
Random(-1.f, 1.f),
Random(-1.f, 1.f), 0.f, 1.f);
123 desc.
_name =
"SSAO_Out";
129 desc.
_name =
"SSAO_Blur_Buffer";
132 desc.
_name =
"SSAO_Out_HalfRes";
149 desc.
_name =
"HalfRes_Normals_Depth";
167 ssaoShaderDescriptor.
_modules.push_back(vertModule);
168 ssaoShaderDescriptor.
_modules.push_back(fragModule);
171 ssaoGenerate.waitForReady(
false);
178 fragModule.
_defines.emplace_back(
"COMPUTE_HALF_RES");
181 ssaoShaderDescriptor.
_modules.push_back(vertModule);
182 ssaoShaderDescriptor.
_modules.push_back(fragModule);
185 ssaoGenerateHalfRes.waitForReady(
false);
190 fragModule.
_variant =
"SSAOBlur.Nvidia";
195 ssaoShaderDescriptor.
_modules.push_back(vertModule);
196 ssaoShaderDescriptor.
_modules.push_back(fragModule);
198 ssaoShaderDescriptor.
_modules.back()._defines.emplace_back(
"HORIZONTAL");
200 ssaoBlurH.waitForReady(
false);
203 ssaoShaderDescriptor.
_modules.back()._defines.back() = {
"VERTICAL" };
206 ssaoBlurV.waitForReady(
false);
210 fragModule.
_variant =
"SSAOPassThrough";
214 ssaoShaderDescriptor.
_modules.push_back(vertModule);
215 ssaoShaderDescriptor.
_modules.push_back(fragModule);
218 ssaoPassThrough.waitForReady(
false);
223 fragModule.
_variant =
"SSAODownsample";
227 ssaoShaderDescriptor.
_modules.push_back(vertModule);
228 ssaoShaderDescriptor.
_modules.push_back(fragModule);
231 ssaoDownSample.waitForReady(
false);
236 fragModule.
_variant =
"SSAOUpsample";
240 ssaoShaderDescriptor.
_modules.push_back(vertModule);
241 ssaoShaderDescriptor.
_modules.push_back(fragModule);
244 ssaoUpSample.waitForReady(
false);
422 if (blurResults() != state)
424 _blur[_genHalfRes ? 1 : 0] = state;
427 _context.context().config().rendering.postFX.ssao.HalfRes.Blur = state;
431 _context.context().config().rendering.postFX.ssao.FullRes.Blur = state;
433 _context.context().config().changed(
true);
493 val = std::max(0.01f, val);
513 val = std::max(0.01f, val);
543 renderPassCmd->
_name =
"DO_SSAO_CLEAR_TARGET";
549 GFX::EnqueueCommand<GFX::EndRenderPassCommand>(bufferInOut);
568 renderPassCmd->
_name =
"DO_SSAO_DOWNSAMPLE_NORMALS";
573 GFX::EnqueueCommand<GFX::BindPipelineCommand>(bufferInOut)->_pipeline =
_downsamplePipeline;
575 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>(bufferInOut);
579 Set( binding.
_data, depthAtt->texture(), depthAtt->_descriptor._sampler );
583 Set( binding.
_data, normalsAtt->texture(), normalsAtt->_descriptor._sampler );
586 GFX::EnqueueCommand<GFX::DrawCommand>(bufferInOut)->_drawCommands.emplace_back();
587 GFX::EnqueueCommand<GFX::EndRenderPassCommand>(bufferInOut);
591 renderPassCmd->
_name =
"DO_SSAO_HALF_RES_CALC";
605 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>(bufferInOut);
613 Set( binding.
_data, halfDepthAtt->texture(), halfDepthAtt->_descriptor._sampler );
616 GFX::EnqueueCommand<GFX::DrawCommand>(bufferInOut)->_drawCommands.emplace_back();
617 GFX::EnqueueCommand<GFX::EndRenderPassCommand>(bufferInOut);
621 renderPassCmd->
_name =
"DO_SSAO_UPSAMPLE_AO";
626 GFX::EnqueueCommand<GFX::BindPipelineCommand>(bufferInOut)->_pipeline =
_upsamplePipeline;
638 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>(bufferInOut);
642 Set( binding.
_data, halfResAOAtt->texture(), linearSampler );
646 Set( binding.
_data, depthAtt->texture(), depthAtt->_descriptor._sampler );
650 Set( binding.
_data, halfDepthAtt->texture(), halfDepthAtt->_descriptor._sampler );
654 Set( binding.
_data, halfResAOAtt->texture(), halfResAOAtt->_descriptor._sampler );
656 GFX::EnqueueCommand<GFX::DrawCommand>(bufferInOut)->_drawCommands.emplace_back();
657 GFX::EnqueueCommand<GFX::EndRenderPassCommand>(bufferInOut);
664 renderPassCmd->
_name =
"DO_SSAO_CALC";
671 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>(bufferInOut);
679 Set( binding.
_data, depthAtt->texture(), depthAtt->_descriptor._sampler );
683 Set( binding.
_data, normalsAtt->texture(), normalsAtt->_descriptor._sampler );
691 GFX::EnqueueCommand<GFX::DrawCommand>(bufferInOut)->_drawCommands.emplace_back();
692 GFX::EnqueueCommand<GFX::EndRenderPassCommand>(bufferInOut);
706 renderPassCmd->
_name =
"DO_SSAO_BLUR_HORIZONTAL";
717 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>(bufferInOut);
721 Set( binding.
_data, ssaoAtt->texture(), ssaoAtt->_descriptor._sampler );
725 Set( binding.
_data, depthAtt->texture(), depthAtt->_descriptor._sampler );
729 Set( binding.
_data, normalsAtt->texture(), normalsAtt->_descriptor._sampler );
732 GFX::EnqueueCommand<GFX::DrawCommand>(bufferInOut)->_drawCommands.emplace_back();
733 GFX::EnqueueCommand<GFX::EndRenderPassCommand>(bufferInOut);
737 renderPassCmd->
_name =
"DO_SSAO_BLUR_VERTICAL";
749 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>(bufferInOut);
753 Set( binding.
_data, horizBlur->texture(), ssaoAtt->_descriptor._sampler );
757 Set( binding.
_data, depthAtt->texture(), depthAtt->_descriptor._sampler );
761 Set( binding.
_data, normalsAtt->texture(), normalsAtt->_descriptor._sampler );
764 GFX::EnqueueCommand<GFX::DrawCommand>(bufferInOut)->_drawCommands.emplace_back();
765 GFX::EnqueueCommand<GFX::EndRenderPassCommand>(bufferInOut);
771 renderPassCmd->
_name =
"DO_SSAO_PASS_THROUGH";
778 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>(bufferInOut);
782 Set( binding.
_data, ssaoAtt->texture(), ssaoAtt->_descriptor._sampler );
784 GFX::EnqueueCommand<GFX::DrawCommand>(bufferInOut)->_drawCommands.emplace_back();
785 GFX::EnqueueCommand<GFX::EndRenderPassCommand>(bufferInOut);
#define WAIT_FOR_CONDITION(...)
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
GFXRTPool & renderTargetPool() noexcept
Pipeline * newPipeline(const PipelineDescriptor &descriptor)
Create and return a new graphics pipeline. This is only used for caching and doesn't use the object a...
const RenderStateBlock & get2DStateBlock() const noexcept
RenderTarget * getRenderTarget(const RenderTargetID target) const
RenderTargetHandle allocateRT(const RenderTargetDescriptor &descriptor)
bool deallocateRT(RenderTargetHandle &handle)
PlatformContext & context() noexcept
Configuration & config() noexcept
RenderTargetHandle screenRT() const noexcept
virtual void reshape(U16 width, U16 height)
virtual void prepare(PlayerIndex idx, GFX::CommandBuffer &bufferInOut)
virtual bool ready() const noexcept
RTAttachment * getAttachment(RTAttachmentType type, RTColourAttachmentSlot slot=RTColourAttachmentSlot::SLOT_0) const
bool resize(U16 width, U16 height)
Resize all attachments.
U16 getWidth() const noexcept
U16 getHeight() const noexcept
F32 bias() const noexcept
void prepare(PlayerIndex idx, GFX::CommandBuffer &bufferInOut) override
F32 blurSharpness() const noexcept
I32 blurKernelSize() const noexcept
RenderTargetHandle _ssaoHalfResOutput
~SSAOPreRenderOperator() override
SamplerDescriptor _noiseSampler
Handle< ShaderProgram > _ssaoUpSampleShader
bool blurResults() const noexcept
Pipeline * _generateFullResPipeline
Pipeline * _blurVerticalPipeline
UniformData _ssaoGenerateConstants
Handle< Texture > _noiseTexture
Handle< ShaderProgram > _ssaoBlurShaderVertical
RenderTargetHandle _halfDepthAndNormals
F32 blurThreshold() const noexcept
void reshape(U16 width, U16 height) override
F32 fadeStart() const noexcept
RenderTargetHandle _ssaoBlurBuffer
RenderTargetHandle _ssaoOutput
Handle< ShaderProgram > _ssaoGenerateHalfResShader
Handle< ShaderProgram > _ssaoGenerateShader
Pipeline * _passThroughPipeline
U8 sampleCount() const noexcept
bool ready() const noexcept override
Handle< ShaderProgram > _ssaoDownSampleShader
Pipeline * _generateHalfResPipeline
Pipeline * _blurHorizontalPipeline
F32 radius() const noexcept
Handle< ShaderProgram > _ssaoPassThroughShader
Handle< ShaderProgram > _ssaoBlurShaderHorizontal
Pipeline * _downsamplePipeline
F32 power() const noexcept
UniformData _ssaoBlurConstants
SSAOPreRenderOperator(GFXDevice &context, PreRenderBatch &parent)
bool execute(PlayerIndex idx, const CameraSnapshot &cameraSnapshot, const RenderTargetHandle &input, const RenderTargetHandle &output, GFX::CommandBuffer &bufferInOut) override
Return true if we rendered into "output".
F32 maxRange() const noexcept
bool genHalfRes() const noexcept
Pipeline * _upsamplePipeline
vec3 & normalize() noexcept
transform the vector to unit length
void set(const T *v) noexcept
set the 3 components of the vector manually using a source pointer to a (large enough) array
Str StringFormat(const char *fmt, Args &&...args)
const vector< vec4< F32 > > & ComputeKernel(const U8 sampleCount)
vector< vec4< F32 > > g_kernels
constexpr U8 SSAO_BLUR_SIZE
constexpr U8 SSAO_NOISE_SIZE
constexpr U8 MAX_KERNEL_SIZE
constexpr U8 MIN_KERNEL_SIZE
Handle console commands that start with a forward slash.
FORCE_INLINE void DestroyResource(Handle< T > &handle, const bool immediate=false)
static constexpr U32 RT_DEPTH_ATTACHMENT_IDX
constexpr T SQUARED(T input) noexcept
@ RES_LOADED
The resource is available for usage.
constexpr F32 to_F32(const T value)
eastl::vector< Type > vector
void Set(DescriptorSetBindingData &dataInOut, ShaderBuffer *buffer, const BufferRange range) noexcept
constexpr U64 _ID(const char *const str, const U64 value=val_64_const) noexcept
DescriptorSetBinding & AddBinding(DescriptorSet &setInOut, U8 slot, U16 stageVisibilityMask)
FORCE_INLINE Handle< T > CreateResource(const ResourceDescriptor< T > &descriptor, bool &wasInCache, std::atomic_uint &taskCounter)
::value constexpr T CLAMPED(T n, T min, T max) noexcept
@ FILTER_SS_AMBIENT_OCCLUSION
RTClearEntry DEFAULT_CLEAR_ENTRY
T FastLerp(T v1, T v2, U t) noexcept
bool COMPARE(T X, U Y) noexcept
FORCE_INLINE T * Get(const Handle< T > handle)
constexpr auto to_base(const Type value) -> Type
mat4< F32 > _projectionMatrix
mat4< F32 > _invProjectionMatrix
struct Divide::Configuration::Rendering::PostFX::SSAO ssao
struct Divide::Configuration::Rendering::PostFX postFX
struct Divide::Configuration::Rendering rendering
DescriptorSetBindingData _data
RTDrawDescriptor _descriptor
RTClearDescriptor _clearDescriptor
PushConstantsStruct _fastData
UniformData * _uniformData
PrimitiveTopology _primitiveTopology
Handle< ShaderProgram > _shaderProgramHandle
RenderStateBlock _stateBlock
vector< ShaderModuleDescriptor > _modules
MipMappingState _mipMappingState
InternalRTAttachmentDescriptors _attachments
static RenderTargetID NORMALS_RESOLVED
static RenderTargetID SSAO_RESULT
PropertyDescriptor< T > _propertyDescriptor
TextureFilter _minFilter
Texture filtering mode.
TextureWrap _wrapU
Texture wrap mode (Or S-R-T)
U8 _anisotropyLevel
The value must be in the range [0...255] and is automatically clamped by the max HW supported level.
TextureMipSampling _mipSampling