RenderManAPI  24.0
RixLightFilter.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 RixLightFilter_h
38 #define RixLightFilter_h
39 
40 #include <cstddef> // for NULL, size_t
41 #include <new> // for operator new
42 #include "RixBxdf.h" // for RixBXLobeSampled
43 #include "RixInterfaces.h" // for RixContext
44 #include "RixShading.h" // for RixShadingContext, etc
45 #include "prmanapi.h" // for PRMANEXPORT
46 #include "RiTypesHelper.h" // for RtVector3, etc.
47 
48 class RixLPEState;
50 struct RixBXLobeWeights;
51 
67 {
68 public:
69  int GetInterface() const override
70  {
71  return k_RixLightFilter;
72  }
73 
77  virtual void Filter(RixLightFilterContext const* lfCtx, void* instanceData,
78  int const numSamples, int const* shadingCtxIndex,
79  RtVector3 const* directions, float const* distances,
80  float const* lightPdfsDirect, RixBXLobeWeights* contribution) = 0;
81 
91  {
94  };
96 
98  RixLightFilterContext const* lfCtx,
99  void* instanceData, float* result) const = 0;
100 
101  // Lights can be queried for general properties. If a particular property
102  // is unsupported, GetProperty() should return k_RixSCInvalidDetail.
103  // Otherwise, return k_RixSCUniform or k_RixSCVarying according to the
104  // detail of the result.
106  {
107  // RtUString: The group(s) to which the filter belongs for linking purposes.
108  // If empty, the light filter is enabled everywhere.
110  // int: if non-zero, the ShadowFilter method will be called
111  // by the renderer to determine the light filter's effects on
112  // shadows
115  };
116 
117  virtual RixSCDetail GetProperty(void* instanceData, LightFilterProperty prop,
118  void const** result) const = 0;
119 
120 protected:
122  {}
123  ~RixLightFilter() override
124  {}
125 
126 public:
132  virtual void ShadowFilter(RixLightFilterContext const* lfCtx, void* instanceData,
133  int const numSamples, int const* shadingCtxIndex,
134  RtVector3 const* directions, float const* distances,
135  RixBXLobeSampled const* incidentLobeSampled,
136  RtColorRGB* transmissions)
137  {
138  PIXAR_ARGUSED(lfCtx);
139  PIXAR_ARGUSED(instanceData);
140  PIXAR_ARGUSED(numSamples);
141  PIXAR_ARGUSED(shadingCtxIndex);
142  PIXAR_ARGUSED(directions);
143  PIXAR_ARGUSED(distances);
144  PIXAR_ARGUSED(incidentLobeSampled);
145  PIXAR_ARGUSED(transmissions);
146  }
147 };
148 
149 // clang-format off
150 #define RIX_LIGHTFILTERPLUGINCREATE \
151  extern "C" PRMANEXPORT RixLightFilter* CreateRixLightFilter(const char* hint)
152 
153 #define RIX_LIGHTFILTERPLUGINDESTROY \
154  extern "C" PRMANEXPORT void DestroyRixLightFilter(RixLightFilter* modifier)
155 // clang-format on
156 
168 {
169 public:
170  int numPts;
171 
174  virtual bool IsEnabled(void const* instance, void** instanceData) const = 0;
175 
177  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, int const** var) const = 0;
178  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, float const** var) const = 0;
179  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, RtFloat3 const** var) const = 0;
180  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, RixLPEState* const** var) const = 0;
181 
183  virtual RixSCDetail GetPrimVar(RtUString const name, float fill, float const** var,
184  float const** radius = NULL) const = 0;
185  virtual RixSCDetail GetPrimVar(RtUString const name, RtFloat2 fill, RtFloat2 const** var,
186  float const** radius = NULL) const = 0;
187  virtual RixSCDetail GetPrimVar(RtUString const name, RtFloat3 fill, RtFloat3 const** var,
188  float const** radius = NULL) const = 0;
189  virtual RixSCDetail GetPrimVar(RtUString const name, RtUString const** var) const = 0;
190  virtual RixSCDetail GetPrimVar(RtUString const name, RtMatrix4x4 const& fill,
191  RtMatrix4x4 const** var) const = 0;
192 
198  RtUString const fromSpace, RtUString const toSpace, RtFloat3* var,
199  float* width = NULL) const = 0;
200 
201  // Separate source and destination arrays.
203  RtUString const fromSpace, RtUString const toSpace,
204  RtFloat3 const* srcVar, RtFloat3* dstVar, float const* srcWidth,
205  float* dstWidth) const = 0;
206 
215  RtUString const fromSpace, RtUString const toSpace, int numPts,
216  int const* shadingCtxIndex, RtFloat3 const* srcVar, RtFloat3* dstVar,
217  float const* srcWidth, float* dstWidth) const = 0;
224  // use "placement new" and not rely on invocation of a destructor.
225  virtual void* Allocate(size_t n, size_t size) const = 0;
226 
234  template <class T>
235  T* New(size_t nObjs) const
236  {
237  T* mem = static_cast<T*>(Allocate(nObjs, sizeof(T)));
238  return new (mem) T[nObjs];
239  }
240 
252  class Allocator
253  {
254  public:
255  Allocator(RixLightFilterContext const* lfCtx) : m_lfCtx(lfCtx)
256  {}
257  template <typename T>
258  T* Allocate(int num)
259  {
260  if (num == 0) return NULL;
261  return (T*)m_lfCtx->Allocate(num, sizeof(T));
262  }
263 
264  private:
265  RixLightFilterContext const* m_lfCtx;
266  };
267 
268 protected:
270  {}
271 
272 public:
291  void* instanceData) const = 0;
292 
295  virtual void EndMutableContext(RixShadingContext* ctx) const = 0;
296 
298  virtual RixLight* GetCurrentLight() const = 0;
299 };
300 
301 #endif
RixShadingContext is analogous to a RenderMan grid - it is a group of 1 or more points that may be sh...
Definition: RixShading.h:663
int GetInterface() const override
Definition: RixLightFilter.h:69
virtual void EndMutableContext(RixShadingContext *ctx) const =0
Terminates the mutable shading context created by CreateMutableContext().
virtual int Transform(RixShadingContext::TransformInterpretation interp, RtUString const fromSpace, RtUString const toSpace, RtFloat3 *var, float *width=NULL) const =0
Transform an array of RtFloat3 (and optional width) the same size as the numPts in the RixLightFilter...
virtual RixSCDetail GetProperty(void *instanceData, LightFilterProperty prop, void const **result) const =0
RixLight This base class defines the interface for light sources.
Definition: RixLight.h:117
pxrcore::ColorRGB RtColorRGB
Definition: RiTypesHelper.h:520
#define k_RixShadingVersion
Definition: RixShading.h:97
Rix interfaces are obtained from an RixContext.
Definition: RixInterfaces.h:172
RixLightFilter()
Definition: RixLightFilter.h:121
BuiltinVar
Definition: RixShading.h:937
RixShadingPlugin is the base class for RixBxdfFactory, RixDisplacementFactory, RixDisplayFilter, RixIntegrator, RixLightFilter, RixLightFactory, RixPattern, RixProjection, and RixSampleFilter.
Definition: RixShading.h:168
The amount by which a light&#39;s radiance is multiplied.
Definition: RixLightFilter.h:93
int numPts
Definition: RixLightFilter.h:170
The RixLightFilterContext provides limited access to data from the shading context associated with a ...
Definition: RixLightFilter.h:167
virtual void ShadowFilter(RixLightFilterContext const *lfCtx, void *instanceData, int const numSamples, int const *shadingCtxIndex, RtVector3 const *directions, float const *distances, RixBXLobeSampled const *incidentLobeSampled, RtColorRGB *transmissions)
Called after Filter has run and default shadow rays have been traced.
Definition: RixLightFilter.h:132
RixSCDetail
RixSCDetail enumerates the valid sizing qualifiers for SC parameters.
Definition: RixShading.h:432
~RixLightFilterContext() override
Definition: RixLightFilter.h:269
Definition: RixLightFilter.h:109
virtual RixLight * GetCurrentLight() const =0
Get the current light associated with the context of execution.
This struct represents the characteristics of just one lobe of a bxdf.
Definition: RixBxdfLobe.h:63
virtual void * Allocate(size_t n, size_t size) const =0
Allocate: fast memory allocation support from a memory pool tailored to light modifier plugins...
Definition: RixBxdfLobe.h:428
Definition: RiTypesHelper.h:82
TransformInterpretation
Definition: RixShading.h:1113
Definition: RixShading.h:116
pxrcore::Float3 RtFloat3
Definition: RiTypesHelper.h:69
Allocator is a utility (fully inlined) class to assist with tedious memory pool allocations.
Definition: RixLightFilter.h:252
virtual RixSCDetail GetPrimVar(RtUString const name, float fill, float const **var, float const **radius=NULL) const =0
Retrieve primitive variables from the underlying shading context.
virtual bool GetRadianceModifier(FilterRadianceModifierProperty property, RixLightFilterContext const *lfCtx, void *instanceData, float *result) const =0
T * Allocate(int num)
Definition: RixLightFilter.h:258
LightFilterProperty
Definition: RixLightFilter.h:105
virtual RixShadingContext * CreateMutableContext(RixLightFilter const *filter, void *instanceData) const =0
Creates a mutable shading context that can be used to re-evaluate connected inputs to the lightfilter...
RixLightFilter plugins modify the lighting contribution to a surface point after a light has been sam...
Definition: RixLightFilter.h:66
virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, int const **var) const =0
Retrieve built-in variables from the underlying shading context.
Definition: RixLightFilter.h:113
~RixLightFilter() override
Definition: RixLightFilter.h:123
Definition: RixLightFilter.h:92
pxrcore::Matrix4x4 RtMatrix4x4
Definition: RiTypesHelper.h:74
Represents the LPE system state of a light transport path.
Definition: RixLPE.h:439
Allocator(RixLightFilterContext const *lfCtx)
Definition: RixLightFilter.h:255
pxrcore::UString RtUString
Definition: RiTypesHelper.h:682
FilterRadianceModifierProperty
Light filters can be queried as to what effect they will have on radiance.
Definition: RixLightFilter.h:90
T * New(size_t nObjs) const
New is a utility (fully inlined) non-virtual method to assist with tedious memory allocation tasks...
Definition: RixLightFilter.h:235
virtual void Filter(RixLightFilterContext const *lfCtx, void *instanceData, int const numSamples, int const *shadingCtxIndex, RtVector3 const *directions, float const *distances, float const *lightPdfsDirect, RixBXLobeWeights *contribution)=0
Called after light sample generation, before bxdf evaluation.
RtFloat3 RtVector3
Definition: RiTypesHelper.h:72
Definition: RixLightFilter.h:114
virtual bool IsEnabled(void const *instance, void **instanceData) const =0
Determine whether or not the given instance of a light filter is active.
#define PIXAR_ARGUSED(x)
Definition: prmanapi.h:170