1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 //    names, trademarks, service marks, or product names of the Licensor
11 //    and its affiliates, except as required to comply with Section 4(c) of
12 //    the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 //     http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 /// \file simpleLight.cpp
25 
26 #include "pxr/imaging/glf/simpleLight.h"
27 
28 #include "pxr/imaging/garch/glApi.h"
29 
30 PXR_NAMESPACE_OPEN_SCOPE
31 
32 
GlfSimpleLight(GfVec4f const & position)33 GlfSimpleLight::GlfSimpleLight(GfVec4f const & position) :
34     _ambient(0.2, 0.2, 0.2, 1.0),
35     _diffuse(1.0, 1.0, 1.0, 1.0),
36     _specular(1.0, 1.0, 1.0, 1.0),
37     _position(position[0], position[1], position[2], 1.0),
38     _spotDirection(0.0, 0.0, -1.0),
39     _spotCutoff(180.0),
40     _spotFalloff(0.0),
41     _attenuation(1.0, 0.0, 0.0),
42     _isCameraSpaceLight(false),
43     _hasIntensity(true),
44     _hasShadow(false),
45     _shadowResolution(512),
46     _shadowBias(0.0),
47     _shadowBlur(0.0),
48     _shadowIndexStart(0),
49     _shadowIndexEnd(0),
50     _transform(GfMatrix4d().SetIdentity()),
51     _shadowMatrices(std::vector<GfMatrix4d>(1, GfMatrix4d().SetIdentity())),
52     _isDomeLight(false),
53     _id()
54 {
55 }
56 
57 GlfSimpleLight::~GlfSimpleLight() = default;
58 
59 GfMatrix4d const &
GetTransform() const60 GlfSimpleLight::GetTransform() const
61 {
62     return _transform;
63 }
64 
65 void
SetTransform(GfMatrix4d const & mat)66 GlfSimpleLight::SetTransform(GfMatrix4d const & mat)
67 {
68     _transform = mat;
69 }
70 
71 GfVec4f const &
GetAmbient() const72 GlfSimpleLight::GetAmbient() const
73 {
74     return _ambient;
75 }
76 
77 void
SetAmbient(GfVec4f const & ambient)78 GlfSimpleLight::SetAmbient(GfVec4f const & ambient)
79 {
80     _ambient = ambient;
81 }
82 
83 
84 GfVec4f const &
GetDiffuse() const85 GlfSimpleLight::GetDiffuse() const
86 {
87     return _diffuse;
88 }
89 
90 void
SetDiffuse(GfVec4f const & diffuse)91 GlfSimpleLight::SetDiffuse(GfVec4f const & diffuse)
92 {
93     _diffuse = diffuse;
94 }
95 
96 
97 GfVec4f const &
GetSpecular() const98 GlfSimpleLight::GetSpecular() const
99 {
100     return _specular;
101 }
102 
103 void
SetSpecular(GfVec4f const & specular)104 GlfSimpleLight::SetSpecular(GfVec4f const & specular)
105 {
106     _specular = specular;
107 }
108 
109 GfVec4f const &
GetPosition() const110 GlfSimpleLight::GetPosition() const
111 {
112     return _position;
113 }
114 
115 void
SetPosition(GfVec4f const & position)116 GlfSimpleLight::SetPosition(GfVec4f const & position)
117 {
118     _position = position;
119 }
120 
121 GfVec3f const &
GetSpotDirection() const122 GlfSimpleLight::GetSpotDirection() const
123 {
124     return _spotDirection;
125 }
126 
127 void
SetSpotDirection(GfVec3f const & spotDirection)128 GlfSimpleLight::SetSpotDirection(GfVec3f const & spotDirection)
129 {
130     _spotDirection = spotDirection;
131 }
132 
133 float const &
GetSpotCutoff() const134 GlfSimpleLight::GetSpotCutoff() const
135 {
136     return _spotCutoff;
137 }
138 
139 void
SetSpotCutoff(float const & spotCutoff)140 GlfSimpleLight::SetSpotCutoff(float const & spotCutoff)
141 {
142     _spotCutoff = spotCutoff;
143 }
144 
145 float const &
GetSpotFalloff() const146 GlfSimpleLight::GetSpotFalloff() const
147 {
148     return _spotFalloff;
149 }
150 
151 void
SetSpotFalloff(float const & spotFalloff)152 GlfSimpleLight::SetSpotFalloff(float const & spotFalloff)
153 {
154     _spotFalloff = spotFalloff;
155 }
156 
157 GfVec3f const &
GetAttenuation() const158 GlfSimpleLight::GetAttenuation() const
159 {
160     return _attenuation;
161 }
162 
163 void
SetAttenuation(GfVec3f const & attenuation)164 GlfSimpleLight::SetAttenuation(GfVec3f const & attenuation)
165 {
166     _attenuation = attenuation;
167 }
168 
169 void
SetHasIntensity(bool hasIntensity)170 GlfSimpleLight::SetHasIntensity(bool hasIntensity)
171 {
172     _hasIntensity = hasIntensity;
173 }
174 
175 bool
HasIntensity() const176 GlfSimpleLight::HasIntensity() const
177 {
178     return _hasIntensity;
179 }
180 
181 bool
HasShadow() const182 GlfSimpleLight::HasShadow() const
183 {
184     return _hasShadow;
185 }
186 
187 void
SetHasShadow(bool hasShadow)188 GlfSimpleLight::SetHasShadow(bool hasShadow)
189 {
190     _hasShadow = hasShadow;
191 }
192 
193 int
GetShadowResolution() const194 GlfSimpleLight::GetShadowResolution() const
195 {
196     return _shadowResolution;
197 }
198 
199 void
SetShadowResolution(int resolution)200 GlfSimpleLight::SetShadowResolution(int resolution)
201 {
202     _shadowResolution = resolution;
203 }
204 
205 float
GetShadowBias() const206 GlfSimpleLight::GetShadowBias() const
207 {
208     return _shadowBias;
209 }
210 
211 void
SetShadowBias(float bias)212 GlfSimpleLight::SetShadowBias(float bias)
213 {
214     _shadowBias = bias;
215 }
216 
217 float
GetShadowBlur() const218 GlfSimpleLight::GetShadowBlur() const
219 {
220     return _shadowBlur;
221 }
222 
223 void
SetShadowBlur(float blur)224 GlfSimpleLight::SetShadowBlur(float blur)
225 {
226     _shadowBlur = blur;
227 }
228 
229 int
GetShadowIndexStart() const230 GlfSimpleLight::GetShadowIndexStart() const
231 {
232     return _shadowIndexStart;
233 }
234 
235 void
SetShadowIndexStart(int shadowStart)236 GlfSimpleLight::SetShadowIndexStart(int shadowStart)
237 {
238     _shadowIndexStart = shadowStart;
239 }
240 
241 int
GetShadowIndexEnd() const242 GlfSimpleLight::GetShadowIndexEnd() const
243 {
244     return _shadowIndexEnd;
245 }
246 
247 void
SetShadowIndexEnd(int shadowEnd)248 GlfSimpleLight::SetShadowIndexEnd(int shadowEnd)
249 {
250     _shadowIndexEnd = shadowEnd;
251 }
252 
253 std::vector<GfMatrix4d> const &
GetShadowMatrices() const254 GlfSimpleLight::GetShadowMatrices() const
255 {
256     return _shadowMatrices;
257 }
258 
259 void
SetShadowMatrices(std::vector<GfMatrix4d> const & matrices)260 GlfSimpleLight::SetShadowMatrices(std::vector<GfMatrix4d> const & matrices)
261 {
262     _shadowMatrices = matrices;
263 }
264 
265 bool
IsCameraSpaceLight() const266 GlfSimpleLight::IsCameraSpaceLight() const
267 {
268     return _isCameraSpaceLight;
269 }
270 
271 void
SetIsCameraSpaceLight(bool isCameraSpaceLight)272 GlfSimpleLight::SetIsCameraSpaceLight(bool isCameraSpaceLight)
273 {
274     _isCameraSpaceLight = isCameraSpaceLight;
275 }
276 
277 SdfPath const &
GetID() const278 GlfSimpleLight::GetID() const
279 {
280     return _id;
281 }
282 
SetID(SdfPath const & id)283 void GlfSimpleLight::SetID(SdfPath const & id)
284 {
285     _id = id;
286 }
287 
288 bool
IsDomeLight() const289 GlfSimpleLight::IsDomeLight() const
290 {
291     return _isDomeLight;
292 }
293 
294 void
SetIsDomeLight(bool isDomeLight)295 GlfSimpleLight::SetIsDomeLight(bool isDomeLight)
296 {
297     _isDomeLight = isDomeLight;
298 }
299 
300 const SdfAssetPath &
GetDomeLightTextureFile() const301 GlfSimpleLight::GetDomeLightTextureFile() const
302 {
303     return _domeLightTextureFile;
304 }
305 
306 void
SetDomeLightTextureFile(const SdfAssetPath & path)307 GlfSimpleLight::SetDomeLightTextureFile(const SdfAssetPath &path)
308 {
309     _domeLightTextureFile = path;
310 }
311 
312 TfToken const &
GetPostSurfaceIdentifier() const313 GlfSimpleLight::GetPostSurfaceIdentifier() const
314 {
315     return _postSurfaceIdentifier;
316 }
317 
318 std::string const &
GetPostSurfaceShaderSource() const319 GlfSimpleLight::GetPostSurfaceShaderSource() const
320 {
321     return _postSurfaceShaderSource;
322 }
323 
324 
325 VtUCharArray const &
GetPostSurfaceShaderParams() const326 GlfSimpleLight::GetPostSurfaceShaderParams() const
327 {
328     return _postSurfaceShaderParams;
329 }
330 
331 void
SetPostSurfaceParams(TfToken const & identifier,std::string const & shaderSource,VtUCharArray const & shaderParams)332 GlfSimpleLight::SetPostSurfaceParams(TfToken const & identifier,
333                                      std::string const & shaderSource,
334                                      VtUCharArray const & shaderParams)
335 {
336     _postSurfaceIdentifier = identifier;
337     _postSurfaceShaderSource = shaderSource;
338     _postSurfaceShaderParams = shaderParams;
339 }
340 
341 // -------------------------------------------------------------------------- //
342 // VtValue requirements
343 // -------------------------------------------------------------------------- //
344 
345 bool
operator ==(const GlfSimpleLight & other) const346 GlfSimpleLight::operator==(const GlfSimpleLight& other) const
347 {
348     return  _ambient == other._ambient
349         &&  _diffuse == other._diffuse
350         &&  _specular == other._specular
351         &&  _position == other._position
352         &&  _spotDirection == other._spotDirection
353         &&  _spotCutoff == other._spotCutoff
354         &&  _spotFalloff == other._spotFalloff
355         &&  _attenuation == other._attenuation
356         &&  _hasIntensity == other._hasIntensity
357         &&  _hasShadow == other._hasShadow
358         &&  _shadowResolution == other._shadowResolution
359         &&  _shadowBias == other._shadowBias
360         &&  _shadowBlur == other._shadowBlur
361         &&  _shadowIndexStart == other._shadowIndexStart
362         &&  _shadowIndexEnd == other._shadowIndexEnd
363         &&  _transform == other._transform
364         &&  _shadowMatrices == other._shadowMatrices
365         &&  _isCameraSpaceLight == other._isCameraSpaceLight
366         &&  _isDomeLight == other._isDomeLight
367         &&  _domeLightTextureFile == other._domeLightTextureFile
368         &&  _postSurfaceIdentifier == other._postSurfaceIdentifier
369         &&  _postSurfaceShaderSource == other._postSurfaceShaderSource
370         &&  _postSurfaceShaderParams == other._postSurfaceShaderParams
371         &&  _id == other._id;
372 }
373 
374 bool
operator !=(const GlfSimpleLight & other) const375 GlfSimpleLight::operator!=(const GlfSimpleLight& other) const
376 {
377     return !(*this == other);
378 }
379 
operator <<(std::ostream & out,const GlfSimpleLight & v)380 std::ostream& operator<<(std::ostream& out, const GlfSimpleLight& v)
381 {
382     out << v._ambient
383         << v._diffuse
384         << v._specular
385         << v._position
386         << v._spotDirection
387         << v._spotCutoff
388         << v._spotFalloff
389         << v._attenuation
390         << v._hasIntensity
391         << v._hasShadow
392         << v._shadowResolution
393         << v._shadowBias
394         << v._shadowBlur
395         << v._shadowIndexStart
396         << v._shadowIndexEnd
397         << v._transform
398         << v._isCameraSpaceLight
399         << v._isDomeLight
400         << v._domeLightTextureFile
401         << v._postSurfaceIdentifier
402         << v._postSurfaceShaderSource
403         << v._postSurfaceShaderParams
404         << v._id;
405     for (auto const& m : v._shadowMatrices) {
406         out << m;
407     }
408     return out;
409 }
410 
411 std::ostream&
operator <<(std::ostream & out,const GlfSimpleLightVector & pv)412 operator<<(std::ostream& out, const GlfSimpleLightVector& pv)
413 {
414     return out;
415 }
416 
417 PXR_NAMESPACE_CLOSE_SCOPE
418 
419