MaterialX 1.39.1
Loading...
Searching...
No Matches
LightHandler.h
Go to the documentation of this file.
1//
2// Copyright Contributors to the MaterialX Project
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#ifndef MATERIALX_LIGHTHANDLER_H
7#define MATERIALX_LIGHTHANDLER_H
8
11
15
17
18MATERIALX_NAMESPACE_BEGIN
19
20extern MX_RENDER_API const int DEFAULT_ENV_SAMPLE_COUNT;
21
22class GenContext;
23
25using LightHandlerPtr = std::shared_ptr<class LightHandler>;
26
28using LightIdMap = std::unordered_map<string, unsigned int>;
29
33class MX_RENDER_API LightHandler
34{
35 public:
36 LightHandler() :
37 _lightTransform(Matrix44::IDENTITY),
38 _directLighting(true),
39 _indirectLighting(true),
40 _usePrefilteredMap(false),
41 _envLightIntensity(1.0f),
42 _envSampleCount(DEFAULT_ENV_SAMPLE_COUNT),
43 _refractionTwoSided(false)
44 {
45 }
46 virtual ~LightHandler() { }
47
49 static LightHandlerPtr create() { return std::make_shared<LightHandler>(); }
50
53
55 void setLightTransform(const Matrix44& mat)
56 {
57 _lightTransform = mat;
58 }
59
62 {
63 return _lightTransform;
64 }
65
67 void setDirectLighting(bool enable)
68 {
69 _directLighting = enable;
70 }
71
73 bool getDirectLighting() const
74 {
75 return _directLighting;
76 }
77
79 void setIndirectLighting(bool enable)
80 {
81 _indirectLighting = enable;
82 }
83
86 {
87 return _indirectLighting;
88 }
89
93
96 {
97 _envRadianceMap = map;
98 }
99
102 {
103 return _envRadianceMap;
104 }
105
108 {
109 _envPrefilteredMap = map;
110 }
111
114 {
115 return _envPrefilteredMap;
116 }
117
119 void setUsePrefilteredMap(bool val)
120 {
121 _usePrefilteredMap = val;
122 }
123
126 {
127 return _usePrefilteredMap;
128 }
129
132 {
133 _envIrradianceMap = map;
134 }
135
138 {
139 return _envIrradianceMap;
140 }
141
143 void setEnvSampleCount(int count)
144 {
145 _envSampleCount = count;
146 }
147
150 {
151 return _envSampleCount;
152 }
153
155 void setEnvLightIntensity(const float intensity)
156 {
157 _envLightIntensity = intensity;
158 }
159
162 {
163 return _envLightIntensity;
164 }
165
167 void setRefractionTwoSided(bool enable)
168 {
169 _refractionTwoSided = enable;
170 }
171
174 {
175 return _refractionTwoSided;
176 }
177
181
184 {
185 _albedoTable = table;
186 }
187
190 {
191 return _albedoTable;
192 }
193
197
200
202 void setLightSources(const vector<NodePtr>& lights)
203 {
204 _lightSources = lights;
205 }
206
208 const vector<NodePtr>& getLightSources() const
209 {
210 return _lightSources;
211 }
212
214 NodePtr getFirstLightOfCategory(const string& category)
215 {
216 for (NodePtr light : _lightSources)
217 {
218 if (light->getCategory() == category)
219 {
220 return light;
221 }
222 }
223 return nullptr;
224 }
225
229
231 const std::unordered_map<string, unsigned int>& getLightIdMap() const
232 {
233 return _lightIdMap;
234 }
235
238 LightIdMap computeLightIdMap(const vector<NodePtr>& nodes);
239
243 void findLights(DocumentPtr doc, vector<NodePtr>& lights);
244
249 void registerLights(DocumentPtr doc, const vector<NodePtr>& lights, GenContext& context);
250
252
253 protected:
254 Matrix44 _lightTransform;
255 bool _directLighting;
256 bool _indirectLighting;
257 bool _usePrefilteredMap;
258
259 ImagePtr _envRadianceMap;
260 ImagePtr _envPrefilteredMap;
261 ImagePtr _envIrradianceMap;
262 float _envLightIntensity;
263 int _envSampleCount;
264
265 bool _refractionTwoSided;
266
267 ImagePtr _albedoTable;
268
269 vector<NodePtr> _lightSources;
270 std::unordered_map<string, unsigned int> _lightIdMap;
271};
272
273MATERIALX_NAMESPACE_END
274
275#endif
The top-level Document class.
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
Image class.
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:23
std::shared_ptr< class LightHandler > LightHandlerPtr
Shared pointer to a LightHandler.
Definition: LightHandler.h:25
std::unordered_map< string, unsigned int > LightIdMap
An unordered map from light names to light indices.
Definition: LightHandler.h:28
Macros for declaring imported and exported symbols.
Rendering utility methods.
shared_ptr< Node > NodePtr
A shared pointer to a Node.
Definition: Node.h:24
A context class for shader generation.
Definition: GenContext.h:31
Utility light handler for creating and providing light data for shader binding.
Definition: LightHandler.h:34
bool getUsePrefilteredMap()
Return whether to use the prefiltered environment lighting model.
Definition: LightHandler.h:125
void setDirectLighting(bool enable)
Set whether direct lighting is enabled.
Definition: LightHandler.h:67
LightIdMap computeLightIdMap(const vector< NodePtr > &nodes)
From a set of nodes, create a mapping of corresponding nodedef identifiers to numbers.
void setEnvIrradianceMap(ImagePtr map)
Set the environment irradiance map.
Definition: LightHandler.h:131
void setEnvPrefilteredMap(ImagePtr map)
Set the environment radiance map for the prefiltered environment lighting model.
Definition: LightHandler.h:107
void setUsePrefilteredMap(bool val)
Set whether to use the prefiltered environment lighting model.
Definition: LightHandler.h:119
float getEnvLightIntensity()
Return the environment light intensity.
Definition: LightHandler.h:161
void findLights(DocumentPtr doc, vector< NodePtr > &lights)
Find lights to use based on an input document.
ImagePtr getEnvPrefilteredMap() const
Return the environment radiance map for the prefiltered environment lighting model.
Definition: LightHandler.h:113
NodePtr getFirstLightOfCategory(const string &category)
Return the first light source, if any, of the given category.
Definition: LightHandler.h:214
bool getDirectLighting() const
Return whether direct lighting is enabled.
Definition: LightHandler.h:73
const vector< NodePtr > & getLightSources() const
Return the vector of light sources.
Definition: LightHandler.h:208
static LightHandlerPtr create()
Create a new light handler.
Definition: LightHandler.h:49
void setEnvSampleCount(int count)
Set the environment lighting sample count.
Definition: LightHandler.h:143
Matrix44 getLightTransform() const
Return the light transform.
Definition: LightHandler.h:61
int getEnvSampleCount() const
Return the environment lighting sample count.
Definition: LightHandler.h:149
void registerLights(DocumentPtr doc, const vector< NodePtr > &lights, GenContext &context)
Register light node definitions and light count with a given generation context.
void setLightTransform(const Matrix44 &mat)
Set the light transform.
Definition: LightHandler.h:55
void setLightSources(const vector< NodePtr > &lights)
Set the vector of light sources.
Definition: LightHandler.h:202
void setAlbedoTable(ImagePtr table)
Set the directional albedo table.
Definition: LightHandler.h:183
ImagePtr getEnvRadianceMap() const
Return the environment radiance map.
Definition: LightHandler.h:101
void setIndirectLighting(bool enable)
Set whether indirect lighting is enabled.
Definition: LightHandler.h:79
ImagePtr getEnvIrradianceMap() const
Return the environment irradiance map.
Definition: LightHandler.h:137
void addLightSource(NodePtr node)
Add a light source.
const std::unordered_map< string, unsigned int > & getLightIdMap() const
Get a list of identifiers associated with a given light nodedef.
Definition: LightHandler.h:231
void setEnvLightIntensity(const float intensity)
Set the environment light intensity.
Definition: LightHandler.h:155
ImagePtr getAlbedoTable() const
Return the directional albedo table.
Definition: LightHandler.h:189
void setRefractionTwoSided(bool enable)
Set the two-sided refraction property.
Definition: LightHandler.h:167
bool getIndirectLighting() const
Return whether indirect lighting is enabled.
Definition: LightHandler.h:85
int getRefractionTwoSided() const
Return the two-sided refraction property.
Definition: LightHandler.h:173
void setEnvRadianceMap(ImagePtr map)
Set the environment radiance map.
Definition: LightHandler.h:95
A 4x4 matrix of floating-point values.
Definition: Types.h:656