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 #include "TonemappingStage.h"
24 
25 class ToneMappingConfig : public render::Job::Config {
26  Q_OBJECT
27  Q_PROPERTY(bool debug MEMBER debug WRITE setDebug NOTIFY dirty);
28  Q_PROPERTY(int curve MEMBER curve WRITE setCurve NOTIFY dirty);
29  Q_PROPERTY(float exposure MEMBER exposure WRITE setExposure NOTIFY dirty);
30 
31 public:
32  ToneMappingConfig() : render::Job::Config(true) {}
33 
34  void setDebug(bool newDebug) { debug = newDebug; emit dirty(); }
35  void setCurve(int newCurve) { curve = std::max(0, std::min((int)TonemappingCurve::FILMIC, newCurve)); emit dirty(); }
36  void setExposure(float newExposure) { exposure = newExposure; emit dirty(); }
37 
38  bool debug { false };
39  int curve { (int)TonemappingCurve::SRGB };
40  float exposure { 0.0f };
41 
42 signals:
43  void dirty();
44 };
45 
46 class ToneMapAndResample {
47 public:
48  ToneMapAndResample();
49  virtual ~ToneMapAndResample() {}
50 
51  void setCurve(TonemappingCurve curve);
52  void setExposure(float exposure);
53 
54  // Inputs: lightingFramebuffer, destinationFramebuffer, tonemappingFrame
55  using Input = render::VaryingSet3<gpu::FramebufferPointer, gpu::FramebufferPointer, TonemappingStage::FramePointer>;
56  using Output = gpu::FramebufferPointer;
57  using Config = ToneMappingConfig;
58  using JobModel = render::Job::ModelIO<ToneMapAndResample, Input, Output, Config>;
59 
60  void configure(const Config& config);
61  void run(const render::RenderContextPointer& renderContext, const Input& input, Output& output);
62 
63 protected:
64  static gpu::PipelinePointer _pipeline;
65  static gpu::PipelinePointer _mirrorPipeline;
66 
67  gpu::FramebufferPointer _destinationFrameBuffer;
68 
69 private:
70  float _exposure { 0.0f };
71 
72  bool _debug { false };
73  TonemappingCurve _debugCurve { TonemappingCurve::SRGB };
74  float _debugExposure { 0.0f };
75 
76  // Class describing the uniform buffer with all the parameters common to the tone mapping shaders
77  class Parameters {
78  public:
79  float _twoPowExposure = 1.0f;
80  int _toneCurve = (int)TonemappingCurve::SRGB;
81 
82  Parameters() {}
83  };
84 
85  typedef gpu::BufferView UniformBufferView;
86  gpu::BufferView _parametersBuffer;
87 
88  void init();
89 };
90 
91 #endif // hifi_ToneMapAndResample_h