RenderManAPI  24.0
RixIES.h
Go to the documentation of this file.
1 /*
2 # ------------------------------------------------------------------------------
3 #
4 # Copyright (c) 2020 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 #ifndef RixIES_h
38 #define RixIES_h
39 
40 #include <cstddef> // for NULL
41 #include <string> // for string
42 #include "RixInterfaces.h" // for RixInterface, etc
43 #include "prmanapi.h" // for PRMAN_INLINE
44 #include "RiTypesHelper.h" // for RtUString
45 
46 /*
47  * RixIES interface -- Rix Light Emission Profile interface
48  *
49  * Each RixLight optionally has an emission profile
50  * accessable via "RixIES* profile = light->GetRixIES();".
51  *
52  * profile->EvaluateIESProfile, profile->EvaluateConeAngle()
53  * are methods to evaluate emission.
54  *
55  * profile->ReadIESProfile reads all the params/settings of a IES profile.
56  *
57  */
58 
59 class RixIES : public RixInterface
60 {
61 public:
62  struct IESProfile
63  {
65  : mapName(US_NULL),
66  profile(NULL),
67  nu(0),
68  nv(0),
69  isColor(false),
70  isExr(false),
71  profileScale(1.0f)
72  {
73  }
74 
76 
77  void clearProfile()
78  {
79  delete[] profile;
80  profile = NULL;
81  }
82  void clear()
83  {
84  clearProfile();
85  mapName = US_NULL;
86  nu = 0;
87  nv = 0;
88  isExr = false;
89  isColor = false;
90  }
91 
93  float* profile;
94  // RtMatrix profileSpace;
95  int nu, nv;
96  bool isColor;
97  bool isExr;
98  float profileScale;
99  };
100 
102  : RixInterface(1),
103  m_coneAngle(-1.0f),
104  m_coneOffset(0.0f),
105  m_hasNegativeDeterminant(false),
106  m_normalizationFactor(1.0f)
107  {
108  // FIXME: do we need to support a profileSpace?
109  // MxIdentity(m_profileSpace);
110  }
111 
113  RtFloat3 const& P,
114  RtColorRGB* emission) const;
115 
117  RixContext const& rixCtx,
118  RtUString const iesProfile);
119 
120  PRMAN_INLINE float EvaluateConeAngle(RtFloat3 const& P) const;
121 
122  PRMAN_INLINE float EvaluateConeAngle(RtPoint3 const& lightP, RtVector3& lightN,
123  RtPoint3 const& offsetP, RtVector3 const& segmentDir,
124  float& minT, float& maxT) const;
125 
126  // clang-format off
127  // get/set funcs
128  IESProfile& GetIESProfile() { return m_iesProfile; }
129 
130  float GetConeAngle() const { return m_coneAngle; }
131  float GetConeOffset() const { return m_coneOffset; }
132  bool GetHasNegativeDeterminant() const { return m_hasNegativeDeterminant; }
133  float GetNormalizationFactor() const { return m_normalizationFactor; }
134 
135  void SetConeAngle(float v) { m_coneAngle = v; m_cosConeAngle = cosf(m_coneAngle); }
136  void SetConeOffset(float v) { m_coneOffset = v; }
137  void SetHasNegativeDeterminant(float v) { m_hasNegativeDeterminant = v; }
138  // clang-format on
139 
140 private:
141  // Utility routines
142  PRMAN_INLINE float calcLongitude(float x, float y, bool isExr) const;
143 
144  PRMAN_INLINE void calcLatLongParam(
145  int n, // number of points in BOP
146  float* dir, // array of reflection directions
147  bool openEXR, // Is this an EXR latlong?
148  float* s, // output s array pointer
149  float* t) const; // output t array pointer
150 
151 private:
152  IESProfile m_iesProfile; // only the read func accesses its members
153 
154  float m_coneAngle;
155  float m_cosConeAngle;
156  float m_coneOffset;
157 
158  bool m_hasNegativeDeterminant;
159 
160  // The factor that scales the profile data to sum to unit intensity over the
161  // entire sphere.
162  float m_normalizationFactor;
163 };
164 
165 #include "RixIESInline.h" // IWYU pragma: export
166 
167 #endif
#define US_NULL
Definition: RiTypesHelper.h:683
int nu
Definition: RixIES.h:95
float GetConeAngle() const
Definition: RixIES.h:130
pxrcore::ColorRGB RtColorRGB
Definition: RiTypesHelper.h:520
Rix interfaces are obtained from an RixContext.
Definition: RixInterfaces.h:172
int nv
Definition: RixIES.h:95
float GetConeOffset() const
Definition: RixIES.h:131
Base class for all Rix interfaces.
Definition: RixInterfaces.h:133
RtFloat3 RtPoint3
Definition: RiTypesHelper.h:70
RixIES()
Definition: RixIES.h:101
IESProfile()
Definition: RixIES.h:64
RtUString mapName
Definition: RixIES.h:92
void clearProfile()
Definition: RixIES.h:77
float GetNormalizationFactor() const
Definition: RixIES.h:133
float profileScale
Definition: RixIES.h:98
pxrcore::Float3 RtFloat3
Definition: RiTypesHelper.h:69
Definition: RixIES.h:59
bool isExr
Definition: RixIES.h:97
Definition: RixIES.h:62
PRMAN_INLINE void EvaluateIESProfile(RtFloat3 const &P, RtColorRGB *emission) const
Definition: RixIESInline.h:50
#define PRMAN_INLINE
Definition: prmanapi.h:99
void SetConeAngle(float v)
Definition: RixIES.h:135
~IESProfile()
Definition: RixIES.h:75
void clear()
Definition: RixIES.h:82
PRMAN_INLINE bool ReadIESProfile(RixContext const &rixCtx, RtUString const iesProfile)
Definition: RixIESInline.h:200
void SetHasNegativeDeterminant(float v)
Definition: RixIES.h:137
pxrcore::UString RtUString
Definition: RiTypesHelper.h:682
void SetConeOffset(float v)
Definition: RixIES.h:136
IESProfile & GetIESProfile()
Definition: RixIES.h:128
bool isColor
Definition: RixIES.h:96
bool GetHasNegativeDeterminant() const
Definition: RixIES.h:132
PRMAN_INLINE float EvaluateConeAngle(RtFloat3 const &P) const
Definition: RixIESInline.h:294
RtFloat3 RtVector3
Definition: RiTypesHelper.h:72
float * profile
Definition: RixIES.h:93