RixLPE.h Source File

RixLPE.h
1 #ifndef RixLPE_h
2 #define RixLPE_h
3 /* $Revision: #5 $ $Date: 2015/11/13 $
4 Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
5 All Rights Reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are
9 met:
10 * Redistributions of source code must retain the above copyright
11  notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13  notice, this list of conditions and the following disclaimer in the
14  documentation and/or other materials provided with the distribution.
15 * Neither the name of Sony Pictures Imageworks nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 /*
32 ** This file may contain modifications from the original source code and
33 ** any changes are proprietary confidential information and trade secrets
34 ** of PIXAR, Copyright (c) 2014 PIXAR, all rights reserved. Reverse
35 ** engineering of object code is prohibited. Use of copyright notice
36 ** is precautionary and does not imply publication.
37 **
38 ** Pixar
39 ** 1200 Park Ave.
40 ** Emeryville, CA 94608
41 */
42 
43 #include "RixInterfaces.h"
44 #include "RixIntegrator.h"
45 #include <stack>
46 #include <map>
47 
48 static const RixChannelId k_invalid = 2147483647;
49 
50 typedef std::vector<RixChannelId> ChanIdVec;
51 
52 class RixLPEAutomata;
53 class RixLPEAutomataNfa;
54 
128 class RixLPEState;
129 
130 class RixLPE : public RixInterface
131 {
132  public:
133 
136  {
137  k_NULL = 0,
138  k_NONE,
139  k_CAMERA,
140  k_LIGHT,
141  k_OBJECT,
142  k_TRANSMIT,
143  k_REFLECT,
144  k_STOP,
145  k_BLANK,
146  k_LAMBDA,
147  k_DOT,
148  k_DIFFUSE1,
149  k_DIFFUSE2,
150  k_DIFFUSE3,
151  k_DIFFUSE4,
152  k_SPECULAR1,
153  k_SPECULAR2,
154  k_SPECULAR3,
155  k_SPECULAR4,
156  k_SPECULAR5,
157  k_SPECULAR6,
158  k_SPECULAR7,
159  k_SPECULAR8,
160  k_USER1,
161  k_USER2,
162  k_USER3,
163  k_USER4,
164  k_USER5,
165  k_USER6,
166  k_USER7,
167  k_USER8,
168  k_EVERYLOBE,
169  k_EVERYDIFFUSE,
170  k_EVERYSPECULAR,
171  k_EVERYUSER,
172  k_numBuiltinTokens,
173  };
174 
178  {
179  k_FlagWithOcclusion = 0x1,
180  k_FlagWithThruput = 0x2,
181  k_FlagWithClamp = 0x4,
182  k_FlagShadowsOnly = 0x8,
183  k_FlagHoldOut = 0x10,
184  k_FlagOverwrite = 0x20,
185  k_FlagNoInfiniteCheck = 0x40,
186  };
187 
188  static const int k_baseLgtGrpTokenOffset = k_numBuiltinTokens;
189 
190  // How to update LPE AOVs with the overwrite flag set.
191  enum OverwritePolicy
192  {
193  k_Ignore,
194  k_Overwrite,
195  k_Accumulate
196  };
197 
198  RixLPE()
199  :
200  RixInterface(1),
201  m_anyLPEs(false),
202  m_anyShadowLPEs(false),
203  m_anyCustomLPEs(false),
204  m_anyHoldOutLPEs(false),
205  m_beautyChanId(k_invalid)
206  {
207  }
208 
211  virtual RixLPEState * AllocateStates(int count) = 0;
212 
214  virtual void FreeStates(int count, RixLPEState *states) = 0;
215 
217  PRMAN_INLINE static RixLPEToken LgtGrpIdToToken(RtInt lgtGrpId);
218 
220  PRMAN_INLINE bool AnyLPEs() const;
221 
223  PRMAN_INLINE bool AnyShadowLPEs() const;
224 
226  PRMAN_INLINE bool AnyCustomLPEs() const;
227 
229  PRMAN_INLINE bool AnyHoldOutLPEs() const;
230 
231 
232  protected:
233 
235  virtual ~RixLPE() {}
236 
238  bool m_anyLPEs;
239 
242 
245 
248 
250  RixChannelId m_beautyChanId;
251 
252  public:
253 
254  typedef RixLPEState State;
255 
259  {
260  public:
261 
267  PRMAN_INLINE
268  SplatHelper(RixDisplayServices *displaySvc, RtInt integratorCtxIdx,
269  RixLPE &rixLpe, RixLPEState &state, RtInt depth,
270  RtInt lgtGrpId, RixLPEToken lpeGrpId,
271  bool isReflect,
272  RtColorRGB const &eyeTrans, RtColorRGB const &lgtTrans,
273  RixShadingContext const *sCtx, RtInt shadingCtxIdx);
274 
275  PRMAN_INLINE ~SplatHelper();
276 
284  PRMAN_INLINE void SplatPerLobe(RixBXActiveLobeWeights &activeLobes,
285  int weightIndex,
286  RtColorRGB const &shadowWeight,
287  RtColorRGB const &thruput,
288  bool isFinite, RtFloat clamp = 1.0f,
289  RtColorRGB const &backgroundColor = RixConstants::k_ZeroRGB,
290  bool isShadowCollector = false);
291 
299  PRMAN_INLINE void SplatEmission(RtColorRGB const &emission,
300  RtColorRGB const &thruput,
301  bool isFinite, RtFloat clamp = 1.0f,
302  bool isShadowCollector = false);
303 
311  PRMAN_INLINE void SplatValue(RtColorRGB const &color,
312  RtColorRGB const &shadowWeight,
313  bool isFinite, RtFloat clamp = 1.0f,
314  RtColorRGB const &backgroundColor = RixConstants::k_ZeroRGB,
315  bool isShadowCollector = false);
316 
318  PRMAN_INLINE void SplatBeauty(RtColorRGB const &val,
319  RtFloat trans = 0.0f) const;
320 
323  PRMAN_INLINE void SplatLPE(RtColorRGB const &val,
324  RtColorRGB const *lgtTrans,
325  RtFloat alpha,
326  bool isFinite,
327  RtFloat clamp,
328  int lpeId = -1,
329  RtColorRGB const *masks = 0,
330  OverwritePolicy overwritePolicy = k_Overwrite);
331 
332  PRMAN_INLINE void SplatShadowLPE(RtColorRGB const *lgtTrans,
333  RtColorRGB const &shadowWeight,
334  RtFloat alpha,
335  bool isFinite,
336  RtFloat clamp,
337  int lpeId = -1,
338  RtColorRGB const *masks = 0,
339  OverwritePolicy overwritePolicy = k_Overwrite,
340  RtColorRGB const &backgroundColor = RixConstants::k_ZeroRGB,
341  bool isShadowCollector = false);
342 
345  PRMAN_INLINE void SplatNfaLPE(RtColorRGB const &val,
346  RtColorRGB const *lgtTrans,
347  RtFloat alpha,
348  bool isFinite,
349  RtFloat clamp,
350  int lpeId = -1,
351  RtColorRGB const *masks = 0,
352  OverwritePolicy overwritePolicy = k_Overwrite);
353 
354  PRMAN_INLINE void SplatShadowNfaLPE(RtColorRGB const *lgtTrans,
355  RtColorRGB const &shadowWeight,
356  RtFloat alpha,
357  bool isFinite,
358  RtFloat clamp,
359  int lpeId = -1,
360  RtColorRGB const *masks = 0,
361  OverwritePolicy overwritePolicy = k_Overwrite,
362  RtColorRGB const &backgroundColor = RixConstants::k_ZeroRGB,
363  bool isShadowCollector = false);
364 
367  RtInt m_depth;
368  RtInt m_lgtGrpId;
369  RixLPEToken m_lpeGrpId;
370  bool m_isReflect;
371  RtFloat m_eyeTran;
372  RtColorRGB m_lgtTrans;
373 
376  RixDisplayServices *m_displaySvc;
377  RtInt m_integratorCtxIdx;
378  RixLPE &m_rixLpe;
379  RixLPEState &m_state;
380  RixShadingContext const *m_sCtx;
381  RtInt m_shadingCtxIdx;
382  };
383 };
384 
393 {
394  public:
396  PRMAN_INLINE RixLPEState(const RixLPEAutomata *automata,
397  const RixLPEAutomataNfa *automataNfa,
398  RixCustomLPE *rixCustomLPE);
399 
401  PRMAN_INLINE RixLPEState(const RixLPEState &that);
402 
404  PRMAN_INLINE ~RixLPEState();
405 
407  PRMAN_INLINE RixLPEState &operator= (const RixLPEState &that);
408 
410  PRMAN_INLINE int GetState();
411 
413  PRMAN_INLINE void SetState(int state);
414 
416  PRMAN_INLINE void Reset();
417 
420  PRMAN_INLINE void MoveCamera(RixShadingContext const *sCtx,
421  int sCtxIndex);
422 
425  PRMAN_INLINE void MoveEmissiveObject
426  (RixShadingContext const *sCtx,
427  int sCtxIndex,
428  RtColorRGB const &thruput,
429  RixLPEToken lpeGrpId = RixLPE::k_BLANK);
430 
433  PRMAN_INLINE void MoveLight(RixShadingContext const *sCtx,
434  int sCtxIndex,
435  RtColorRGB const &thruput,
436  RtColorRGB const *lgtTrans,
437  bool firstContribution,
438  RixLPEToken lgtGrpToken);
439 
447  PRMAN_INLINE void MoveVertex(RixShadingContext const *sCtx,
448  int sCtxIndex,
449  RixBXLobeSampled lobeSampled,
450  RtColorRGB const &thruput,
451  bool firstContribution,
452  RixLPEToken lpeGrpId = RixLPE::k_BLANK,
453  RtColorRGB const **masks = 0);
454 
461  PRMAN_INLINE void MoveVertexMultiLobe
462  (RixShadingContext const *sCtx,
463  int sCtxIndex,
464  bool isReflect,
465  RixBXActiveLobeWeights const &activeLobes,
466  int weightIndex,
467  RixLPEToken lpeGrpId = RixLPE::k_BLANK,
468  bool doStateTransition = true);
469 
471  PRMAN_INLINE ChanIdVec const *GetChannelIds();
472 
474  PRMAN_INLINE std::vector<int> const *GetOutputIndexes();
475 
477  PRMAN_INLINE std::vector<int> const *GetFlags();
478 
480  PRMAN_INLINE std::vector<int> const *GetCustomIds();
481 
483  PRMAN_INLINE RtColorRGB const *GetThruputs();
484 
486  PRMAN_INLINE RixCustomLPE *GetRixCustomLPE();
487 
488  PRMAN_INLINE RixLPEAutomata const *GetAutomata();
489  PRMAN_INLINE RixLPEAutomataNfa const *GetAutomataNfa();
490 
491  PRMAN_INLINE std::map<int, RtColorRGB> const &GetThruputsNfa();
492  PRMAN_INLINE void SetThruputsNfa(std::map<int, RtColorRGB> const &thrus);
493 
494  private:
495 
497  PRMAN_INLINE void move(RixLPEToken event);
498  PRMAN_INLINE void move(RixLPEToken event, RixLPEToken scatt);
499  PRMAN_INLINE void move(RixLPEToken event, RixLPEToken scatt,
500  RixLPEToken id);
501 
504  RixLPEAutomata const *m_automata;
505 
507  int m_state;
508 
510  RtColorRGB *m_thruput;
511 
513  RixCustomLPE *m_rixCustomLPE;
514 
515  RixLPEAutomataNfa const *m_automataNfa;
516 
517  std::map<int, RtColorRGB> *m_thruputsNfa;
518 };
519 
523 
524 #include "RixLPEInline.h"
525 
526 #endif