RenderMan API  23.0
RixShading.h
Go to the documentation of this file.
1 /*
2 # ------------------------------------------------------------------------------
3 #
4 # Copyright (c) 1986-2019 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 RixShading_h
38 #define RixShading_h
39 
40 #include <algorithm> // for fill_n
41 #include <cassert> // for assert
42 #include <cstddef> // for NULL, size_t
43 #include <cstring> // for memcpy
44 #include <new> // for operator new
45 #include <vector> // for vector
46 #include "RixInterfaces.h" // for RixContext
47 #include "RixRNG.h" // for random number generation
48 #include "ri.hpp" // for RtConstPointer, etc
49 
50 class RixBxdf;
51 class RixBxdfFactory;
52 class RixDisplacement;
53 class RixDisplayFilter;
54 class RixDisplayServices;
56 class RixLPEState;
57 class RixLight;
58 class RixLightFilter;
59 class RixOpacity;
60 class RixParameterList;
61 class RixPostLighting;
62 class RixSampleFilter;
64 struct RixBXLobeTraits;
65 struct RixSCParamInfo;
66 struct RtHitPoint;
67 struct RtRayGeometry;
68 
97 #define k_RixShadingVersion 230 // XXY (XX: MAJOR, Y:MINOR)
98 
100 {
104 };
105 
110 {
121 };
122 
128 {
129  // delivered in primary thread...
132  k_RixSCInstanceEdit, // Currently unused
133  k_RixSCCancel, // Currently unused
134  k_RixSCCheckpointRecover, // Restarting at "int increment"
135  // delivered by one (arbitrary) thread...
136  k_RixSCCheckpointWrite, // Writing "int increment" for "string reason" ("checkpoint",
137  // "exiting", or "finished").
138  k_RixSCIncrementBarrier, // Indicates "int increment" about to begin (only sent if
139  // wantsIncrementBarrier is true.)
140 };
141 
169 {
170 public:
171  virtual int GetVersion() const
172  {
173  return m_version;
174  }
175  virtual int GetInterface() const
176  {
177  return k_RixInvalid;
178  }
179 
190  virtual int Init(RixContext& ctx, RtUString const pluginPath) = 0;
191 
195  virtual void Finalize(RixContext& ctx) = 0;
196 
209  virtual RixSCParamInfo const* GetParamTable() = 0;
210 
215  virtual void Synchronize(RixContext& ctx, RixSCSyncMsg syncMsg,
216  RixParameterList const* syncParams) = 0;
217 
275  {
276  k_None = 0x00000000,
277  k_All = 0xFFFFFFFF
278  };
279 
281  {
283  : data(NULL),
284  datalen(0),
285  freefunc(NULL),
286  paramtable(NULL),
288  {}
290  size_t datalen;
291  void (*freefunc)(RtPointer);
294  };
295 
303  virtual void CreateInstanceData(RixContext& rixCtx, RtUString const handle,
304  RixParameterList const* parameterList,
305  InstanceData* instanceData)
306  {
307  PIXAR_ARGUSED(rixCtx);
308  PIXAR_ARGUSED(handle);
309  PIXAR_ARGUSED(parameterList);
310  PIXAR_ARGUSED(instanceData);
311  }
312 
326  virtual void SynchronizeInstanceData(RixContext& rixCtx, RtUString const handle,
327  RixParameterList const* instanceParams,
328  uint32_t const editHints,
329  InstanceData* instanceData)
330  {
331  PIXAR_ARGUSED(rixCtx);
332  PIXAR_ARGUSED(handle);
333  PIXAR_ARGUSED(instanceParams);
334  PIXAR_ARGUSED(editHints);
335  PIXAR_ARGUSED(instanceData);
336  }
337 
338 protected:
339  RixShadingPlugin(int version) : m_version(version)
340  {}
342  {}
344 };
345 
350 {
352  k_RixSCAnyType, // signals a dynamic binding scenario
363  k_RixSCBxdf, // always uniform
364  k_RixSCLightFilter, // always uniform
365  k_RixSCStructBegin, // always uniform
366  k_RixSCStructEnd, // always uniform
367  k_RixSCSampleFilter, // always uniform
368  k_RixSCDisplayFilter, // always uniform
370 };
371 
377 {
379  k_RixSCUniform, // needs an eval per shading "grid"
380  k_RixSCVarying, // needs an eval per shading point
382 };
383 
398 {
399  // clang-format off
401  k_RixSCOutput = 1 << 0,
409  // use Input + output at the same time to indicate invalid
411  // clang-format on
412 };
413 
419 {
424 };
425 
431 {
435 };
436 
444 {
445  k_RayDepth, // ray depth (scattering events)
450  k_RayTrueDepth // ray depth (scattering events + volume envelopes etc.)
451 };
452 
457 {
458  // most common constructor of POD parameters.
460  int length = -1)
461  : name(_name), customtype(US_NULL), type(t), access(a), arraylen(length)
462  {}
463 
464  // full constructor
465  RixSCParamInfo(RtUString const structName, RtUString const _name, RixSCType t,
466  RixSCAccess a = k_RixSCInput, int length = -1)
467  : name(_name), customtype(structName), type(t), access(a), arraylen(length)
468  {}
469 
470  // default constructor, useful to signal end of paraminfo table
472  : name(US_NULL),
473  customtype(US_NULL),
474  type(k_RixSCInvalidType),
475  access(k_RixSCInvalidAccess),
476  arraylen(-1)
477  {}
478 
480  RtUString customtype; // NULL unless struct
483  int arraylen; // -1 means no array, 0 means empty
484  bool IsArray() const
485  {
486  return (arraylen != -1);
487  }
488 };
489 
498 {
509 };
510 
518 {
519 public:
520  virtual int GetNumParams() const = 0;
521 
528  virtual int GetParamId(const RtUString name, int* paramId) const = 0;
529 
533  virtual int GetParamId(int plistIndex, int* paramId) const = 0;
534 
540  virtual int GetParamInfo(int paramId, RixSCType* type, RixSCConnectionInfo* cInfo,
541  int* arrayLength = NULL) const = 0;
542 
545  int GetParamInfo(int paramId, RixSCType* type, bool* isConnected, int* arrayLength = NULL) const
546  {
547  RixSCConnectionInfo cInfo;
548  int err = GetParamInfo(paramId, type, &cInfo, arrayLength);
549  if (isConnected) *isConnected = (cInfo == k_RixSCNetworkValue);
550  return err;
551  }
552 
563  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, int* result) const = 0;
564  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, float* result) const = 0;
565  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RtColorRGB* result) const = 0;
566  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RtFloat3* result) const = 0;
567  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RtMatrix4x4* result) const = 0;
568  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RtUString* result) const = 0;
569  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RixLightFilter** result,
570  RtConstPointer* instance) const = 0;
571  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RixSampleFilter** result,
572  RtConstPointer* instance) const = 0;
573  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RixDisplayFilter** result,
574  RtConstPointer* instance) const = 0;
575 
576 protected:
578  {}
579 };
580 
606 {
607 public:
614  struct Id
615  {
616  Id() : shadingCtxNum(-6666)
617  {}
618  Id(unsigned int i) : shadingCtxNum(static_cast<short>(i & 0xFFFF))
619  {}
620  // Convert to a serialized integral representation.
621  unsigned int Serialize() const
622  {
623  return shadingCtxNum;
624  }
625  void Invalidate()
626  {
627  shadingCtxNum = -6666;
628  }
629  bool IsValid() const
630  {
631  return shadingCtxNum != -6666;
632  }
634  } shadingCtxId;
635 
638  int numPts;
639 
642  struct
643  {
644  // clang-format off
645  unsigned eyePath : 1;
646  unsigned lightPath : 1;
647  unsigned primaryHit : 1;
648  unsigned missContext : 1;
649  unsigned reyesGrid : 1;
650  // clang-format on
653 
657 
661 
662  // The opacity shader is non-NULL when computing presence and
663  // transmission.
665 
666  // The displacement shader is non-NULL when computing displacement
668 
669  // The subsurface shader is non-NULL when invoking subsurf. integrators
671 
672  // The volume shader is non-NULL when invoking volume integrators.
674 
675  // The postlighting shader is non-NULL when invoking postlighting
677  } scTraits; // "uniform" traits associated with the shading context
678 
679  bool HasHits() const
680  {
681  return (scTraits.missContext == 0);
682  }
683  bool HasMisses() const
684  {
685  return (scTraits.missContext == 1);
686  }
687 
688  RixBxdf* GetBxdf() const
689  {
690  assert(scTraits.shadingMode == k_RixSCScatterQuery ||
691  scTraits.shadingMode == k_RixSCVolumeScatterQuery ||
692  scTraits.shadingMode == k_RixSCVolumeTransmissionQuery);
693  return scTraits.bxdf;
694  }
695 
697  {
698  assert(scTraits.shadingMode == k_RixSCOpacityQuery ||
699  scTraits.shadingMode == k_RixSCPresenceQuery ||
700  scTraits.shadingMode == k_RixSCVolumeTransmissionQuery);
701  return scTraits.opacity;
702  }
703 
705  {
706  assert(scTraits.shadingMode == k_RixSCDisplacementQuery);
707  return scTraits.displacement;
708  }
709 
711  {
712  assert(scTraits.shadingMode == k_RixSCScatterQuery ||
713  scTraits.shadingMode == k_RixSCVolumeScatterQuery ||
714  scTraits.shadingMode == k_RixSCVolumeTransmissionQuery);
715  return scTraits.subsurface;
716  }
717 
719  {
720  assert(scTraits.shadingMode == k_RixSCScatterQuery ||
721  scTraits.shadingMode == k_RixSCVolumeScatterQuery ||
722  scTraits.shadingMode == k_RixSCVolumeTransmissionQuery ||
723  scTraits.shadingMode == k_RixSCEmissionQuery);
724  return scTraits.volume;
725  }
726 
728  {
729  assert(scTraits.shadingMode == k_RixSCScatterQuery ||
730  scTraits.shadingMode == k_RixSCVolumeScatterQuery);
731  return scTraits.postlighting;
732  }
733 
734  virtual bool HasSubsurface() const = 0;
735  virtual RixVolumeIntegrator* BeginSubsurface(int numRays, RtRayGeometry* rays) const = 0;
736  virtual void EndSubsurface(RixVolumeIntegrator*) const = 0;
737 
748  virtual bool HasVolume(RixSCVolumeSelector) const = 0;
749  virtual RixVolumeIntegrator* BeginVolume(RixSCVolumeSelector, int numRays,
750  RtRayGeometry* rays) const = 0;
751  virtual void EndVolume(RixVolumeIntegrator*) const = 0;
754  {
755  return BeginVolume(k_RixSCIncidentVolume, numRays, rays);
756  }
758  {
759  return BeginVolume(k_RixSCOppositeVolume, numRays, rays);
760  }
761 
764  virtual std::vector<const RixShadingContext*> const* GetOverlappingVolumes() const = 0;
765 
770  enum BuiltinVolume // built-in subsurface interior integrator
771  {
772  k_SSDiffusion, // sss using Burley's normalized diffusion model
773  k_SSPathTraced // sss using brute-force volume scattering
774  };
775  virtual RixVolumeIntegrator* GetBuiltinVolume(BuiltinVolume builtin, RixBxdfFactory* factory,
776  RtPointer instanceData) const = 0;
777 
785 
791  int* rayId;
792 
798 
801  float* pointWeight;
802 
806 
807  // When dealing with non-fully-opaque surfaces, and when using probabilistic hit-testing, the
808  // total opacity (product of the `presence` and the `opacity` values returned by RixOpacity) can
809  // be interpreted as the probability that we actually hit the surface.
810  //
811  // When only considering a scalar presence value (i.e. opacity is one, so the total opacity is
812  // monochromatic), the hit probability is usually the inverse of the scalar presence value, and
813  // no special weighting needs to be applied to the shading on hits.
814  //
815  // However, when dealing with arbitrary (i.e. colored) total opacity, it is necessary to weight
816  // the shading on hit by the product of:
817  // - `opacityThroughput`: a colored weight resulting from stochastic continuations that
818  // happened before reaching the selected hit
819  // - `opacityStochasticWeight`: inverse of the local probability of having selected the hit,
820  // knowing that we have reached it
821  // - `opacity`: the total opacity of the selected hit
822 
823  // Per-point colored weight resulting from stochastic continuations that happened before
824  // reaching the selected hit.
825  //
826  // If no probabilistic hit-testing was involved before reaching the current point, or if the ray
827  // only went through surfaces with monochromatic opacity, then this quantity is [1 1 1]. If the
828  // ray went through surfaces with colored opacity, then this quantity is the total transmission
829  // (up to the current point) divided by the probability of reaching this point.
831 
832  // Per-point combined opacity: the product of presence and opacity for the current point.
834 
835  // Per-point probabilistic hit-testing weight.
836  //
837  // If the current hit's opacity is monochromatic, or if the `opacityThroughput` up to it is
838  // monochromatic, then this quantity only depends on the hit's total opacity. Otherwise, this
839  // weight also depends on the accumulated transmission up to the hit.
841 
843  mutable void* lightingServicesData;
844 
845  // The light shader is non-NULL when the shading context contains
846  // points on the surface of a light
847  RixLight const* light;
848 
849  // This is accessed and used by patterns to generate random numbers
850  // A NULL value of m_rngCtx means the integrator in use does not support
851  // this functionality. Pattern writer needs to check against NULL pointer
852  // before using m_rngCtx. See PxrRand pattern for example code.
853  mutable RixRNG* m_rngCtx;
854  virtual void SetupRngCtxForPattern() const = 0;
855 
860  {
861  k_NullBxdf
862  };
863  virtual RixBxdf* GetBuiltinBxdf(BuiltinBxdf, RixBxdfFactory*) const = 0;
864 
869  virtual RixDisplayServices* GetDisplayServices(int version = 1) const = 0;
870 
872  {
873  // clang-format off
874  k_P = 0,
875  k_PRadius,
876  k_Po,
891  k_u,
892  k_v,
893  k_w,
895  k_dufp = k_du,
897  k_dvfp = k_dv,
899  k_dwfp = k_dw,
918  k_numBuiltinVars
919  // clang-format on
920  };
921  virtual void GetBuiltinVar(BuiltinVar, int const** var) const = 0;
922  virtual void GetBuiltinVar(BuiltinVar, float const** var) const = 0;
923  virtual void GetBuiltinVar(BuiltinVar, RtFloat3 const** var) const = 0;
924  virtual void GetBuiltinVar(BuiltinVar, RixLPEState* const** var) const = 0;
925 
951  virtual void SetBuiltinVar(BuiltinVar, float* var) = 0;
952  virtual void SetBuiltinVar(BuiltinVar, RtFloat3* var) = 0;
953 
964  virtual RixSCDetail GetPrimVar(const RtUString name, RixSCType* type, int* arraylen) const = 0;
965 
966  virtual RixSCDetail GetPrimVar(const RtUString name, float fill, float const** var,
967  float const** radius = NULL) const = 0;
968 
969  virtual RixSCDetail GetPrimVar(const RtUString name, RtFloat2 fill, RtFloat2 const** var,
970  float const** radius = NULL) const = 0;
971 
972  virtual RixSCDetail GetPrimVar(const RtUString name, RtFloat3 fill, RtFloat3 const** var,
973  float const** radius = NULL) const = 0;
974 
975  virtual RixSCDetail GetPrimVar(const RtUString name, RtUString const** var) const = 0;
976 
977  virtual RixSCDetail GetPrimVar(const RtUString name, RtMatrix4x4 const& fill,
978  RtMatrix4x4 const** var) const = 0;
979 
985 
986  virtual RixSCDetail GetPrimVar(const RtUString name, float const** var, float const** dXdu,
987  float const** dXdv) const = 0;
988 
989  virtual RixSCDetail GetPrimVar(const RtUString name, RtFloat2 const** var, float const** dXdu,
990  float const** dYdu, float const** dXdv,
991  float const** dYdv) const = 0;
992 
993  virtual RixSCDetail GetPrimVar(const RtUString name, RtFloat3 const** var, float const** dXdu,
994  float const** dYdu, float const** dZdu, float const** dXdv,
995  float const** dYdv, float const** dZdv) const = 0;
996 
1013  virtual void SetPrimVar(const RtUString name, RixSCDetail d, float* var, float* radius) = 0;
1014 
1015  virtual void SetPrimVar(const RtUString name, RixSCDetail d, RtFloat2* var, float* radius) = 0;
1016 
1017  virtual void SetPrimVar(const RtUString name, RixSCDetail d, RtFloat3* var, float* radius) = 0;
1018 
1019  virtual void SetPrimVar(const RtUString name, RixSCDetail d, RtUString* var) = 0;
1020 
1021  virtual void SetPrimVar(const RtUString name, RixSCDetail d, RtMatrix4x4* var) = 0;
1022 
1033  virtual bool GetProperty(RayProperty, void const* /* result */) const
1034  {
1035  return false;
1036  }
1037 
1038  // Shading context obtains the pointer to the corresponding
1039  // integrator and integrator context.
1040  // The integrator is responsible for setting the values.
1041  virtual bool SetProperty(RayProperty, void const* /* in */) const
1042  {
1043  return false;
1044  }
1045 
1047  {
1050  k_AsNormals
1051  };
1052 
1057  virtual int Transform(TransformInterpretation interp, const RtUString fromSpace,
1058  const RtUString toSpace, RtFloat3* var, float* radius = NULL) const = 0;
1059 
1065  virtual int GetTransform(const RtUString fromSpace, const RtUString toSpace,
1066  RtMatrix4x4 const** matrix, int* numMatrices) const = 0;
1067 
1073  virtual RixShadingContext* CreateMutableContext() const = 0;
1074 
1079  virtual RixShadingContext const* GetPrimaryContext() const = 0;
1080 
1083  virtual RixIntegratorContext* GetIntegratorContext() const = 0;
1084 
1091  virtual RixShadingContext const* GetContextById(RixShadingContext::Id sCtxId) const = 0;
1092 
1127 
1128  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, int const** result,
1129  int const* dflt = NULL, bool promoteToVarying = false) const = 0;
1130 
1131  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, float const** result,
1132  float const* dflt = NULL,
1133  bool promoteToVarying = false) const = 0;
1134 
1135  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RtColorRGB const** result,
1136  RtColorRGB const* dflt = NULL,
1137  bool promoteToVarying = false) const = 0;
1138 
1139  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RtFloat3 const** result,
1140  RtFloat3 const* dflt = NULL,
1141  bool promoteToVarying = false) const = 0;
1142 
1143  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RtMatrix4x4 const** result,
1144  RtMatrix4x4 const* dflt = NULL,
1145  bool promoteToVarying = false) const = 0;
1146 
1147  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RtUString const** result,
1148  RtUString const* dflt = NULL,
1149  bool promoteToVarying = false) const = 0;
1150 
1151  virtual RixSCDetail EvalParam(int paramId, int arrayIndex, RixBxdfFactory** result,
1152  RixBxdfFactory* dflt = NULL,
1153  bool promoteToVarying = false) const = 0;
1154 
1156  {
1158  k_PatternMem
1159  };
1160 
1167  template <class T>
1168  RixSCDetail EvalAndCopyParam(int paramId, int arrayIndex, T** result, T const* dflt = NULL,
1169  bool promoteToVarying = false, MemCategory mcat = k_BxdfMem) const
1170  {
1171  T const* constResult;
1172  RixSCDetail d = EvalParam(paramId, arrayIndex, &constResult, dflt);
1173  switch (d)
1174  {
1175  case k_RixSCVarying:
1176  *result = (T*)Allocate(this->numPts, sizeof(T), mcat);
1177  memcpy(*result, constResult, this->numPts * sizeof(T));
1178  break;
1179  case k_RixSCUniform:
1180  if (promoteToVarying)
1181  {
1182  *result = (T*)Allocate(this->numPts, sizeof(T), mcat);
1183  std::fill_n(*result, this->numPts, constResult[0]);
1184  }
1185  else
1186  {
1187  *result = (T*)Allocate(1, sizeof(T), mcat);
1188  (*result)[0] = constResult[0];
1189  }
1190  break;
1191  default:
1192  *result = 0x0;
1193  break;
1194  }
1195  return d;
1196  }
1197 
1203  virtual int GetParamId(const RtUString name, int* paramId) const = 0;
1204 
1210  virtual int GetParamInfo(int paramId, RixSCType* type, RixSCConnectionInfo* cInfo,
1211  int* arrayLength = NULL) const = 0;
1212 
1215  int GetParamInfo(int paramId, RixSCType* type, bool* isConnected, int* arrayLength = NULL) const
1216  {
1217  RixSCConnectionInfo cInfo;
1218  int err = GetParamInfo(paramId, type, &cInfo, arrayLength);
1219  if (isConnected) *isConnected = (cInfo == k_RixSCNetworkValue);
1220  return err;
1221  }
1222 
1245  virtual void GetNearestHits(int numRays, RtRayGeometry const* rays,
1246  // result:
1247  RtHitPoint* hits,
1248  // optional parameters:
1249  const RtUString subset = US_NULL,
1250  const RtUString excludeSubset = US_NULL,
1251  RtHitSides hitSides = k_SidesBoth) const = 0;
1252 
1258  virtual bool GetLightEmission(RtColorRGB* emission, int* lightGroupIds = NULL) const = 0;
1259 
1268  virtual void* Allocate(size_t n, size_t size, MemCategory m) const = 0;
1269 
1277  template <class T>
1278  T* New(size_t nObjs, MemCategory cat = k_BxdfMem) const
1279  {
1280  T* mem = static_cast<T*>(Allocate(nObjs, sizeof(T), cat));
1281  return new (mem) T[nObjs];
1282  }
1283 
1296  {
1297  public:
1298  Allocator(RixShadingContext const* sCtx) : m_sCtx(sCtx)
1299  {}
1300  template <typename T>
1301  T* Allocate(int num)
1302  {
1303  if (num == 0) return NULL;
1304  return (T*)m_sCtx->Allocate(num, sizeof(T), k_BxdfMem);
1305  }
1306  template <typename T>
1307  T* AllocFor(MemCategory memcat, int num)
1308  {
1309  if (num == 0) return NULL;
1310  return (T*)m_sCtx->Allocate(num, sizeof(T), memcat);
1311  }
1312  template <typename T>
1313  T* AllocForVolume(int num)
1314  {
1315  // currently the memory-pool lifetime of volumes matches
1316  // that of Bxdf.
1317  if (num == 0) return NULL;
1318  return (T*)m_sCtx->Allocate(num, sizeof(T), k_BxdfMem);
1319  }
1320  template <typename T>
1321  T* AllocForBxdf(int num)
1322  {
1323  if (num == 0) return NULL;
1324  return (T*)m_sCtx->Allocate(num, sizeof(T), k_BxdfMem);
1325  }
1326  template <typename T>
1327  T* AllocForPattern(int num)
1328  {
1329  if (num == 0) return NULL;
1330  return (T*)m_sCtx->Allocate(num, sizeof(T), k_PatternMem);
1331  }
1332 
1333  private:
1334  RixShadingContext const* m_sCtx;
1335  };
1336 
1337 protected:
1339  {}
1340 
1341  // Hide these interfaces. These are not useful/relevant for clients to
1342  // directly call. However, they need to be accessed by the
1343  // RixVolumeIntegrator internals, so allow access for this class only.
1344  friend class RixVolumeIntegrator;
1345  // LightVertexCache::RayDensityEstimation() in UPBP needs to call
1346  // BeginVolumeSampling() so allow it access, too.
1347  friend class LightVertexCache;
1348  virtual RixShadingContext* BeginVolumeSampling() const = 0;
1349  virtual RixShadingContext const* EndVolumeSampling(const RixShadingContext*,
1350  RixBXLobeTraits const* exposeVol = NULL,
1351  int const* membership = NULL) const = 0;
1352 
1353  mutable RixRNG::SampleCtx* m_rngSampleCtx; // assembled by querying into the integrator
1354 };
1355 
1356 #endif
unsigned reyesGrid
true if this context represents misses
Definition: RixShading.h:649
RtColorRGB * transmission
Definition: RixShading.h:797
Attribute "identifier" "id2" (type int)
Definition: RixShading.h:906
RixPostLighting * GetPostLighting() const
Definition: RixShading.h:727
Id(unsigned int i)
Definition: RixShading.h:618
PxrMeshLight emission mode.
Definition: RixShading.h:507
RixShadingPlugin(int version)
Definition: RixShading.h:339
Instantaneous P velocity relative to the camera (type RtFloat3)
Definition: RixShading.h:915
Wavelength of incident ray (type float): 380-780nm visible spectrum.
Definition: RixShading.h:916
T * AllocFor(MemCategory memcat, int num)
Definition: RixShading.h:1307
Micropolygon size; 0 for non-tessellated surfaces (type float)
Definition: RixShading.h:888
Normalized shading tangent (type RtFloat3)
Definition: RixShading.h:881
virtual ~RixParameterList()
Definition: RixShading.h:577
virtual bool SetProperty(RayProperty, void const *) const
Definition: RixShading.h:1041
RtHitSides
Definition: RixShading.h:99
pxrcore::ColorRGB RtColorRGB
unsigned lightPath
true if shading for an eye path
Definition: RixShading.h:646
#define US_NULL
PRMANAPI const RtUString k_Po
"Po"
virtual ~RixShadingPlugin()
Definition: RixShading.h:341
int * integratorCtxIndex
Definition: RixShading.h:784
int GetParamInfo(int paramId, RixSCType *type, bool *isConnected, int *arrayLength=NULL) const
Definition: RixShading.h:1215
Local principal surface curvature in u dir (type float)
Definition: RixShading.h:913
Local principal surface curvature in v dir (type float)
Definition: RixShading.h:914
void * RtPointer
Definition: ri.h:69
RixSCConnectionInfo
Definition: RixShading.h:430
bool IsArray() const
Definition: RixShading.h:484
RixBxdf * GetBxdf() const
Definition: RixShading.h:688
RixOpacity * opacity
Definition: RixShading.h:664
Attribute "identifier" "id" (type int)
Definition: RixShading.h:905
RixVolumeIntegrator * volume
Definition: RixShading.h:673
RixRNG * m_rngCtx
Definition: RixShading.h:853
unsigned primaryHit
true if shading for a light path
Definition: RixShading.h:647
Ray footprint (radius) in V (type float)
Definition: RixShading.h:896
Opacity (type RtFloat3)
Definition: RixShading.h:908
RixSCAccess access
Definition: RixShading.h:482
void(* freefunc)(RtPointer)
Definition: RixShading.h:291
Normalized shading normal (type RtFloat3)
Definition: RixShading.h:878
RixSCShadingMode
Definition: RixShading.h:497
RixShadingInterface
Definition: RixShading.h:109
RixRNG::SampleCtx * m_rngSampleCtx
Definition: RixShading.h:1353
T * New(size_t nObjs, MemCategory cat=k_BxdfMem) const
Definition: RixShading.h:1278
RtColorRGB * opacity
Definition: RixShading.h:833
Instantaneous P velocity relative to the world (type RtFloat3)
Definition: RixShading.h:903
RixBxdfFactory::BeginScatter mode.
Definition: RixShading.h:502
RixDisplacementFactory::BeginDisplacement mode.
Definition: RixShading.h:506
bool HasHits() const
Definition: RixShading.h:679
Normalized undisplaced N (type RtFloat3)
Definition: RixShading.h:880
unsigned int Serialize() const
Definition: RixShading.h:621
RixSCDetail
Definition: RixShading.h:376
virtual int GetInterface() const
Definition: RixShading.h:175
virtual void Synchronize(RixContext &ctx, RixSCSyncMsg syncMsg, RixParameterList const *syncParams)=0
RixSCParamInfo(RtUString const structName, RtUString const _name, RixSCType t, RixSCAccess a=k_RixSCInput, int length=-1)
Definition: RixShading.h:465
Backward 2D raster-space motion vector (type RtFloat3)
Definition: RixShading.h:912
unsigned eyePath
Definition: RixShading.h:645
PRMANAPI const RtUString k_dv
"dv"
RixVolumeIntegrator * GetVolume() const
Definition: RixShading.h:718
RtUString customtype
Definition: RixShading.h:480
Ray footprint (radius) in U (type float)
Definition: RixShading.h:894
Surface derivative in U (type RtFloat3)
Definition: RixShading.h:900
Surface derivative in W (type RtFloat3)
Definition: RixShading.h:902
RixPostLighting * postlighting
Definition: RixShading.h:676
Allocator(RixShadingContext const *sCtx)
Definition: RixShading.h:1298
Bias to apply for transmitted rays (type float)
Definition: RixShading.h:890
RixSCShadingMode shadingMode
Definition: RixShading.h:656
RixSCType
Definition: RixShading.h:349
Radius of incident ray at P (type float)
Definition: RixShading.h:886
RixBxdf * bxdf
Definition: RixShading.h:660
RixBxdfFactory::BeginOpacity opacity mode.
Definition: RixShading.h:501
RixBXLobeSampled id of incident rays (type int)
Definition: RixShading.h:887
Local mean surface curvature (type float)
Definition: RixShading.h:884
bool HasMisses() const
Definition: RixShading.h:683
Forward 2D raster-space motion vector (type RtFloat3)
Definition: RixShading.h:911
RixSCVolumeSelector
Definition: RixShading.h:418
Normalized view vector, points away from shading points (type RtFloat3)
Definition: RixShading.h:882
virtual RixSCParamInfo const * GetParamTable()=0
float * pointWeight
Definition: RixShading.h:801
RtColorRGB * opacityThroughput
Definition: RixShading.h:830
Invalid shading context.
Definition: RixShading.h:499
pxrcore::UString RtUString
virtual void SynchronizeInstanceData(RixContext &rixCtx, RtUString const handle, RixParameterList const *instanceParams, uint32_t const editHints, InstanceData *instanceData)
Definition: RixShading.h:326
Normalized analytical undisplaced N (type RtFloat3)
Definition: RixShading.h:917
void * lightingServicesData
lightingServicesData is a blind pointer private RixLightingServices data
Definition: RixShading.h:843
Shading time, normalized between shutter open and close (type float)
Definition: RixShading.h:904
Surface V parameterization (type float)
Definition: RixShading.h:892
Parent ray shading context serialization (type int)
Definition: RixShading.h:910
Ray footprint (radius) in W (type float)
Definition: RixShading.h:898
virtual void CreateInstanceData(RixContext &rixCtx, RtUString const handle, RixParameterList const *parameterList, InstanceData *instanceData)
Definition: RixShading.h:303
virtual int Init(RixContext &ctx, RtUString const pluginPath)=0
RixDisplacement * displacement
Definition: RixShading.h:667
pxrcore::Matrix4x4 RtMatrix4x4
Definition: RiTypesHelper.h:73
Length of view vector (type float)
Definition: RixShading.h:883
void const * RtConstPointer
Definition: ri.h:86
RtUString name
Definition: RixShading.h:479
RixBxdfFactory::BeginInterior mode.
Definition: RixShading.h:503
Number of shading modes.
Definition: RixShading.h:508
pxrcore::Float3 RtFloat3
Definition: RiTypesHelper.h:68
RayProperty
Definition: RixShading.h:443
PRMANAPI const RtUString k_P
"P"
Definition: RixRNG.h:59
Surface W parameterization (type float)
Definition: RixShading.h:893
int GetParamInfo(int paramId, RixSCType *type, bool *isConnected, int *arrayLength=NULL) const
Definition: RixShading.h:545
Spread of incident ray (type float): how much the ray radius increased for each unit distance the ray...
Definition: RixShading.h:885
Incident index of refraction (type float)
Definition: RixShading.h:907
virtual bool GetProperty(RayProperty, void const *) const
Definition: RixShading.h:1033
Bias to apply for reflected rays (type float)
Definition: RixShading.h:889
Surface U parameterization (type float)
Definition: RixShading.h:891
RixBxdfFactory::BeginScatter mode.
Definition: RixShading.h:504
RixVolumeIntegrator * BeginOppositeVol(int numRays, RtRayGeometry *rays) const
Definition: RixShading.h:757
RixOpacity * GetOpacity() const
Definition: RixShading.h:696
float * opacityStochasticWeight
Definition: RixShading.h:840
RixSCParamInfo(RtUString const _name, RixSCType t, RixSCAccess a=k_RixSCInput, int length=-1)
Definition: RixShading.h:459
Surface derivative in V (type RtFloat3)
Definition: RixShading.h:901
Definition: RixBxdf.h:919
RixSCAccess
Definition: RixShading.h:397
RixSCParamInfo const * paramtable
Definition: RixShading.h:292
Current LPE State (type RixLPEState)
Definition: RixShading.h:909
RixVolumeIntegrator * GetSubsurface() const
Definition: RixShading.h:710
RixSCSyncMsg
Definition: RixShading.h:127
RtInt * pointSampleCount
Definition: RixShading.h:805
Normalized geometric normal (type RtFloat3)
Definition: RixShading.h:879
RixVolumeIntegrator * BeginIncidentVol(int numRays, RtRayGeometry *rays) const
two convenience methods
Definition: RixShading.h:753
RixSCDetail EvalAndCopyParam(int paramId, int arrayIndex, T **result, T const *dflt=NULL, bool promoteToVarying=false, MemCategory mcat=k_BxdfMem) const
Definition: RixShading.h:1168
bool IsValid() const
Definition: RixShading.h:629
virtual void Finalize(RixContext &ctx)=0
RixDisplacement * GetDisplacement() const
Definition: RixShading.h:704
RixBxdfFactory::BeginOpacity presence mode.
Definition: RixShading.h:500
PRMANAPI const RtUString k_du
"du"
Texture baking mode.
Definition: RixShading.h:505
virtual ~RixShadingContext()
Definition: RixShading.h:1338
int RtInt
Definition: ri.h:55
unsigned missContext
true if shading for a first hit
Definition: RixShading.h:648
RixSCType type
Definition: RixShading.h:481
RixVolumeIntegrator * subsurface
Definition: RixShading.h:670
#define PIXAR_ARGUSED(x)
Definition: prmanapi.h:171
RixLight const * light
Definition: RixShading.h:847
virtual int GetVersion() const
Definition: RixShading.h:171