RenderMan API  23.0
RixIES.h
Go to the documentation of this file.
1 /*
2 # ------------------------------------------------------------------------------
3 #
4 # Copyright (c) 1986-2019 Pixar. All rights reserved.
5 #
6 # The information in this file (the "Software") is provided for the exclusive
7 # use of the software licensees of Pixar ("Licensees"). Licensees have the
8 # right to incorporate the Software into other products for use by other
9 # authorized software licensees of Pixar, without fee. Except as expressly
10 # permitted herein, the Software may not be disclosed to third parties, copied
11 # or duplicated in any form, in whole or in part, without the prior written
12 # permission of Pixar.
13 #
14 # The copyright notices in the Software and this entire statement, including the
15 # above license grant, this restriction and the following disclaimer, must be
16 # included in all copies of the Software, in whole or in part, and all permitted
17 # derivative works of the Software, unless such copies or derivative works are
18 # solely in the form of machine-executable object code generated by a source
19 # language processor.
20 #
21 # PIXAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL PIXAR BE
23 # LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
24 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
25 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
26 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. IN NO CASE WILL
27 # PIXAR'S TOTAL LIABILITY FOR ALL DAMAGES ARISING OUT OF OR IN CONNECTION WITH
28 # THE USE OR PERFORMANCE OF THIS SOFTWARE EXCEED $50.
29 #
30 # Pixar
31 # 1200 Park Ave
32 # Emeryville CA 94608
33 #
34 # ------------------------------------------------------------------------------
35 */
36 
37 
38 #ifndef RixIES_h
39 #define RixIES_h
40 
41 #include <cstddef> // for NULL
42 #include <string> // for string
43 #include "RixInterfaces.h" // for RixInterface, etc
44 #include "prmanapi.h" // for PRMAN_INLINE
45 #include "ri.h" // for RtConstString
46 
47 /*
48  * RixIES interface -- Rix Light Emission Profile interface
49  *
50  * Each RixLight optionally has an emission profile
51  * accessable via "RixIES* profile = light->GetRixIES();".
52  *
53  * profile->EvaluateIESProfile, profile->EvaluateConeAngle()
54  * are methods to evaluate emission.
55  *
56  * profile->ReadIESProfile reads all the params/settings of a IES profile.
57  *
58  */
59 
60 class RixIES : public RixInterface
61 {
62 public:
63  struct IESProfile
64  {
66  : mapName(US_NULL),
67  profile(NULL),
68  nu(0),
69  nv(0),
70  isColor(false),
71  isExr(false),
72  profileScale(1.0f)
73  {
74  }
75 
77 
78  void clearProfile()
79  {
80  delete[] profile;
81  profile = NULL;
82  }
83  void clear()
84  {
85  clearProfile();
86  mapName = US_NULL;
87  nu = 0;
88  nv = 0;
89  isExr = false;
90  isColor = false;
91  }
92 
94  float* profile;
95  // RtMatrix profileSpace;
96  int nu, nv;
97  bool isColor;
98  bool isExr;
99  float profileScale;
100  };
101 
103  : RixInterface(1),
104  m_coneAngle(-1.0f),
105  m_coneOffset(0.0f),
106  m_hasNegativeDeterminant(false),
107  m_normalizationFactor(1.0f)
108  {
109  // FIXME: do we need to support a profileSpace?
110  // MxIdentity(m_profileSpace);
111  }
112 
114  RtFloat3 const& P,
115  RtColorRGB* emission) const;
116 
118  RixContext const& rixCtx,
119  RtUString const iesProfile);
120 
121  PRMAN_INLINE float EvaluateConeAngle(RtFloat3 const& P) const;
122 
123  PRMAN_INLINE float EvaluateConeAngle(RtPoint3 const& lightP, RtVector3& lightN,
124  RtPoint3 const& offsetP, RtVector3 const& segmentDir,
125  float& minT, float& maxT) const;
126 
127  // clang-format off
128  // get/set funcs
129  IESProfile& GetIESProfile() { return m_iesProfile; }
130 
131  float GetConeAngle() const { return m_coneAngle; }
132  float GetConeOffset() const { return m_coneOffset; }
133  bool GetHasNegativeDeterminant() const { return m_hasNegativeDeterminant; }
134  float GetNormalizationFactor() const { return m_normalizationFactor; }
135 
136  void SetConeAngle(float v) { m_coneAngle = v; m_cosConeAngle = cosf(m_coneAngle); }
137  void SetConeOffset(float v) { m_coneOffset = v; }
138  void SetHasNegativeDeterminant(float v) { m_hasNegativeDeterminant = v; }
139  // clang-format on
140 
141 private:
142  // Utility routines
143  PRMAN_INLINE float calcLongitude(float x, float y, bool isExr) const;
144 
145  PRMAN_INLINE void calcLatLongParam(
146  int n, // number of points in BOP
147  float* dir, // array of reflection directions
148  bool openEXR, // Is this an EXR latlong?
149  float* s, // output s array pointer
150  float* t) const; // output t array pointer
151 
152 private:
153  IESProfile m_iesProfile; // only the read func accesses its members
154 
155  float m_coneAngle;
156  float m_cosConeAngle;
157  float m_coneOffset;
158 
159  bool m_hasNegativeDeterminant;
160 
161  // The factor that scales the profile data to sum to unit intensity over the
162  // entire sphere.
163  float m_normalizationFactor;
164 };
165 
166 #include "RixIESInline.h" // IWYU pragma: export
167 
168 #endif
pxrcore::ColorRGB RtColorRGB
IESProfile & GetIESProfile()
Definition: RixIES.h:129
#define US_NULL
void SetConeAngle(float v)
Definition: RixIES.h:136
void clear()
Definition: RixIES.h:83
float * profile
Definition: RixIES.h:94
RtFloat3 RtPoint3
Definition: RiTypesHelper.h:69
void SetConeOffset(float v)
Definition: RixIES.h:137
PRMAN_INLINE bool ReadIESProfile(RixContext const &rixCtx, RtUString const iesProfile)
Definition: RixIESInline.h:201
PRMAN_INLINE void EvaluateIESProfile(RtFloat3 const &P, RtColorRGB *emission) const
Definition: RixIESInline.h:51
bool GetHasNegativeDeterminant() const
Definition: RixIES.h:133
pxrcore::UString RtUString
#define PRMAN_INLINE
Definition: prmanapi.h:86
void clearProfile()
Definition: RixIES.h:78
void SetHasNegativeDeterminant(float v)
Definition: RixIES.h:138
float GetNormalizationFactor() const
Definition: RixIES.h:134
pxrcore::Float3 RtFloat3
Definition: RiTypesHelper.h:68
Definition: RixIES.h:60
float profileScale
Definition: RixIES.h:99
RixIES()
Definition: RixIES.h:102
PRMAN_INLINE float EvaluateConeAngle(RtFloat3 const &P) const
Definition: RixIESInline.h:295
float GetConeAngle() const
Definition: RixIES.h:131
RtUString mapName
Definition: RixIES.h:93
float GetConeOffset() const
Definition: RixIES.h:132
RtFloat3 RtVector3
Definition: RiTypesHelper.h:71