Overte C++ Documentation
HazeStage.h
1 //
2 // HazeStage.h
3 
4 // Created by Nissim Hadar on 9/26/2017.
5 // Copyright 2015 High Fidelity, Inc.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #ifndef hifi_render_utils_HazeStage_h
12 #define hifi_render_utils_HazeStage_h
13 
14 #include <graphics/Stage.h>
15 #include <set>
16 #include <unordered_map>
17 #include <render/IndexedContainer.h>
18 #include <render/Stage.h>
19 
20 #include <render/Forward.h>
21 #include <render/DrawTask.h>
22 #include <graphics/Haze.h>
23 
24 // Haze stage to set up haze-related rendering tasks
25 class HazeStage : public render::Stage {
26 public:
27  static std::string _stageName;
28  static const std::string& getName() { return _stageName; }
29 
30  using Index = render::indexed_container::Index;
31  static const Index INVALID_INDEX;
32  static bool isIndexInvalid(Index index) { return index == INVALID_INDEX; }
33 
34  using HazePointer = graphics::HazePointer;
35  using Hazes = render::indexed_container::IndexedPointerVector<graphics::Haze>;
36  using HazeMap = std::unordered_map<HazePointer, Index>;
37 
38  using HazeIndices = std::vector<Index>;
39 
40  Index findHaze(const HazePointer& haze) const;
41  Index addHaze(const HazePointer& haze);
42 
43  HazePointer removeHaze(Index index);
44 
45  bool checkHazeId(Index index) const { return _hazes.checkIndex(index); }
46 
47  Index getNumHazes() const { return _hazes.getNumElements(); }
48  Index getNumFreeHazes() const { return _hazes.getNumFreeIndices(); }
49  Index getNumAllocatedHazes() const { return _hazes.getNumAllocatedIndices(); }
50 
51  HazePointer getHaze(Index hazeId) const {
52  return _hazes.get(hazeId);
53  }
54 
55  Hazes _hazes;
56  HazeMap _hazeMap;
57 
58  class Frame {
59  public:
60  Frame() {}
61 
62  void clear() { _hazes.clear(); }
63 
64  void pushHaze(HazeStage::Index index) { _hazes.emplace_back(index); }
65 
66  HazeStage::HazeIndices _hazes;
67  };
68  using FramePointer = std::shared_ptr<Frame>;
69 
70  Frame _currentFrame;
71 };
72 using HazeStagePointer = std::shared_ptr<HazeStage>;
73 
74 class HazeStageSetup {
75 public:
76  using JobModel = render::Job::Model<HazeStageSetup>;
77 
78  HazeStageSetup();
79  void run(const render::RenderContextPointer& renderContext);
80 
81 protected:
82 };
83 
84 class FetchHazeConfig : public render::Job::Config {
85  Q_OBJECT
86 
87  Q_PROPERTY(glm::vec3 hazeColor MEMBER hazeColor WRITE setHazeColor NOTIFY dirty);
88  Q_PROPERTY(float hazeGlareAngle MEMBER hazeGlareAngle WRITE setHazeGlareAngle NOTIFY dirty);
89 
90  Q_PROPERTY(glm::vec3 hazeGlareColor MEMBER hazeGlareColor WRITE setHazeGlareColor NOTIFY dirty);
91  Q_PROPERTY(float hazeBaseReference MEMBER hazeBaseReference WRITE setHazeBaseReference NOTIFY dirty);
92 
93  Q_PROPERTY(bool isHazeActive MEMBER isHazeActive WRITE setHazeActive NOTIFY dirty);
94  Q_PROPERTY(bool isAltitudeBased MEMBER isAltitudeBased WRITE setAltitudeBased NOTIFY dirty);
95  Q_PROPERTY(bool isHazeAttenuateKeyLight MEMBER isHazeAttenuateKeyLight WRITE setHazeAttenuateKeyLight NOTIFY dirty);
96  Q_PROPERTY(bool isModulateColorActive MEMBER isModulateColorActive WRITE setModulateColorActive NOTIFY dirty);
97  Q_PROPERTY(bool isHazeEnableGlare MEMBER isHazeEnableGlare WRITE setHazeEnableGlare NOTIFY dirty);
98 
99  Q_PROPERTY(float hazeRange MEMBER hazeRange WRITE setHazeRange NOTIFY dirty);
100  Q_PROPERTY(float hazeHeight MEMBER hazeHeight WRITE setHazeAltitude NOTIFY dirty);
101 
102  Q_PROPERTY(float hazeKeyLightRange MEMBER hazeKeyLightRange WRITE setHazeKeyLightRange NOTIFY dirty);
103  Q_PROPERTY(float hazeKeyLightAltitude MEMBER hazeKeyLightAltitude WRITE setHazeKeyLightAltitude NOTIFY dirty);
104 
105  Q_PROPERTY(float hazeBackgroundBlend MEMBER hazeBackgroundBlend WRITE setHazeBackgroundBlend NOTIFY dirty);
106 
107 public:
108  FetchHazeConfig() : render::Job::Config() {}
109 
110  glm::vec3 hazeColor{ graphics::Haze::INITIAL_HAZE_COLOR };
111  float hazeGlareAngle{ graphics::Haze::INITIAL_HAZE_GLARE_ANGLE };
112 
113  glm::vec3 hazeGlareColor{ graphics::Haze::INITIAL_HAZE_GLARE_COLOR };
114  float hazeBaseReference{ graphics::Haze::INITIAL_HAZE_BASE_REFERENCE };
115 
116  bool isHazeActive{ false };
117  bool isAltitudeBased{ false };
118  bool isHazeAttenuateKeyLight{ false };
119  bool isModulateColorActive{ false };
120  bool isHazeEnableGlare{ false };
121 
122  float hazeRange{ graphics::Haze::INITIAL_HAZE_RANGE };
123  float hazeHeight{ graphics::Haze::INITIAL_HAZE_HEIGHT };
124 
125  float hazeKeyLightRange{ graphics::Haze::INITIAL_KEY_LIGHT_RANGE };
126  float hazeKeyLightAltitude{ graphics::Haze::INITIAL_KEY_LIGHT_ALTITUDE };
127 
128  float hazeBackgroundBlend{ graphics::Haze::INITIAL_HAZE_BACKGROUND_BLEND };
129 
130 public slots:
131  void setHazeColor(const glm::vec3 value) { hazeColor = value; emit dirty(); }
132  void setHazeGlareAngle(const float value) { hazeGlareAngle = value; emit dirty(); }
133 
134  void setHazeGlareColor(const glm::vec3 value) { hazeGlareColor = value; emit dirty(); }
135  void setHazeBaseReference(const float value) { hazeBaseReference = value; ; emit dirty(); }
136 
137  void setHazeActive(const bool active) { isHazeActive = active; emit dirty(); }
138  void setAltitudeBased(const bool active) { isAltitudeBased = active; emit dirty(); }
139  void setHazeAttenuateKeyLight(const bool active) { isHazeAttenuateKeyLight = active; emit dirty(); }
140  void setModulateColorActive(const bool active) { isModulateColorActive = active; emit dirty(); }
141  void setHazeEnableGlare(const bool active) { isHazeEnableGlare = active; emit dirty(); }
142 
143  void setHazeRange(const float value) { hazeRange = value; emit dirty(); }
144  void setHazeAltitude(const float value) { hazeHeight = value; emit dirty(); }
145 
146  void setHazeKeyLightRange(const float value) { hazeKeyLightRange = value; emit dirty(); }
147  void setHazeKeyLightAltitude(const float value) { hazeKeyLightAltitude = value; emit dirty(); }
148 
149  void setHazeBackgroundBlend(const float value) { hazeBackgroundBlend = value; ; emit dirty(); }
150 
151 signals:
152  void dirty();
153 };
154 #endif