Overte C++ Documentation
ToneMapAndResampleTask.h
1 //
2 // ToneMapAndResample.h
3 // libraries/render-utils/src
4 //
5 // Created by Anna Brewer on 7/3/19.
6 // Copyright 2019 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_ToneMapAndResample_h
13 #define hifi_ToneMapAndResample_h
14 
15 #include <DependencyManager.h>
16 #include <NumericalConstants.h>
17 
18 #include <gpu/Resource.h>
19 #include <gpu/Pipeline.h>
20 #include <render/Forward.h>
21 #include <render/DrawTask.h>
22 
23 enum class ToneCurve {
24  // Different tone curve available
25  None,
26  Gamma22,
27  Reinhard,
28  Filmic,
29 };
30 
31 class ToneMappingConfig : public render::Job::Config {
32  Q_OBJECT
33  Q_PROPERTY(float exposure MEMBER exposure WRITE setExposure);
34  Q_PROPERTY(int curve MEMBER curve WRITE setCurve);
35 
36 public:
37  ToneMappingConfig() : render::Job::Config(true) {}
38 
39  void setExposure(float newExposure) { exposure = newExposure; emit dirty(); }
40  void setCurve(int newCurve) { curve = std::max((int)ToneCurve::None, std::min((int)ToneCurve::Filmic, newCurve)); emit dirty(); }
41 
42 
43  float exposure{ 0.0f };
44  int curve{ (int)ToneCurve::Gamma22 };
45 
46 signals:
47  void dirty();
48 };
49 
50 class ToneMapAndResample {
51 public:
52  ToneMapAndResample();
53  virtual ~ToneMapAndResample() {}
54 
55  void render(RenderArgs* args, const gpu::TexturePointer& lightingBuffer, gpu::FramebufferPointer& destinationBuffer);
56 
57  void setExposure(float exposure);
58  float getExposure() const { return _parametersBuffer.get<Parameters>()._exposure; }
59 
60  void setToneCurve(ToneCurve curve);
61  ToneCurve getToneCurve() const { return (ToneCurve)_parametersBuffer.get<Parameters>()._toneCurve; }
62 
63  // Inputs: lightingFramebuffer, destinationFramebuffer
64  using Input = render::VaryingSet2<gpu::FramebufferPointer, gpu::FramebufferPointer>;
65  using Output = gpu::FramebufferPointer;
66  using Config = ToneMappingConfig;
67  using JobModel = render::Job::ModelIO<ToneMapAndResample, Input, Output, Config>;
68 
69  void configure(const Config& config);
70  void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output);
71 
72 protected:
73  static gpu::PipelinePointer _pipeline;
74  static gpu::PipelinePointer _mirrorPipeline;
75 
76  gpu::FramebufferPointer _destinationFrameBuffer;
77 
78  float _factor{ 2.0f };
79 
80  gpu::FramebufferPointer getResampledFrameBuffer(const gpu::FramebufferPointer& sourceFramebuffer);
81 
82 private:
83  gpu::PipelinePointer _blitLightBuffer;
84 
85  // Class describing the uniform buffer with all the parameters common to the tone mapping shaders
86  class Parameters {
87  public:
88  float _exposure = 0.0f;
89  float _twoPowExposure = 1.0f;
90  glm::vec2 spareA;
91  int _toneCurve = (int)ToneCurve::Gamma22;
92  glm::vec3 spareB;
93 
94  Parameters() {}
95  };
96 
97  typedef gpu::BufferView UniformBufferView;
98  gpu::BufferView _parametersBuffer;
99 
100  void init();
101 };
102 
103 #endif // hifi_ToneMapAndResample_h