Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
MotionBlurPreRenderOperator.cpp
Go to the documentation of this file.
1
2
4
7
13
17
18namespace Divide {
19
22{
23 ShaderModuleDescriptor vertModule = {};
25 vertModule._sourceFile = "baseVertexShaders.glsl";
26 vertModule._variant = "FullScreenQuad";
27
28 ShaderModuleDescriptor fragModule = {};
30 fragModule._sourceFile = "blur.glsl";
31 fragModule._variant = "ObjectMotionBlur";
32
33 ShaderProgramDescriptor shaderDescriptor = {};
34 shaderDescriptor._modules.push_back(vertModule);
35 shaderDescriptor._modules.push_back(fragModule);
36 shaderDescriptor._globalDefines.emplace_back( "dvd_velocityScale PushData0[0].x" );
37 shaderDescriptor._globalDefines.emplace_back( "dvd_maxSamples int(PushData0[0].y)" );
38
39 ResourceDescriptor<ShaderProgram> motionBlur("MotionBlur", shaderDescriptor );
40 motionBlur.waitForReady(false);
41 _blurApply = CreateResource(motionBlur);
42
43 PipelineDescriptor pipelineDescriptor = {};
44 pipelineDescriptor._stateBlock = _context.get2DStateBlock();
45 pipelineDescriptor._shaderProgramHandle = _blurApply;
47
49
51}
52
54{
56}
57
59{
60 if (_blurApplyPipelineCmd._pipeline != nullptr)
61 {
63 }
64
65 return false;
66}
67
69{
70 NOP();
71}
72
73bool MotionBlurPreRenderOperator::execute([[maybe_unused]] const PlayerIndex idx, [[maybe_unused]] const CameraSnapshot& cameraSnapshot, const RenderTargetHandle& input, const RenderTargetHandle& output, GFX::CommandBuffer& bufferInOut)
74{
77
78 const F32 fps = _context.context().app().timer().getFps();
80 const F32 velocityFactor = fps / Config::TARGET_FRAME_RATE * velocityScale;
81
82 GFX::BeginRenderPassCommand* beginRenderPassCmd = GFX::EnqueueCommand<GFX::BeginRenderPassCommand>(bufferInOut);
83 beginRenderPassCmd->_name = "DO_MOTION_BLUR_PASS";
84 beginRenderPassCmd->_target = output._targetID;
85 beginRenderPassCmd->_descriptor = _screenOnlyDraw;
87
89
90 auto cmd = GFX::EnqueueCommand<GFX::BindShaderResourcesCommand>( bufferInOut );
91 cmd->_usage = DescriptorSetUsage::PER_DRAW;
92 {
94 Set( binding._data, screenAtt->texture(), screenAtt->_descriptor._sampler );
95 }
96 {
98 Set( binding._data, velocityAtt->texture(), velocityAtt->_descriptor._sampler );
99 }
100
101 PushConstantsStruct& params = GFX::EnqueueCommand<GFX::SendPushConstantsCommand>( bufferInOut )->_fastData;
102 params.data[0]._vec[0].xy.set( velocityFactor, to_F32( maxSamples() ) );
103
104 GFX::EnqueueCommand<GFX::DrawCommand>(bufferInOut)->_drawCommands.emplace_back();
105 GFX::EnqueueCommand<GFX::EndRenderPassCommand>(bufferInOut);
106
107 return true;
108}
109}
#define NOP()
Time::ApplicationTimer & timer() noexcept
Definition: Application.inl:92
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
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...
Definition: GFXDevice.cpp:3074
const RenderStateBlock & get2DStateBlock() const noexcept
Definition: GFXDevice.inl:123
bool execute(PlayerIndex idx, const CameraSnapshot &cameraSnapshot, const RenderTargetHandle &input, const RenderTargetHandle &output, GFX::CommandBuffer &bufferInOut) override
Return true if we rendered into "output".
MotionBlurPreRenderOperator(GFXDevice &context, PreRenderBatch &parent)
PlatformContext & context() noexcept
Application & app() noexcept
Configuration & config() noexcept
RenderTargetHandle screenRT() const noexcept
virtual bool ready() const noexcept
RTDrawDescriptor _screenOnlyDraw
RTAttachment * getAttachment(RTAttachmentType type, RTColourAttachmentSlot slot=RTColourAttachmentSlot::SLOT_0) const
vec4< T > _vec[4]
Definition: MathMatrices.h:709
void set(const T *v) noexcept
set the 2 components of the vector manually using a source pointer to a (large enough) array
Definition: MathVectors.h:335
vec2< T > xy
Definition: MathVectors.h:1366
constexpr U16 TARGET_FRAME_RATE
Application desired framerate for physics and input simulations.
Definition: config.h:97
FORCE_INLINE T * EnqueueCommand(CommandBuffer &buffer)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
FORCE_INLINE void DestroyResource(Handle< T > &handle, const bool immediate=false)
constexpr F32 to_F32(const T value)
Project & parent
Definition: DefaultScene.h:41
void Set(DescriptorSetBindingData &dataInOut, ShaderBuffer *buffer, const BufferRange range) noexcept
DescriptorSetBinding & AddBinding(DescriptorSet &setInOut, U8 slot, U16 stageVisibilityMask)
FORCE_INLINE Handle< T > CreateResource(const ResourceDescriptor< T > &descriptor, bool &wasInCache, std::atomic_uint &taskCounter)
RTClearEntry DEFAULT_CLEAR_ENTRY
constexpr auto to_base(const Type value) -> Type
F32 velocityScale
struct Divide::Configuration::Rendering::PostFX::MotionBlur motionBlur
struct Divide::Configuration::Rendering::PostFX postFX
struct Divide::Configuration::Rendering rendering
DescriptorSetBindingData _data
RTClearDescriptor _clearDescriptor
Definition: Commands.inl:97
static constexpr RTColourAttachmentSlot ALBEDO
Definition: GFXDevice.h:228
static constexpr RTColourAttachmentSlot VELOCITY
Definition: GFXDevice.h:229
PrimitiveTopology _primitiveTopology
Definition: Pipeline.h:48
Handle< ShaderProgram > _shaderProgramHandle
Definition: Pipeline.h:47
RenderStateBlock _stateBlock
Definition: Pipeline.h:46
vector< ShaderModuleDescriptor > _modules
RenderTargetID _targetID
Definition: RenderTarget.h:47