RixLightFilter.h Source File

RixLightFilter.h
1 #ifndef RixLightFilter_h
2 #define RixLightFilter_h
3 /* $Revision: #4 $ $Date: 2015/09/01 $
4 # ------------------------------------------------------------------------------
5 #
6 # Copyright (c) 2015 Pixar Animation Studios. All rights reserved.
7 #
8 # The information in this file (the "Software") is provided for the
9 # exclusive use of the software licensees of Pixar. Licensees have
10 # the right to incorporate the Software into other products for use
11 # by other authorized software licensees of Pixar, without fee.
12 # Except as expressly permitted herein, the Software may not be
13 # disclosed to third parties, copied or duplicated in any form, in
14 # whole or in part, without the prior written permission of
15 # Pixar Animation Studios.
16 #
17 # The copyright notices in the Software and this entire statement,
18 # including the above license grant, this restriction and the
19 # following disclaimer, must be included in all copies of the
20 # Software, in whole or in part, and all permitted derivative works of
21 # the Software, unless such copies or derivative works are solely
22 # in the form of machine-executable object code generated by a
23 # source language processor.
24 #
25 # PIXAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
26 # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
27 # SHALL PIXAR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
28 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
29 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
30 # ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
31 # SOFTWARE.
32 #
33 # Pixar
34 # 1200 Park Ave
35 # Emeryville CA 94608
36 #
37 # ------------------------------------------------------------------------------
38 */
39 
40 #include "RixShading.h"
41 
42 struct RixBXLobeTraits;
43 struct RixBXLobeWeights;
44 
46 
62 {
63 public:
64 
65  virtual int GetInterface() const { return k_RixLightFilter; }
66 
67  virtual int Init(RixContext &ctx, char const *pluginPath) = 0;
68  virtual void Finalize(RixContext &) = 0;
69 
70  virtual RixSCParamInfo const *GetParamTable() = 0;
71 
75  virtual void Filter(RixLightFilterContext const *lfCtx,
76  RtConstPointer instancedata,
77  RtInt const numSamples,
78  RtInt const * shadingCtxIndex,
79  RtVector3 const * toLight,
80  RtFloat const * dist,
81  RtFloat const * lightPdfIllum,
82  RixBXLobeWeights *contribution
83  ) = 0;
84 
85 protected:
86  RixLightFilter() : RixShadingPlugin(k_RixShadingVersion) {}
87  virtual ~RixLightFilter() {}
88 };
89 
90 #define RIX_LIGHTFILTERPLUGINCREATE \
91 extern "C" PRMANEXPORT RixLightFilter *CreateRixLightFilter(const char *hint)
92 
93 #define RIX_LIGHTFILTERPLUGINDESTROY \
94 extern "C" PRMANEXPORT void DestroyRixLightFilter(RixLightFilter *modifier)
95 
106 class RixLightFilterContext : public RixContext
107 {
108 public:
109 
110  RtInt numPts;
111 
114  virtual bool IsEnabled(RtConstPointer instance, RtConstPointer* instanceData) const = 0;
115 
117  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, RtInt const**var) const = 0;
118  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, RtFloat const**var) const = 0;
119  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, RtFloat3 const**var) const = 0;
120  virtual void GetBuiltinVar(RixShadingContext::BuiltinVar, RixLPEState * const**var) const = 0;
121 
123  virtual RixSCDetail GetPrimVar(char const *name, RtFloat fill,
124  RtFloat const **var,
125  RtFloat const **radius=NULL) const = 0;
126  virtual RixSCDetail GetPrimVar(char const *name, RtFloat2 fill,
127  RtFloat2 const **var,
128  RtFloat const **radius=NULL) const = 0;
129  virtual RixSCDetail GetPrimVar(char const *name, RtFloat3 fill,
130  RtFloat3 const **var,
131  RtFloat const **radius=NULL) const = 0;
132  virtual RixSCDetail GetPrimVar(char const *name,
133  RtConstString **var) const = 0;
134 
139  virtual int Transform(RixShadingContext::TransformInterpretation interp,
140  char const *fromSpace, char const *toSpace,
141  RtFloat3 *var, RtFloat *width = NULL) const = 0;
142 
143  // Separate source and destination arrays.
144  virtual int Transform(RixShadingContext::TransformInterpretation interp,
145  char const *fromSpace, char const *toSpace,
146  RtFloat3 const * srcVar, RtFloat3 * dstVar,
147  RtFloat const * srcWidth, RtFloat * dstWidth) const = 0;
148 
156  virtual int Transform(RixShadingContext::TransformInterpretation interp,
157  char const *fromSpace, char const *toSpace,
158  RtInt numPts, RtInt const * shadingCtxIndex,
159  RtFloat3 const * srcVar, RtFloat3 * dstVar,
160  RtFloat const * srcWidth, RtFloat * dstWidth) const = 0;
167  // use "placement new" and not rely on invocation of a destructor.
168  virtual void *Allocate(size_t n, size_t size) const = 0;
169 
177  template <class T>
178  T *New(size_t nObjs) const
179  {
180  T *mem = static_cast<T*>(Allocate(nObjs, sizeof(T)));
181  return new (mem) T[nObjs];
182  }
183 
195  class Allocator
196  {
197  public:
198  Allocator(RixLightFilterContext const *lfCtx) : m_lfCtx(lfCtx) {}
199  template <typename T>
200  T *Allocate(RtInt num)
201  {
202  if(num == 0) return NULL;
203  return (T *) m_lfCtx->Allocate(num, sizeof(T));
204  }
205 
206  private:
207  RixLightFilterContext const *m_lfCtx;
208  };
209 
210 protected:
211  virtual ~RixLightFilterContext() {}
212 };
213 
214 #endif