Overte C++ Documentation
VelocityBufferPass.h
1 //
2 // VelocityBufferPass.h
3 // libraries/render-utils/src/
4 //
5 // Created by Sam Gateau 8/15/2017.
6 // Copyright 2017 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_VelocityBufferPass_h
13 #define hifi_VelocityBufferPass_h
14 
15 #include "SurfaceGeometryPass.h"
16 
17 
18 // VelocityFramebuffer is a helper class gathering in one place theframebuffers and targets describing the surface geometry linear depth
19 // from a z buffer
20 class VelocityFramebuffer {
21 public:
22  VelocityFramebuffer();
23 
24  gpu::FramebufferPointer getVelocityFramebuffer();
25  gpu::TexturePointer getVelocityTexture();
26 
27  // Update the depth buffer which will drive the allocation of all the other resources according to its size.
28  void updatePrimaryDepth(const gpu::TexturePointer& depthBuffer);
29 
30  gpu::TexturePointer getPrimaryDepthTexture();
31  const glm::ivec2& getDepthFrameSize() const { return _frameSize; }
32 
33  void setResolutionLevel(int level);
34  int getResolutionLevel() const { return _resolutionLevel; }
35 
36 protected:
37  void clear();
38  void allocate();
39 
40  gpu::TexturePointer _primaryDepthTexture;
41 
42  gpu::FramebufferPointer _velocityFramebuffer;
43  gpu::TexturePointer _velocityTexture;
44 
45  glm::ivec2 _frameSize;
46  glm::ivec2 _halfFrameSize;
47  int _resolutionLevel{ 0 };
48 };
49 
50 using VelocityFramebufferPointer = std::shared_ptr<VelocityFramebuffer>;
51 
52 class VelocityBufferPassConfig : public render::GPUJobConfig {
53  Q_OBJECT
54  Q_PROPERTY(float depthThreshold MEMBER depthThreshold NOTIFY dirty)
55 
56 public:
57  VelocityBufferPassConfig() : render::GPUJobConfig(true) {}
58 
59  float depthThreshold{ 5.0f };
60 
61 signals:
62  void dirty();
63 };
64 
65 class VelocityBufferPass {
66 public:
67  using Inputs = render::VaryingSet2<DeferredFrameTransformPointer, DeferredFramebufferPointer>;
68  using Outputs = render::VaryingSet3<VelocityFramebufferPointer, gpu::FramebufferPointer, gpu::TexturePointer>;
69  using Config = VelocityBufferPassConfig;
70  using JobModel = render::Job::ModelIO<VelocityBufferPass, Inputs, Outputs, Config>;
71 
72  VelocityBufferPass();
73 
74  void configure(const Config& config);
75  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
76 
77 private:
78  typedef gpu::BufferView UniformBufferView;
79 
80  VelocityFramebufferPointer _velocityFramebuffer;
81 
82  const gpu::PipelinePointer& getCameraMotionPipeline(const render::RenderContextPointer& renderContext);
83  gpu::PipelinePointer _cameraMotionPipeline;
84 
85  gpu::RangeTimerPointer _gpuTimer;
86 };
87 
88 
89 #endif // hifi_VelocityBufferPass_h