RenderManAPI  24.0
RixLight.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 RixLight_h
38 #define RixLight_h
39 
40 #include <cstddef> // for NULL
41 #include "RixBxdf.h" // for RixBXEvaluateDomain
42 #include "RixIES.h" // for RixIES
43 #include "RixShading.h" // for RixParameterList (ptr only), etc
44 #include "prmanapi.h" // for PRMANEXPORT
45 #include "RiTypesHelper.h" // for RtColorRGB, RtPoint3, etc
46 
47 class RixContext;
48 class RixLightFactory;
49 class RixPhotonGuiding;
50 
57 {
58 public:
63  // Retrieve the RixPhotonGuiding object given to the LightingServices
65  {
66  return m_pPhotonGuiding;
67  }
68 
69  // Obtain the time associated with this query
70  virtual float GetTime() const = 0;
71 
72  // Obtain a sample for the i'th element in this query context.
73  // Only valid when in a sampling context. Will return 0,0 otherwise
74  virtual RtFloat2 GetSample2D() const = 0;
75  virtual void GetSample4D(RtFloat2& xy, RtFloat2& zw) const = 0;
76 
77  // BBox encompassing the world. Needed for environment lights to emit
78  // photons when there is no photon guiding object available
79  virtual void GetWorldBBox(RtBBox& worldBBox) const = 0;
80 
81  // Transform between named spaces
82  virtual void GetFromToTransform(
83  RtUString from, RtUString to,
84  const float time,
85  RtMatrix4x4& xform) const = 0;
86  virtual void GetFromToTransform(
87  RtUString from, RtUString to,
88  RtMatrix4x4& xform) const = 0;
89  // light space to current space
90  virtual void GetLightToCurrentTransform(
91  RtMatrix4x4& lightToCurrent) const = 0;
92  // light space to current space
93  virtual void GetLightToCurrentTransform(
94  float const time,
95  RtMatrix4x4& lightToCurrent) const = 0;
96  // current space to light space
97  virtual void GetCurrentToLightTransform(
98  RtMatrix4x4& lightToCurrent) const = 0;
99  // current space to light space
100  virtual void GetCurrentToLightTransform(
101  float const time,
102  RtMatrix4x4& lightToCurrent) const = 0;
103 
104 protected:
105  // Hide the constructor of this class. It should never be constructed
106  // nor copied directly.
108  ~RixLightContext() override {}
109 
111 };
112 
117 class RixLight
118 {
119 public:
120  enum Type
121  {
124  };
125 
127  {
132  };
133 
135  {
136  int const patchIndex;
137  RtFloat3 const uvw;
139  float const distance;
140 
141  RixSamplePoint (int const& inPatchIndex,
142  RtFloat3 const& inUvw,
143  RtFloat3 const& inDirection,
144  float const& inDistance)
145  : patchIndex(inPatchIndex),
146  uvw(inUvw),
147  direction(inDirection),
148  distance(inDistance)
149  {
150  }
151 
152  };
153 
155  RixLightFactory const* lightFactory,
156  Type type)
157  : m_lightFactory(lightFactory),
158  m_type(type)
159  {
160  }
161 
162  virtual ~RixLight()
163  {
164  }
165 
166  bool IsLocal() const { return m_type == k_RixLocal; }
167  bool IsInfinite() const { return m_type == k_RixInfinite; }
168 
169  // Lights can be queried for general properties. If a particular property
170  // is unsupported, GetProperty() should return k_RixSCInvalidDetail.
171  // Otherwise, return k_RixSCUniform or k_RixSCVarying according to the
172  // detail of the result.
174  {
175  k_LightGroupName, // RtUString
177  k_ShadowColor, // RtColorRGB
179  k_ShadowFalloff, // float
181  k_ShadowSubset, // RtUString
182  k_ShadowExcludeSubset, // RtUString
184  k_ThinShadow, // int
187  k_RixIES, // RixIES*
188  k_Importance, // float
189  // Only flat, single-sided lights should return normals
190  k_LightNormal, // RtVector3
191  k_ApproxFocus, // float
192  k_LightName, // RtUString
194  };
195 
196  virtual RixSCDetail GetProperty(
197  LightProperty prop,
198  void const** result) const = 0;
199 
200  // This methods needs to be implemented for local lights.
201  // It can return a single point (i.e. null extent) for infinite lights.
202  virtual void GetBounds(int& nPoints, RtPoint3 const*& points) const = 0;
203 
204  virtual bool Intersect(
205  bool isTransmissionRay,
206  float const rayTime,
207  RtPoint3 const& rayOrigin,
208  RtVector3 const& rayDirection,
209  // outputs
210  float& hitDistance,
211  float& u,
212  float& v,
213  float& w,
214  RtPoint3& hitP,
215  RtNormal3& hitNn) const = 0;
216 
226  virtual float GetIncidentRadianceEstimate(
227  RtPoint3 const& P,
228  RtMatrix4x4 const& lightToCurrent,
229  RtMatrix4x4 const& currentToLight) const = 0;
230 
239  virtual float GetIncidentRadianceEstimate(
240  RtPoint3 const& segmentOrigin,
241  RtVector3 const& segmentDir,
242  float segmentLen,
243  RtMatrix4x4 const& lightToCurrent,
244  RtMatrix4x4 const& currentToLight,
245  RtFloat& minT,
246  RtFloat& maxT) const = 0;
247 
255  virtual float GetPowerEstimate(RtMatrix4x4 const& xform) const = 0;
256 
268  {
269  public:
270  int& patchIndex; // only set by mesh lights
273  float& distance;
274  float& pdfDirect;
275  bool const isBidirectional;
276  float& pdfEmit;
282  };
283  virtual void GenerateSamples(
284  RixLightContext const& lCtx,
285  RixScatterPoint const& scatter,
286  GenerateSamplesResults& results) const = 0;
287 
297  {
298  float& pdfDirect;
299  bool const isBidirectional;
300  float& pdfEmit;
306  };
307  virtual void EvaluateSamples(
308  RixLightContext const& lCtx,
309  RixSamplePoint const& sample,
310  RixScatterPoint const& scatter,
311  EvaluateSamplesResults& results) const = 0;
312 
317  {
318  int& patchIndex; // only set by mesh lights
323  float& distance;
324  float& pdfEmit; // area measure
326  };
327  virtual void GenerateEmission(
328  RixLightContext const& lCtx,
329  GenerateEmissionResults& results) const = 0;
330 
335  {
337  };
338  virtual void EvaluateEmissionForCamera(
339  RixLightContext const& lCtx,
340  RixSamplePoint const& sample,
341  RixScatterPoint const& scatter,
342  EvaluateEmissionForCameraResults& results) const = 0;
343 
344  // This method is called when a light has been edited. It is up to
345  // the implementation of the light to determine if the edit can be
346  // done in place, or if a new light needs to be created. If the edit
347  // is done in place, the light returned should be "this".
348  virtual RixLight* Edit(
349  RixContext& ctx,
350  RtUString const name,
351  RixParameterList const* pList,
352  void* instanceData) = 0;
353 
354 protected:
356 
357 private:
358  Type m_type;
359 };
360 
365 {
366 public:
367  int GetInterface() const override { return k_RixLightFactory; }
368 
369  virtual RixLight* CreateLight(
370  RixContext& ctx,
371  RtUString const name,
372  RixParameterList const* pList,
373  void* instanceData) = 0;
374 
375  virtual void DestroyLight(RixLight const* light) = 0;
376 
377 protected:
379  ~RixLightFactory() override {}
380 };
381 
382 #define RIX_LIGHTFACTORYCREATE \
383  extern "C" PRMANEXPORT RixLightFactory* CreateRixLightFactory(RtUString const hint)
384 
385 #define RIX_LIGHTFACTORYDESTROY \
386  extern "C" PRMANEXPORT void DestroyRixLightFactory(RixLightFactory* factory)
387 
388 #endif
bool IsLocal() const
Definition: RixLight.h:166
Definition: RixPhotonGuiding.h:51
float & solidAngleToArea
Definition: RixLight.h:278
Generate the color for lights visible to the camera.
Definition: RixLight.h:334
Definition: RixLight.h:185
RixBXEvaluateDomain evalDomain
Definition: RixLight.h:131
RtVector3 & direction
Definition: RixLight.h:272
float & pdfEmit
Definition: RixLight.h:276
float const distance
Definition: RixLight.h:139
Definition: RixLight.h:175
RixLight This base class defines the interface for light sources.
Definition: RixLight.h:117
int & patchIndex
Definition: RixLight.h:270
RtColorRGB diffuseColor
Definition: RixLight.h:303
RixBXEvaluateDomain
The RixBxdf interface is a shading plugin responsible for creating a RixBxdf from the the ShadingCont...
Definition: RixBxdf.h:121
Definition: RixLight.h:182
virtual void GenerateSamples(RixLightContext const &lCtx, RixScatterPoint const &scatter, GenerateSamplesResults &results) const =0
Definition: RixLight.h:126
pxrcore::ColorRGB RtColorRGB
Definition: RiTypesHelper.h:520
#define k_RixShadingVersion
Definition: RixShading.h:97
RtColorRGB specularColor
Definition: RixLight.h:304
virtual void GenerateEmission(RixLightContext const &lCtx, GenerateEmissionResults &results) const =0
Rix interfaces are obtained from an RixContext.
Definition: RixInterfaces.h:172
Definition: RixLight.h:178
RixShadingPlugin is the base class for RixBxdfFactory, RixDisplacementFactory, RixDisplayFilter, RixIntegrator, RixLightFilter, RixLightFactory, RixPattern, RixProjection, and RixSampleFilter.
Definition: RixShading.h:168
RtColorRGB specularColor
Definition: RixLight.h:280
RtColorRGB cameraColor
Definition: RixLight.h:336
RtFloat3 const uvw
Definition: RixLight.h:137
Definition: RixLight.h:179
RtPoint3 & position
Definition: RixLight.h:320
RtFloat3 & UVW
Definition: RixLight.h:319
virtual bool Intersect(bool isTransmissionRay, float const rayTime, RtPoint3 const &rayOrigin, RtVector3 const &rayDirection, float &hitDistance, float &u, float &v, float &w, RtPoint3 &hitP, RtNormal3 &hitNn) const =0
float & solidAngleToArea
Definition: RixLight.h:302
virtual float GetTime() const =0
RtFloat3 RtPoint3
Definition: RiTypesHelper.h:70
bool IsInfinite() const
Definition: RixLight.h:167
virtual RixLight * Edit(RixContext &ctx, RtUString const name, RixParameterList const *pList, void *instanceData)=0
RixSamplePoint(int const &inPatchIndex, RtFloat3 const &inUvw, RtFloat3 const &inDirection, float const &inDistance)
Definition: RixLight.h:141
float RtFloat
Definition: ri.h:54
float & pdfEmitDirection
Definition: RixLight.h:277
RixSCDetail
RixSCDetail enumerates the valid sizing qualifiers for SC parameters.
Definition: RixShading.h:432
float & pdfEmitDirection
Definition: RixLight.h:325
float & pdfEmitDirection
Definition: RixLight.h:301
float & pdfEmit
Definition: RixLight.h:300
Definition: RixLight.h:183
virtual void EvaluateEmissionForCamera(RixLightContext const &lCtx, RixSamplePoint const &sample, RixScatterPoint const &scatter, EvaluateEmissionForCameraResults &results) const =0
virtual void GetCurrentToLightTransform(RtMatrix4x4 &lightToCurrent) const =0
RtFloat3 const direction
Definition: RixLight.h:138
RixLightFactory()
Definition: RixLight.h:378
Definition: RiTypesHelper.h:82
int const patchIndex
Definition: RixLight.h:136
float & pdfEmit
Definition: RixLight.h:324
float & pdfDirect
Definition: RixLight.h:274
RixParameterList exposes the non-varying values that are associated with the definition or editing of...
Definition: RixShading.h:575
Definition: RixLight.h:192
Type
Definition: RixLight.h:120
Definition: RixLight.h:134
pxrcore::Float3 RtFloat3
Definition: RiTypesHelper.h:69
Light Factory.
Definition: RixLight.h:364
Definition: RiTypesHelper.h:327
EvaluateSamples Given surface information, q, and ray hit information on this light source wo...
Definition: RixLight.h:296
RtVector3 & direction
Definition: RixLight.h:322
~RixLightFactory() override
Definition: RixLight.h:379
GenerateSamples() Generate samples, using data from the RixLightContext object:
Definition: RixLight.h:267
virtual void DestroyLight(RixLight const *light)=0
Definition: RixLight.h:181
RixLight(RixLightFactory const *lightFactory, Type type)
Definition: RixLight.h:154
Definition: RixLight.h:193
float & distance
Definition: RixLight.h:323
bool const isBidirectional
Definition: RixLight.h:275
RtNormal3 & normal
Definition: RixLight.h:305
virtual RixLight * CreateLight(RixContext &ctx, RtUString const name, RixParameterList const *pList, void *instanceData)=0
RtFloat3 RtNormal3
Definition: RiTypesHelper.h:73
virtual void EvaluateSamples(RixLightContext const &lCtx, RixSamplePoint const &sample, RixScatterPoint const &scatter, EvaluateSamplesResults &results) const =0
virtual void GetBounds(int &nPoints, RtPoint3 const *&points) const =0
Definition: RixLight.h:176
RtFloat3 & UVW
Definition: RixLight.h:271
RtPoint3 const scatterP
Definition: RixLight.h:128
RixLightContext()
Definition: RixLight.h:107
virtual RixSCDetail GetProperty(LightProperty prop, void const **result) const =0
virtual void GetSample4D(RtFloat2 &xy, RtFloat2 &zw) const =0
Definition: RixLight.h:186
Generate a sample on a light for photon emission.
Definition: RixLight.h:316
virtual RtFloat2 GetSample2D() const =0
Definition: RixLight.h:177
Definition: RixLight.h:122
RtVector3 const scatterV
Definition: RixLight.h:130
RixLightContext This class provides access to the rendering context during light sampling and evaluat...
Definition: RixLight.h:56
virtual void GetFromToTransform(RtUString from, RtUString to, const float time, RtMatrix4x4 &xform) const =0
bool const isBidirectional
Definition: RixLight.h:299
Definition: RixLight.h:191
pxrcore::Matrix4x4 RtMatrix4x4
Definition: RiTypesHelper.h:74
Definition: RixLight.h:180
RixPhotonGuiding const * GetPhotonGuiding() const
Public interface.
Definition: RixLight.h:64
Definition: RixLight.h:190
RtNormal3 & normal
Definition: RixLight.h:281
virtual ~RixLight()
Definition: RixLight.h:162
Definition: RixShading.h:115
Definition: RixLight.h:123
RixPhotonGuiding const * m_pPhotonGuiding
Definition: RixLight.h:110
virtual void GetLightToCurrentTransform(RtMatrix4x4 &lightToCurrent) const =0
LightProperty
Definition: RixLight.h:173
pxrcore::UString RtUString
Definition: RiTypesHelper.h:682
virtual float GetPowerEstimate(RtMatrix4x4 const &xform) const =0
GetPowerEstimate Returns an estimate of the power emitted by this light.
int GetInterface() const override
Definition: RixLight.h:367
virtual float GetIncidentRadianceEstimate(RtPoint3 const &P, RtMatrix4x4 const &lightToCurrent, RtMatrix4x4 const &currentToLight) const =0
GetIncidentRadianceEstimate Returns an estimate of the radiance this light will return for a shading ...
float & distance
Definition: RixLight.h:273
RtColorRGB diffuseColor
Definition: RixLight.h:279
~RixLightContext() override
Definition: RixLight.h:108
Definition: RixLight.h:188
RtNormal3 const scatterN
Definition: RixLight.h:129
Definition: RixLight.h:184
RtNormal3 & normal
Definition: RixLight.h:321
virtual void GetWorldBBox(RtBBox &worldBBox) const =0
RtFloat3 RtVector3
Definition: RiTypesHelper.h:72
float & pdfDirect
Definition: RixLight.h:298
int & patchIndex
Definition: RixLight.h:318
Definition: RixLight.h:187
RixLightFactory const * m_lightFactory
Definition: RixLight.h:355