RenderMan API  23.0
RixLight.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 RixLight_h
39 #define RixLight_h
40 
41 #include <cstddef> // for NULL
42 #include "RixBxdf.h" // for RixBXEvaluateDomain
43 #include "RixIES.h" // for RixIES
44 #include "RixShading.h" // for RixParameterList (ptr only), etc
45 #include "prmanapi.h" // for PRMANEXPORT
46 #include "ri.h" // for RtColorRGB, RtPoint3, etc
47 
48 class RixContext;
49 class RixLightFactory;
50 class RixPhotonGuiding;
51 
58 {
59 public:
64  // Retrieve the RixPhotonGuiding object given to the LightingServices
66  {
67  return m_pPhotonGuiding;
68  }
69 
70  // Obtain the time associated with this query
71  virtual float GetTime() const = 0;
72 
73  // Obtain a sample for the i'th element in this query context.
74  // Only valid when in a sampling context. Will return 0,0 otherwise
75  virtual RtFloat2 GetSample2D() const = 0;
76  virtual void GetSample4D(RtFloat2& xy, RtFloat2& zw) const = 0;
77 
78  // BBox encompassing the world. Needed for environment lights to emit
79  // photons when there is no photon guiding object available
80  virtual void GetWorldBBox(RtBBox& worldBBox) const = 0;
81 
82  // Transform between named spaces
83  virtual void GetFromToTransform(
84  RtUString from, RtUString to,
85  const float time,
86  RtMatrix4x4& xform) const = 0;
87  virtual void GetFromToTransform(
88  RtUString from, RtUString to,
89  RtMatrix4x4& xform) const = 0;
90  // light space to current space
91  virtual void GetLightToCurrentTransform(
92  RtMatrix4x4& lightToCurrent) const = 0;
93  // light space to current space
94  virtual void GetLightToCurrentTransform(
95  float const time,
96  RtMatrix4x4& lightToCurrent) const = 0;
97  // current space to light space
98  virtual void GetCurrentToLightTransform(
99  RtMatrix4x4& lightToCurrent) const = 0;
100  // current space to light space
101  virtual void GetCurrentToLightTransform(
102  float const time,
103  RtMatrix4x4& lightToCurrent) const = 0;
104 
105 protected:
106  // Hide the constructor of this class. It should never be constructed
107  // nor copied directly.
109  virtual ~RixLightContext() {}
110 
112 };
113 
118 class RixLight
119 {
120 public:
121  enum Type
122  {
124  k_RixInfinite
125  };
126 
128  {
133  };
134 
136  {
137  int const patchIndex;
138  RtFloat3 const uvw;
140  float const distance;
141 
142  RixSamplePoint (int const& inPatchIndex,
143  RtFloat3 const& inUvw,
144  RtFloat3 const& inDirection,
145  float const& inDistance)
146  : patchIndex(inPatchIndex),
147  uvw(inUvw),
148  direction(inDirection),
149  distance(inDistance)
150  {
151  }
152 
153  };
154 
156  RixLightFactory const* lightFactory,
157  Type type)
158  : m_lightFactory(lightFactory),
159  m_type(type)
160  {
161  }
162 
163  virtual ~RixLight()
164  {
165  }
166 
167  bool IsLocal() const { return m_type == k_RixLocal; }
168  bool IsInfinite() const { return m_type == k_RixInfinite; }
169 
170  // Lights can be queried for general properties. If a particular property
171  // is unsupported, GetProperty() should return k_RixSCInvalidDetail.
172  // Otherwise, return k_RixSCUniform or k_RixSCVarying according to the
173  // detail of the result.
175  {
176  k_LightGroupName, // RtUString
178  k_ShadowColor, // RtColorRGB
180  k_ShadowFalloff, // float
182  k_ShadowSubset, // RtUString
183  k_ShadowExcludeSubset, // RtUString
185  k_ThinShadow, // int
188  k_RixIES, // RixIES*
189  k_Importance, // float
190  // Only flat, single-sided lights should return normals
191  k_LightNormal, // RtVector3
192  k_ApproxFocus, // float
193  k_LightName, // RtUString
194  k_numLightProperties
195  };
196 
197  virtual RixSCDetail GetProperty(
198  LightProperty prop,
199  void const** result) const = 0;
200 
201  // This methods needs to be implemented for local lights.
202  // It can return a single point (i.e. null extent) for infinite lights.
203  virtual void GetBounds(int& nPoints, RtPoint3 const*& points) const = 0;
204 
205  virtual bool Intersect(
206  bool isTransmissionRay,
207  float const rayTime,
208  RtPoint3 const& rayOrigin,
209  RtVector3 const& rayDirection,
210  // outputs
211  float& hitDistance,
212  float& u,
213  float& v,
214  float& w,
215  RtPoint3& hitP,
216  RtNormal3& hitNn) const = 0;
217 
227  virtual RtFloat GetIncidentRadianceEstimate(
228  RtPoint3 const& P,
229  RtMatrix4x4 const& lightToCurrent,
230  RtMatrix4x4 const& currentToLight) const = 0;
231 
240  virtual RtFloat GetIncidentRadianceEstimate(
241  RtPoint3 const& segmentOrigin,
242  RtVector3 const& segmentDir,
243  RtFloat segmentLen,
244  RtMatrix4x4 const& lightToCurrent,
245  RtMatrix4x4 const& currentToLight,
246  RtFloat& minT,
247  RtFloat& maxT) const = 0;
248 
256  virtual float GetPowerEstimate(RtMatrix4x4 const& xform) const = 0;
257 
269  {
270  public:
271  int& patchIndex; // only set by mesh lights
274  float& distance;
275  float& pdfDirect;
276  bool const isBidirectional;
277  float& pdfEmit;
283  };
284  virtual void GenerateSamples(
285  RixLightContext const& lCtx,
286  RixScatterPoint const& scatter,
287  GenerateSamplesResults& results) const = 0;
288 
298  {
299  float& pdfDirect;
300  bool const isBidirectional;
301  float& pdfEmit;
307  };
308  virtual void EvaluateSamples(
309  RixLightContext const& lCtx,
310  RixSamplePoint const& sample,
311  RixScatterPoint const& scatter,
312  EvaluateSamplesResults& results) const = 0;
313 
318  {
319  int& patchIndex; // only set by mesh lights
324  float& distance;
325  float& pdfEmit; // area measure
327  };
328  virtual void GenerateEmission(
329  RixLightContext const& lCtx,
330  GenerateEmissionResults& results) const = 0;
331 
336  {
338  };
339  virtual void EvaluateEmissionForCamera(
340  RixLightContext const& lCtx,
341  RixSamplePoint const& sample,
342  RixScatterPoint const& scatter,
343  EvaluateEmissionForCameraResults& results) const = 0;
344 
345  // This method is called when a light has been edited. It is up to
346  // the implementation of the light to determine if the edit can be
347  // done in place, or if a new light needs to be created. If the edit
348  // is done in place, the light returned should be "this".
349  virtual RixLight* Edit(
350  RixContext& ctx,
351  RtUString const name,
352  RixParameterList const* pList,
353  RtPointer instanceData) = 0;
354 
355 protected:
357 
358 private:
359  Type m_type;
360 };
361 
366 {
367 public:
368  virtual int GetInterface() const override { return k_RixLightFactory; }
369 
370  virtual RixLight* CreateLight(
371  RixContext& ctx,
372  RtUString const name,
373  RixParameterList const* pList,
374  RtPointer instanceData) = 0;
375 
376  virtual void DestroyLight(RixLight const* light) = 0;
377 
378 protected:
380  virtual ~RixLightFactory() {}
381 };
382 
383 #define RIX_LIGHTFACTORYCREATE \
384  extern "C" PRMANEXPORT RixLightFactory* CreateRixLightFactory(RtUString const hint)
385 
386 #define RIX_LIGHTFACTORYDESTROY \
387  extern "C" PRMANEXPORT void DestroyRixLightFactory(RixLightFactory* factory)
388 
389 #endif
LightProperty
Definition: RixLight.h:174
float const distance
Definition: RixLight.h:140
RtPoint3 const scatterP
Definition: RixLight.h:129
pxrcore::ColorRGB RtColorRGB
virtual ~RixLightContext()
Definition: RixLight.h:109
void * RtPointer
Definition: ri.h:69
RixBXEvaluateDomain evalDomain
Definition: RixLight.h:132
virtual void GetSample4D(RtFloat2 &xy, RtFloat2 &zw) const =0
virtual void GetWorldBBox(RtBBox &worldBBox) const =0
virtual void GetCurrentToLightTransform(RtMatrix4x4 &lightToCurrent) const =0
float RtFloat
Definition: ri.h:54
RtFloat3 RtPoint3
Definition: RiTypesHelper.h:69
virtual int GetInterface() const override
Definition: RixLight.h:368
RixSCDetail
Definition: RixShading.h:376
RixPhotonGuiding const * GetPhotonGuiding() const
Definition: RixLight.h:65
virtual ~RixLight()
Definition: RixLight.h:163
RtNormal3 const scatterN
Definition: RixLight.h:130
RtFloat3 RtNormal3
Definition: RiTypesHelper.h:72
RixPhotonGuiding const * m_pPhotonGuiding
Definition: RixLight.h:111
RtFloat3 const uvw
Definition: RixLight.h:138
bool IsInfinite() const
Definition: RixLight.h:168
RtVector3 const scatterV
Definition: RixLight.h:131
pxrcore::UString RtUString
#define k_RixShadingVersion
Definition: RixShading.h:97
pxrcore::Matrix4x4 RtMatrix4x4
Definition: RiTypesHelper.h:73
virtual RtFloat2 GetSample2D() const =0
pxrcore::Float3 RtFloat3
Definition: RiTypesHelper.h:68
RtFloat3 const direction
Definition: RixLight.h:139
RixBXEvaluateDomain
Definition: RixBxdf.h:121
virtual void GetLightToCurrentTransform(RtMatrix4x4 &lightToCurrent) const =0
bool IsLocal() const
Definition: RixLight.h:167
virtual void GetFromToTransform(RtUString from, RtUString to, const float time, RtMatrix4x4 &xform) const =0
virtual ~RixLightFactory()
Definition: RixLight.h:380
RixSamplePoint(int const &inPatchIndex, RtFloat3 const &inUvw, RtFloat3 const &inDirection, float const &inDistance)
Definition: RixLight.h:142
RixLight(RixLightFactory const *lightFactory, Type type)
Definition: RixLight.h:155
RixLightFactory const * m_lightFactory
Definition: RixLight.h:356
virtual float GetTime() const =0
RtFloat3 RtVector3
Definition: RiTypesHelper.h:71