Overte C++ Documentation
LightingModel.h
1 //
2 // LightingModel.h
3 // libraries/render-utils/src/
4 //
5 // Created by Sam Gateau 7/1/2016.
6 // Copyright 2016 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_LightingModel_h
13 #define hifi_LightingModel_h
14 
15 #include <gpu/Resource.h>
16 
17 #include <render/Forward.h>
18 #include <render/DrawTask.h>
19 
20 // LightingModel is a helper class gathering in one place the flags to enable the lighting contributions
21 class LightingModel {
22 public:
23  using UniformBufferView = gpu::BufferView;
24 
25  LightingModel();
26 
27 
28  void setUnlit(bool enable);
29  bool isUnlitEnabled() const;
30 
31  void setEmissive(bool enable);
32  bool isEmissiveEnabled() const;
33  void setLightmap(bool enable);
34  bool isLightmapEnabled() const;
35 
36  void setBackground(bool enable);
37  bool isBackgroundEnabled() const;
38 
39  void setHaze(bool enable);
40  bool isHazeEnabled() const;
41  void setBloom(bool enable);
42  bool isBloomEnabled() const;
43 
44  void setObscurance(bool enable);
45  bool isObscuranceEnabled() const;
46 
47  void setScattering(bool enable);
48  bool isScatteringEnabled() const;
49  void setDiffuse(bool enable);
50  bool isDiffuseEnabled() const;
51  void setSpecular(bool enable);
52  bool isSpecularEnabled() const;
53 
54  void setAlbedo(bool enable);
55  bool isAlbedoEnabled() const;
56 
57  void setMaterialTexturing(bool enable);
58  bool isMaterialTexturingEnabled() const;
59 
60  void setAmbientLight(bool enable);
61  bool isAmbientLightEnabled() const;
62  void setDirectionalLight(bool enable);
63  bool isDirectionalLightEnabled() const;
64  void setPointLight(bool enable);
65  bool isPointLightEnabled() const;
66  void setSpotLight(bool enable);
67  bool isSpotLightEnabled() const;
68 
69  void setShowLightContour(bool enable);
70  bool isShowLightContourEnabled() const;
71 
72  void setWireframe(bool enable);
73  bool isWireframeEnabled() const;
74  void setSkinning(bool enable);
75  bool isSkinningEnabled() const;
76  void setBlendshape(bool enable);
77  bool isBlendshapeEnabled() const;
78 
79 
80  void setAmbientOcclusion(bool enable);
81  bool isAmbientOcclusionEnabled() const;
82  void setShadow(bool enable);
83  bool isShadowEnabled() const;
84 
85  UniformBufferView getParametersBuffer() const { return _parametersBuffer; }
86  gpu::TexturePointer getAmbientFresnelLUT() const { return _ambientFresnelLUT; }
87 
88 protected:
89 
90 
91  // Class describing the uniform buffer with the transform info common to the AO shaders
92  // It s changing every frame
93  class Parameters {
94  public:
95  float enableUnlit{ 1.0f };
96  float enableEmissive{ 1.0f };
97  float enableLightmap{ 1.0f };
98  float enableBackground{ 1.0f };
99 
100  float enableScattering{ 1.0f };
101  float enableDiffuse{ 1.0f };
102  float enableSpecular{ 1.0f };
103  float enableAlbedo{ 1.0f };
104 
105  float enableAmbientLight{ 1.0f };
106  float enableDirectionalLight{ 1.0f };
107  float enablePointLight{ 1.0f };
108  float enableSpotLight{ 1.0f };
109 
110  float showLightContour { 0.0f }; // false by default
111 
112  float enableObscurance{ 1.0f };
113 
114  float enableMaterialTexturing { 1.0f };
115  float enableWireframe { 0.0f }; // false by default
116 
117  float enableHaze{ 1.0f };
118  float enableBloom{ 1.0f };
119  float enableSkinning{ 1.0f };
120  float enableBlendshape{ 1.0f };
121 
122  float enableAmbientOcclusion{ 0.0f }; // false by default
123  float enableShadow{ 1.0f };
124  float spare1{ 1.0f };
125  float spare2{ 1.0f };
126 
127  Parameters() {}
128  };
129  UniformBufferView _parametersBuffer;
130  static gpu::TexturePointer _ambientFresnelLUT;
131 };
132 
133 using LightingModelPointer = std::shared_ptr<LightingModel>;
134 
135 
136 
137 
138 class MakeLightingModelConfig : public render::Job::Config {
139  Q_OBJECT
140 
141  Q_PROPERTY(bool enableUnlit MEMBER enableUnlit NOTIFY dirty)
142  Q_PROPERTY(bool enableEmissive MEMBER enableEmissive NOTIFY dirty)
143  Q_PROPERTY(bool enableLightmap MEMBER enableLightmap NOTIFY dirty)
144  Q_PROPERTY(bool enableBackground MEMBER enableBackground NOTIFY dirty)
145  Q_PROPERTY(bool enableHaze MEMBER enableHaze NOTIFY dirty)
146 
147  Q_PROPERTY(bool enableObscurance MEMBER enableObscurance NOTIFY dirty)
148 
149  Q_PROPERTY(bool enableScattering MEMBER enableScattering NOTIFY dirty)
150  Q_PROPERTY(bool enableDiffuse MEMBER enableDiffuse NOTIFY dirty)
151  Q_PROPERTY(bool enableSpecular MEMBER enableSpecular NOTIFY dirty)
152  Q_PROPERTY(bool enableAlbedo MEMBER enableAlbedo NOTIFY dirty)
153 
154  Q_PROPERTY(bool enableMaterialTexturing MEMBER enableMaterialTexturing NOTIFY dirty)
155 
156  Q_PROPERTY(bool enableAmbientLight MEMBER enableAmbientLight NOTIFY dirty)
157  Q_PROPERTY(bool enableDirectionalLight MEMBER enableDirectionalLight NOTIFY dirty)
158  Q_PROPERTY(bool enablePointLight MEMBER enablePointLight NOTIFY dirty)
159  Q_PROPERTY(bool enableSpotLight MEMBER enableSpotLight NOTIFY dirty)
160 
161  Q_PROPERTY(bool enableWireframe MEMBER enableWireframe NOTIFY dirty)
162  Q_PROPERTY(bool showLightContour MEMBER showLightContour NOTIFY dirty)
163 
164  Q_PROPERTY(bool enableBloom MEMBER enableBloom NOTIFY dirty)
165  Q_PROPERTY(bool enableSkinning MEMBER enableSkinning NOTIFY dirty)
166  Q_PROPERTY(bool enableBlendshape MEMBER enableBlendshape NOTIFY dirty)
167 
168  Q_PROPERTY(bool enableAmbientOcclusion READ isAmbientOcclusionEnabled WRITE setAmbientOcclusion NOTIFY dirty)
169  Q_PROPERTY(bool enableShadow READ isShadowEnabled WRITE setShadow NOTIFY dirty)
170 
171 
172 public:
173  MakeLightingModelConfig() : render::Job::Config() {} // Make Lighting Model is always on
174 
175  bool enableUnlit{ true };
176  bool enableEmissive{ true };
177  bool enableLightmap{ true };
178  bool enableBackground{ true };
179  bool enableObscurance{ true };
180 
181  bool enableScattering{ true };
182  bool enableDiffuse{ true };
183  bool enableSpecular{ true };
184 
185  bool enableAlbedo{ true };
186  bool enableMaterialTexturing { true };
187 
188  bool enableAmbientLight{ true };
189  bool enableDirectionalLight{ true };
190  bool enablePointLight{ true };
191  bool enableSpotLight{ true };
192 
193  bool showLightContour { false }; // false by default
194 
195  bool enableWireframe { false }; // false by default
196  bool enableHaze{ true };
197  bool enableBloom{ true };
198  bool enableSkinning{ true };
199  bool enableBlendshape{ true };
200 
201  bool enableAmbientOcclusion{ false }; // false by default
202  bool enableShadow{ true };
203 
204 
205  void setAmbientOcclusion(bool enable) { enableAmbientOcclusion = enable; emit dirty();}
206  bool isAmbientOcclusionEnabled() const { return enableAmbientOcclusion; }
207  void setShadow(bool enable) { enableShadow = enable; emit dirty(); }
208  bool isShadowEnabled() const { return enableShadow; }
209 
210 signals:
211  void dirty();
212 };
213 
214 class MakeLightingModel {
215 public:
216  using Config = MakeLightingModelConfig;
217  using JobModel = render::Job::ModelO<MakeLightingModel, LightingModelPointer, Config>;
218 
219  MakeLightingModel();
220 
221  void configure(const Config& config);
222  void run(const render::RenderContextPointer& renderContext, LightingModelPointer& lightingModel);
223 
224 private:
225  LightingModelPointer _lightingModel;
226 };
227 
228 #endif // hifi_SurfaceGeometryPass_h