RenderMan  26.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RixLightFilter.h
Go to the documentation of this file.
1 /*
2 # ------------------------------------------------------------------------------
3 #
4 # Copyright (c) 2021 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  {
96  };
97 
99  RixLightFilterContext const* lfCtx,
100  void* instanceData, float* result) const = 0;
101 
102  // Lights can be queried for general properties. If a particular property
103  // is unsupported, GetProperty() should return k_RixSCInvalidDetail.
104  // Otherwise, return k_RixSCUniform or k_RixSCVarying according to the
105  // detail of the result.
107  {
108  // RtUString: The group(s) to which the filter belongs for linking purposes.
109  // If empty, the light filter is enabled everywhere.
111  // int: if non-zero, the ShadowFilter method will be called
112  // by the renderer to determine the light filter's effects on
113  // shadows
116  };
117 
118  virtual RixSCDetail GetProperty(void* instanceData, LightFilterProperty prop,
119  void const** result) const = 0;
120 
121 protected:
123  {}
124  ~RixLightFilter() override
125  {}
126 
127 public:
133  virtual void ShadowFilter(RixLightFilterContext const* lfCtx, void* instanceData,
134  int const numSamples, int const* shadingCtxIndex,
135  RtVector3 const* directions, float const* distances,
136  RixBXLobeSampled const* incidentLobeSampled,
137  RtColorRGB* transmissions)
138  {
139  PIXAR_ARGUSED(lfCtx);
140  PIXAR_ARGUSED(instanceData);
141  PIXAR_ARGUSED(numSamples);
142  PIXAR_ARGUSED(shadingCtxIndex);
143  PIXAR_ARGUSED(directions);
144  PIXAR_ARGUSED(distances);
145  PIXAR_ARGUSED(incidentLobeSampled);
146  PIXAR_ARGUSED(transmissions);
147  }
148 };
149 
150 // clang-format off
151 #define RIX_LIGHTFILTERPLUGINCREATE \
152  extern "C" PRMANEXPORT RixLightFilter* CreateRixLightFilter(const char* hint)
153 
154 #define RIX_LIGHTFILTERPLUGINDESTROY \
155  extern "C" PRMANEXPORT void DestroyRixLightFilter(RixLightFilter* modifier)
156 // clang-format on
157 
169 {
170 public:
171  int numPts;
172 
175  virtual bool IsEnabled(void const* instance, void** instanceData) const = 0;
176 
178  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, int const** var) const = 0;
179  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, float const** var) const = 0;
180  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, RtFloat3 const** var) const = 0;
181  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, RixLPEState* const** var) const = 0;
182 
184  virtual RixSCDetail GetPrimVar(RtUString const name, float fill, float const** var,
185  float const** radius = NULL) const = 0;
186  virtual RixSCDetail GetPrimVar(RtUString const name, RtFloat2 fill, RtFloat2 const** var,
187  float const** radius = NULL) const = 0;
188  virtual RixSCDetail GetPrimVar(RtUString const name, RtFloat3 fill, RtFloat3 const** var,
189  float const** radius = NULL) const = 0;
190  virtual RixSCDetail GetPrimVar(RtUString const name, RtUString const** var) const = 0;
191  virtual RixSCDetail GetPrimVar(RtUString const name, RtMatrix4x4 const& fill,
192  RtMatrix4x4 const** var) const = 0;
193 
199  RtUString const fromSpace, RtUString const toSpace, RtFloat3* var,
200  float* width = NULL) const = 0;
201 
202  // Separate source and destination arrays.
204  RtUString const fromSpace, RtUString const toSpace,
205  RtFloat3 const* srcVar, RtFloat3* dstVar, float const* srcWidth,
206  float* dstWidth) const = 0;
207 
216  RtUString const fromSpace, RtUString const toSpace, int numPts,
217  int const* shadingCtxIndex, RtFloat3 const* srcVar, RtFloat3* dstVar,
218  float const* srcWidth, float* dstWidth) const = 0;
225  // use "placement new" and not rely on invocation of a destructor.
226  virtual void* Allocate(size_t n, size_t size) const = 0;
227 
235  template <class T>
236  T* New(size_t nObjs) const
237  {
238  T* mem = static_cast<T*>(Allocate(nObjs, sizeof(T)));
239  return new (mem) T[nObjs];
240  }
241 
253  class Allocator
254  {
255  public:
256  Allocator(RixLightFilterContext const* lfCtx) : m_lfCtx(lfCtx)
257  {}
258  template <typename T>
259  T* Allocate(int num)
260  {
261  if (num == 0) return NULL;
262  return (T*)m_lfCtx->Allocate(num, sizeof(T));
263  }
264 
265  private:
266  RixLightFilterContext const* m_lfCtx;
267  };
268 
269 protected:
271  {}
272 
273 public:
292  void* instanceData) const = 0;
293 
296  virtual void EndMutableContext(RixShadingContext* ctx) const = 0;
297 
299  virtual RixLight* GetCurrentLight() const = 0;
300 
305  virtual RixDisplayServices* GetDisplayServices(int version = 1) const = 0;
306 
309  virtual const int* GetIntegratorCtxIndexMap() const = 0;
310 };
311 
312 #endif