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 // Copyright 2024 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 //
12 
13 #ifndef hifi_LightingModel_h
14 #define hifi_LightingModel_h
15 
16 #include <gpu/Resource.h>
17 
18 #include <render/Forward.h>
19 #include <render/DrawTask.h>
20 
21 // LightingModel is a helper class gathering in one place the flags to enable the lighting contributions
22 class LightingModel {
23 public:
24  using UniformBufferView = gpu::BufferView;
25 
26  LightingModel();
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  void setAmbientOcclusion(bool enable);
80  bool isAmbientOcclusionEnabled() const;
81  void setLocalLightingEnabled(bool enable);
82  bool isLocalLightingEnabled() const;
83  void setShadow(bool enable);
84  bool isShadowEnabled() const;
85 
86  void setNormalMapAttenuation(float min, float max);
87 
88  UniformBufferView getParametersBuffer() const { return _parametersBuffer; }
89  gpu::TexturePointer getAmbientFresnelLUT() const { return _ambientFresnelLUT; }
90 
91 protected:
92  bool _enableLocalLighting { true };
93 
94  // Class describing the uniform buffer with the transform info common to the AO shaders
95  // It s changing every frame
96  class Parameters {
97  public:
98  float enableUnlit { 1.0f };
99  float enableEmissive { 1.0f };
100  float enableLightmap { 1.0f };
101  float enableBackground { 1.0f };
102 
103  float enableScattering { 1.0f };
104  float enableDiffuse { 1.0f };
105  float enableSpecular { 1.0f };
106  float enableAlbedo { 1.0f };
107 
108  float enableAmbientLight { 1.0f };
109  float enableDirectionalLight { 1.0f };
110  float enablePointLight { 1.0f };
111  float enableSpotLight { 1.0f };
112 
113  float showLightContour { 0.0f }; // false by default
114 
115  float enableObscurance { 1.0f };
116 
117  float enableMaterialTexturing { 1.0f };
118  float enableWireframe { 0.0f }; // false by default
119 
120  float enableHaze { 1.0f };
121  float enableBloom { 1.0f };
122  float enableSkinning { 1.0f };
123  float enableBlendshape { 1.0f };
124 
125  float enableAmbientOcclusion { 1.0f };
126  float enableShadow { 1.0f };
127  float normalMapAttenuationMin { 1.0f };
128  float normalMapAttenuationMax { 1.0f };
129 
130  Parameters() {}
131  };
132  UniformBufferView _parametersBuffer;
133  static gpu::TexturePointer _ambientFresnelLUT;
134 };
135 using LightingModelPointer = std::shared_ptr<LightingModel>;
136 
137 class MakeLightingModelConfig : public render::Job::Config {
138  Q_OBJECT
139 
140  Q_PROPERTY(bool enableUnlit MEMBER enableUnlit NOTIFY dirty)
141  Q_PROPERTY(bool enableEmissive MEMBER enableEmissive NOTIFY dirty)
142  Q_PROPERTY(bool enableLightmap MEMBER enableLightmap NOTIFY dirty)
143  Q_PROPERTY(bool enableBackground MEMBER enableBackground NOTIFY dirty)
144  Q_PROPERTY(bool enableHaze MEMBER enableHaze NOTIFY dirty)
145 
146  Q_PROPERTY(bool enableObscurance MEMBER enableObscurance NOTIFY dirty)
147 
148  Q_PROPERTY(bool enableScattering MEMBER enableScattering NOTIFY dirty)
149  Q_PROPERTY(bool enableDiffuse MEMBER enableDiffuse NOTIFY dirty)
150  Q_PROPERTY(bool enableSpecular MEMBER enableSpecular NOTIFY dirty)
151  Q_PROPERTY(bool enableAlbedo MEMBER enableAlbedo NOTIFY dirty)
152 
153  Q_PROPERTY(bool enableMaterialTexturing MEMBER enableMaterialTexturing NOTIFY dirty)
154 
155  Q_PROPERTY(bool enableAmbientLight MEMBER enableAmbientLight NOTIFY dirty)
156  Q_PROPERTY(bool enableDirectionalLight MEMBER enableDirectionalLight NOTIFY dirty)
157  Q_PROPERTY(bool enablePointLight MEMBER enablePointLight NOTIFY dirty)
158  Q_PROPERTY(bool enableSpotLight MEMBER enableSpotLight NOTIFY dirty)
159 
160  Q_PROPERTY(bool enableWireframe MEMBER enableWireframe NOTIFY dirty)
161  Q_PROPERTY(bool showLightContour MEMBER showLightContour NOTIFY dirty)
162 
163  Q_PROPERTY(bool enableBloom MEMBER enableBloom NOTIFY dirty)
164  Q_PROPERTY(bool enableSkinning MEMBER enableSkinning NOTIFY dirty)
165  Q_PROPERTY(bool enableBlendshape MEMBER enableBlendshape NOTIFY dirty)
166 
167  Q_PROPERTY(bool enableAmbientOcclusion READ isAmbientOcclusionEnabled WRITE setAmbientOcclusion NOTIFY dirty)
168  Q_PROPERTY(bool enableLocalLighting READ isLocalLightingEnabled WRITE setLocalLighting NOTIFY dirty)
169  Q_PROPERTY(bool enableShadow READ isShadowEnabled WRITE setShadow NOTIFY dirty)
170 
171 public:
172  MakeLightingModelConfig() : render::Job::Config() {} // Make Lighting Model is always on
173 
174  bool enableUnlit { true };
175  bool enableEmissive { true };
176  bool enableLightmap { true };
177  bool enableBackground { true };
178  bool enableObscurance { true };
179 
180  bool enableScattering { true };
181  bool enableDiffuse { true };
182  bool enableSpecular { true };
183 
184  bool enableAlbedo { true };
185  bool enableMaterialTexturing { true };
186 
187  bool enableAmbientLight { true };
188  bool enableDirectionalLight { true };
189  bool enablePointLight { true };
190  bool enableSpotLight { true };
191 
192  bool showLightContour { false }; // false by default
193 
194  bool enableWireframe { false }; // false by default
195  bool enableHaze { true };
196  bool enableBloom { true };
197  bool enableSkinning { true };
198  bool enableBlendshape { true };
199 
200  bool enableAmbientOcclusion { true };
201  bool enableLocalLighting { true };
202  bool enableShadow { true };
203 
204  void setAmbientOcclusion(bool enable) { enableAmbientOcclusion = enable; emit dirty();}
205  bool isAmbientOcclusionEnabled() const { return enableAmbientOcclusion; }
206  void setLocalLighting(bool enable) { enableLocalLighting = enable; emit dirty();}
207  bool isLocalLightingEnabled() const { return enableLocalLighting; }
208  void setShadow(bool enable) { enableShadow = enable; emit dirty(); }
209  bool isShadowEnabled() const { return enableShadow; }
210  void setHaze(bool enable) { enableHaze = enable; emit dirty(); }
211  void setBloom(bool enable) { enableBloom = enable; emit dirty(); }
212 
213 signals:
214  void dirty();
215 };
216 
217 class MakeLightingModel {
218 public:
219  using Config = MakeLightingModelConfig;
220  using JobModel = render::Job::ModelO<MakeLightingModel, LightingModelPointer, Config>;
221 
222  MakeLightingModel();
223 
224  void configure(const Config& config);
225  void run(const render::RenderContextPointer& renderContext, LightingModelPointer& lightingModel);
226 
227 private:
228  LightingModelPointer _lightingModel;
229 };
230 
231 #endif // hifi_SurfaceGeometryPass_h