MaterialX 1.38.2
LightHandler.h
Go to the documentation of this file.
1//
2// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3// All rights reserved. See LICENSE.txt for license.
4//
5
6#ifndef MATERIALX_LIGHTHANDLER_H
7#define MATERIALX_LIGHTHANDLER_H
8
11
14
16
17namespace MaterialX
18{
19
20class GenContext;
21
23using LightHandlerPtr = std::shared_ptr<class LightHandler>;
24
26using LightIdMap = std::unordered_map<string, unsigned int>;
27
31class MX_RENDER_API LightHandler
32{
33 public:
35 {
36 }
37 virtual ~LightHandler() { }
38
40 static LightHandlerPtr create() { return std::make_shared<LightHandler>(); }
41
43 void addLightSource(NodePtr node);
44
46 const vector<NodePtr>& getLightSources() const
47 {
48 return _lightSources;
49 }
50
52 NodePtr getFirstLightOfCategory(const string& category)
53 {
54 for (NodePtr light : _lightSources)
55 {
56 if (light->getCategory() == category)
57 {
58 return light;
59 }
60 }
61 return nullptr;
62 }
63
65 const std::unordered_map<string, unsigned int>& getLightIdentifierMap() const
66 {
67 return _lightIdentifierMap;
68 }
69
71 void setLightSources(const vector<NodePtr>& lights)
72 {
73 _lightSources = lights;
74 }
75
78 {
79 _envRadianceMap = map;
80 }
81
84 {
85 return _envRadianceMap;
86 }
87
90 {
91 _envIrradianceMap = map;
92 }
93
96 {
97 return _envIrradianceMap;
98 }
99
102 {
103 _albedoTable = table;
104 }
105
108 {
109 return _albedoTable;
110 }
111
114 LightIdMap computeLightIdMap(const vector<NodePtr>& nodes);
115
119 void findLights(DocumentPtr doc, vector<NodePtr>& lights);
120
125 void registerLights(DocumentPtr doc, const vector<NodePtr>& lights, GenContext& context);
126
127 private:
128 vector<NodePtr> _lightSources;
129 std::unordered_map<string, unsigned int> _lightIdentifierMap;
130 ImagePtr _envRadianceMap;
131 ImagePtr _envIrradianceMap;
132 ImagePtr _albedoTable;
133};
134
135} // namespace MaterialX
136
137#endif
The top-level Document class.
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:23
Image class.
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:24
std::shared_ptr< class LightHandler > LightHandlerPtr
Shared pointer to a LightHandler.
Definition: LightHandler.h:23
std::unordered_map< string, unsigned int > LightIdMap
An unordered map from light names to light indices.
Definition: LightHandler.h:26
Macros for declaring imported and exported symbols.
shared_ptr< Node > NodePtr
A shared pointer to a Node.
Definition: Node.h:25
A context class for shader generation.
Definition: GenContext.h:27
Utility light handler for creating and providing light data for shader binding.
Definition: LightHandler.h:32
void setEnvIrradianceMap(ImagePtr map)
Set the environment irradiance map.
Definition: LightHandler.h:89
NodePtr getFirstLightOfCategory(const string &category)
Return the first active light source, if any, of the given category.
Definition: LightHandler.h:52
const std::unordered_map< string, unsigned int > & getLightIdentifierMap() const
Get a list of identifiers associated with a given light nodedef.
Definition: LightHandler.h:65
const vector< NodePtr > & getLightSources() const
Return the vector of active light sources.
Definition: LightHandler.h:46
static LightHandlerPtr create()
Create a new light handler.
Definition: LightHandler.h:40
void setLightSources(const vector< NodePtr > &lights)
Set the list of light sources.
Definition: LightHandler.h:71
void setAlbedoTable(ImagePtr table)
Set the directional albedo table.
Definition: LightHandler.h:101
ImagePtr getEnvRadianceMap() const
Return the environment radiance map.
Definition: LightHandler.h:83
ImagePtr getEnvIrradianceMap() const
Return the environment irradiance map.
Definition: LightHandler.h:95
ImagePtr getAlbedoTable() const
Return the directional albedo table.
Definition: LightHandler.h:107
void setEnvRadianceMap(ImagePtr map)
Set the environment radiance map.
Definition: LightHandler.h:77