RixBxdf.h Source File

RixBxdf.h
1 #ifndef RixBxdf_h
2 #define RixBxdf_h
3 /* $Revision: #11 $ $Date: 2016/01/04 $
4 # ------------------------------------------------------------------------------
5 #
6 # Copyright (c) 2013-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 #include "RixShading.h"
40 #include "RixShadingUtils.h"
41 #include "RixBxdfLobe.h"
42 #include "RixRNG.h"
43 
101 enum RixBXEvaluateDomain
110 {
111  // Legend for diagrams
112  // V = view , L = light/connect/merge, N = normal, ------ = surface
113 
114  k_RixBXEmptyDomain = 0, // black hole (possibly emissive)
115 
116  k_RixBXFront = 1, // two-sided, non-translucent
117  // V\ N /L
118  //----------
119  //
120  // or
121  // N
122  //----------
123  // V/ \L
124 
125  k_RixBXBack = 2, // translucent, interior integrator
126  // V\ N
127  //----------
128  // \L
129  // or
130  // N /L
131  //----------
132  // V/
133 
134  k_RixBXBoth = 3, // thin-translucent, two-sided
135  // V\ N /L
136  //----------
137  // V/ \L
138 
139  k_RixBXOutside = 4, // 1-sided, requires Nn/Ngn facing "outside"
140  // V\ N /L
141  //----------
142  // V/
143 
144  k_RixBXInside = 5, // 1-sided, requires Nn/Ngn facing "outside"
145  // V\ N
146  //----------
147  // V/ \L
148 
149  k_RixBXVolume = 6 // transmits light from all directions
150 };
151 
153 enum RixBXTransportTrait
154 {
155  k_RixBXDirectLighting = 1<<0, // (direct lighting samples only)
156  k_RixBXIndirectLighting = 1<<1, // (indirect lighting samples only)
157  k_RixBXAnyLighting = k_RixBXDirectLighting | k_RixBXIndirectLighting
158 };
159 
161 enum RixBXRayFlags
162 {
163  k_RixBXBothEndsInVolume = 0,
164  k_RixBXOriginOnBoundary = 1,
165  k_RixBXEndOnBoundary = 2,
166  k_RixBXBothEndsOnBoundary = 3
167 };
168 
169 class RixBsdf;
170 class RixOpacity;
171 class RixVolumeIntegrator;
172 class RixIntegratorContext;
173 class RixLightingServices;
174 struct RtRayGeometry;
175 
177 {
178 public:
179  virtual int GetInterface() const { return k_RixBxdfFactory; }
180 
183  virtual int Init(RixContext &ctx, char const *pluginPath) = 0;
184  virtual RixSCParamInfo const *GetParamTable() = 0;
185  virtual void Finalize(RixContext &ctx) = 0;
186 
214  {
215  k_TriviallyOpaque=0,
216  k_ComputesOpacity=1,
221  k_ComputesInterior=0x10,
226  };
227  virtual int GetInstanceHints(RtConstPointer /* instancedata */) const
228  {
229  return k_TriviallyOpaque;
230  }
231 
254  virtual RixBsdf *BeginScatter(RixShadingContext const *,
255  RixBXLobeTraits const &hints,
256  RixSCShadingMode,
257  RtConstPointer instancedata) = 0;
258  virtual void EndScatter(class RixBsdf *bsdf) = 0;
260 
289  RixSCShadingMode,
290  RtConstPointer /* instancedata */)
291  { return 0; }
292  virtual void EndOpacity(class RixOpacity *) {}
293 
322  RixSCShadingMode,
323  RtConstPointer /* instancedata */)
324  { return 0; }
325  virtual void EndInterior(RixVolumeIntegrator *) {}
326 
327 protected:
328  RixBxdfFactory() : RixShadingPlugin(k_RixShadingVersion) {}
329  virtual ~RixBxdfFactory() {}
330 };
331 
334 class RixBsdf
335 {
336 public:
337  RixBsdf(RixShadingContext const *sCtx, RixBxdfFactory *fact) :
338  shadingCtx(sCtx), bxdfFactory(fact) {}
339 
340  virtual ~RixBsdf() {}
341 
342  RixShadingContext const *GetShadingCtx() { return shadingCtx; }
343  RixBxdfFactory *GetBxdfFactory() { return bxdfFactory; }
344 
348  virtual RixBXEvaluateDomain GetEvaluateDomain() = 0;
349 
351  virtual void GetAggregateLobeTraits(RixBXLobeTraits *t) = 0;
352 
353  PRMAN_INLINE RixBXLobeTraits GetAllLobeTraits()
354  {
355  RixBXLobeTraits t;
356  this->GetAggregateLobeTraits(&t);
357  return t;
358  }
359 
366  {
367  k_Albedo,
369  };
370  virtual RixSCDetail GetProperty(BxdfProperty, void const ** /* result */) const
371  {
375  return k_RixSCInvalidDetail;
376  }
377 
379  virtual bool EmitLocal(RtColorRGB* /* result */)
380  {
385  return false;
386 
387  /*
392 
393  RtInt nPts = shadingCtx->numPts;
394  for (int i = 0; i < nPts; i++)
395  result[i] = RtColorRGB(1.0f);
396 
397  return true;
398  */
399  }
400 
423  virtual void GenerateSample(RixBXTransportTrait transportTrait,
424  RixBXLobeTraits const *lobesWanted,
425  RixRNG *rng,
426  RixBXLobeSampled *lobesSampled,
427  RtVector3 *sampleDirs,
428  RixBXLobeWeights &weights,
429  RtFloat *forwardPdfs,
430  RtFloat *reversePdfs) = 0;
431 
453  virtual void EvaluateSample(RixBXTransportTrait transportTrait,
454  RixBXLobeTraits const *lobesWanted,
455  RixBXLobeTraits *lobesEvaluated,
456  RtVector3 const *sampleDirs,
457  RixBXLobeWeights &weights,
458  RtFloat *forwardPdfs,
459  RtFloat *reversePdfs) = 0;
460 
464  virtual void EvaluateSamplesAtIndex(RixBXTransportTrait transportTrait,
465  RixBXLobeTraits const &lobesWanted,
466  RtInt index,
467  RtInt numSamples,
468  RixBXLobeTraits *lobesEvaluated,
469  RtVector3 const *sampleDirs,
470  RixBXLobeWeights &weights,
471  RtFloat *forwardPdfs,
472  RtFloat *reversePdfs) = 0;
473 
478  virtual void Release() { if (bxdfFactory) bxdfFactory->EndScatter(this); }
479 
480 protected:
481  RixShadingContext const *shadingCtx;
482  RixBxdfFactory *bxdfFactory;
483 };
484 
508 {
509 public:
510  RixOpacity(RixShadingContext const *sCtx, RixBxdfFactory *fact) :
511  shadingCtx(sCtx), bxdfFactory(fact) {}
512  virtual ~RixOpacity() {}
513  RixBxdfFactory *GetBxdfFactory() { return bxdfFactory; }
514  RixShadingContext const *GetShadingCtx() { return shadingCtx; }
515 
527  virtual bool GetPresence(RtFloat *result) = 0;
528 
539  virtual bool GetOpacity(RtColorRGB *result) = 0;
540 
541  virtual void Release() { if (bxdfFactory) bxdfFactory->EndOpacity(this); }
542 
543 protected:
544  RixShadingContext const *shadingCtx;
545  RixBxdfFactory *bxdfFactory;
546 };
547 
572 {
573 public:
575  shadingCtx(sCtx), bxdfFactory(f), params(NULL) {}
576  virtual ~RixVolumeIntegrator() {}
577  RixShadingContext const *GetShadingCtx() { return shadingCtx; }
578  void SetShadingCtx(const RixShadingContext *ctx) { shadingCtx = ctx; }
579  RixBxdfFactory *GetBxdfFactory() { return bxdfFactory; }
580 
581  virtual void SetParameters(void const *subclassParams)
582  {
583  params = subclassParams;
584  }
585 
587  {
588  public:
589  virtual void PerformDirectLighting(RixShadingContext const &,
590  RixBXLobeTraits const *lobesWanted,
591  int step) = 0;
592 
593  protected:
594  virtual ~IntegratorDelegate() {}
595  };
596 
597  virtual void Release() { if(bxdfFactory) bxdfFactory->EndInterior(this); }
598 
606  {
607  k_DensityType,
611  };
612  virtual RixSCDetail GetProperty(VolumeProperty, void const ** /* result */) const
613  {
617  return k_RixSCInvalidDetail;
618  }
619 
620  virtual void GetNearestHits(RtInt numRays, RtRayGeometry const *rays,
621  RixRNG *rng,
622  RixBXLobeTraits const &lobesWanted,
623  RixIntegratorContext &iCtx,
624  RixLightingServices *lightingServices,
630  IntegratorDelegate *lcb,
631  RtInt *numGrps,
632  RixShadingContext const **shadeGrps,
634  char const *subset=NULL,
635  bool isLightPath=false,
636  RtHitSides hitSides=k_SidesBoth,
637  bool isPrimary=false
638  )=0;
639 
645  virtual void GetTransmission(RtInt /* numRays */, RtRayGeometry const * /* rays */,
646  RixRNG * /* rng */,
647  RixIntegratorContext &iCtx,
648  RtColorRGB * /* trans */,
650  char const * /* subset */ =NULL) {}
651 
654 
677  virtual void GetNearestHitsAndPdfs(RtInt numRays,
678  RtRayGeometry const *rays,
679  RixRNG *rng,
680  RixBXLobeTraits const &lobesWanted,
681  RixIntegratorContext &iCtx,
682  bool /* insideVolume */,
683  bool /* generateLongBeams */,
684  bool * /* scatterRay */,
686  RtInt *numGrps,
687  RixShadingContext const **shadeGrps,
688  RtFloat * forwardPdf,
689  RtFloat * reversePdf,
690  RtFloat * crossPdf,
691  RtFloat * forwardBoundaryPdf,
692  RtFloat * reverseBoundaryPdf,
693  RtColorRGB * densityCoefficient) {
694  GetNearestHits(numRays, rays, rng, lobesWanted, iCtx,
695  NULL, NULL, numGrps, shadeGrps, NULL);
696  for ( int i = 0; i < numRays; ++i)
697  {
698  forwardPdf[i] = reversePdf[i] = crossPdf[i] =
699  forwardBoundaryPdf[i] = reverseBoundaryPdf[i] =
700  densityCoefficient[i].r = densityCoefficient[i].g =
701  densityCoefficient[i].b = 1.0f;
702  }
703  }
704 
713  RtInt numRays,
714  RtRayGeometry const *rays,
715  RixRNG *rng,
716  RixIntegratorContext &iCtx,
717  RixBXRayFlags const * /* rayFlags */,
719  RtColorRGB *trans,
720  RtFloat * forwardPdf, RtFloat * reversePdf,
721  RtFloat * crossPdf,
723  RtColorRGB * /* densityCoefficient */ = NULL)
724  {
725  GetTransmission(numRays, rays, rng, iCtx, trans, NULL);
726  for ( int i = 0; i < numRays; ++i)
727  {
728  forwardPdf[i] = reversePdf[i] = crossPdf[i] = 1.0f;
729  }
730  }
731 
736  virtual RixBsdf * CreateBSDF(RixShadingContext const * /* vCtx */,
737  RixShadingContext::Allocator & /* pool */)
738  {
739  return NULL;
740  }
741 
743  virtual bool IsMultiScatter() const
744  {
745  return false;
746  }
747 protected:
748  RixShadingContext const *shadingCtx;
749  RixBxdfFactory *bxdfFactory;
750  void const *params;
751 };
752 
753 #define RIX_BXDFPLUGINCREATE \
754 extern "C" PRMANEXPORT RixBxdfFactory *CreateRixBxdfFactory(const char *hint)
755 
756 #define RIX_BXDFPLUGINDESTROY \
757 extern "C" PRMANEXPORT void DestroyRixBxdfFactory(RixBxdfFactory *bxdf)
758 
759 #endif