38 #ifndef RixLPEInline_h 39 #define RixLPEInline_h 58 static const unsigned char k_numScatterTypes = k_RixBXMaxNumDiffuseLobes +
59 k_RixBXMaxNumSpecularLobes +
60 k_RixBXMaxNumUserLobes;
63 static const unsigned char k_diffStart = 0;
64 static const unsigned char k_specStart = k_diffStart + k_RixBXMaxNumDiffuseLobes;
65 static const unsigned char k_userStart = k_specStart + k_RixBXMaxNumSpecularLobes;
79 const Transition *middle = begin + ((end - begin)>>1);
80 if (symbol < middle->symbol)
82 else if (middle->
symbol < symbol)
90 void *
const *
getRules(
int state,
int &count)
const 130 return lgtGrpId + k_baseLgtGrpTokenOffset;
146 return m_anyCustomLPEs;
154 : m_automata( automata ), m_nautomata( nautomata )
167 m_state.resize(m_nautomata);
168 std::fill(m_state.begin(), m_state.end(), 0);
193 if( !m_automata )
return true;
194 for(
int i = 0; i < m_nautomata; i++ ) if(m_state[i] >=0)
return false;
202 std::vector<short> saveState =
GetState();
203 move(dir, sca, custom);
218 nautomata = m_nautomata;
237 m_thruput *= thruput;
259 bool firstContribution,
284 move( event, scatt, lpeGroupId );
295 bool doStateTransition)
304 if( doStateTransition )
306 move( event, scatt, lpeGroupId );
309 m_thruput *= thruput;
320 for(
int i = 0; i < m_nautomata; i++ )
327 m_state[i] = m_automata[i].
getTransition(m_state[i], custom);
340 bool isSpecular,
unsigned char lpeId)
342 m_isReflect = isReflect;
347 m_lpeIndex =
static_cast<unsigned char>(k_userStart + m_lpeId);
349 else if( isSpecular )
352 m_lpeIndex =
static_cast<unsigned char>(k_specStart + m_lpeId);
357 m_lpeIndex =
static_cast<unsigned char>(k_diffStart + m_lpeId);
372 else if( lobeSampled.
GetUser() )
375 m_lpeIndex =
static_cast<unsigned char>(k_userStart + m_lpeId);
380 m_lpeIndex =
static_cast<unsigned char>(k_specStart + m_lpeId);
386 m_lpeIndex =
static_cast<unsigned char>(k_diffStart + m_lpeId);
400 assert((dl && !sl) ||
404 if( (dl && sl) || (!dl && !sl) )
409 m_lpeId = m_lpeIndex = 0;
417 bool isDiffuse = (dl != 0);
423 m_lpeIndex = isDiffuse ? k_diffStart : k_specStart;
424 m_lpeIndex =
static_cast<unsigned char>(m_lpeIndex + m_lpeId);
427 m_scatter += m_lpeId;
446 return !GetValid() ? 0 : m_lpeId;
452 return !GetValid() ? 0 : m_lpeIndex;
468 int integratorCtxIdx,
479 bool writeOpacityAllowed)
481 m_lgtLpeToken(lgtLpeToken),
482 m_lpeGrpId(lpeGrpId),
483 m_isReflect(isReflect),
484 m_lgtTrans(lgtTrans),
485 m_displaySvc(displaySvc),
486 m_integratorCtxIdx(integratorCtxIdx),
490 m_shadingCtxIdx(shadingCtxIdx),
491 m_writeOpacityAllowed(writeOpacityAllowed)
519 bool firstContribution =
true;
523 size_t stateSize = state.size();
524 short stateBuffer[1<<16];
526 short* stateBackup = stateBuffer;
527 if (stateSize > 1<<16)
529 stateBackup = (
short*)malloc(stateSize*
sizeof(
short));
531 memcpy(stateBackup, state.data(), stateSize*
sizeof(short));
539 firstContribution =
false;
542 int diffLpeId = k_diffStart + lpeId;
549 firstContribution, lgtLpeToken);
551 diffuse, &
m_lgtTrans, isFinite, clamp, diffLpeId,
555 memcpy(state.data(), stateBackup, stateSize*
sizeof(short));
564 firstContribution =
false;
567 int specLpeId = k_specStart + lpeId;
574 firstContribution, lgtLpeToken);
576 specular, &
m_lgtTrans, isFinite, clamp, specLpeId,
580 memcpy(state.data(), stateBackup, stateSize*
sizeof(short));
588 firstContribution =
false;
591 int userLpeId = k_userStart + lpeId;
604 memcpy(state.data(), stateBackup, stateSize*
sizeof(short));
607 if (stateBackup != stateBuffer) free(stateBackup);
617 : RixConstants::k_ZeroRGB;
650 size_t stateSize = state.size();
651 short stateBuffer[1<<16];
653 short* stateBackup = stateBuffer;
654 if (stateSize > 1<<16)
656 stateBackup = (
short*)malloc(stateSize*
sizeof(
short));
658 memcpy(stateBackup, state.data(), stateSize*
sizeof(short));
667 memcpy(state.data(), stateBackup, stateSize*
sizeof(short));
669 if (stateBackup != stateBuffer) free(stateBackup);
680 : RixConstants::k_ZeroRGB,
712 : RixConstants::k_ZeroRGB,
721 float trans1 = trans.ChannelAvg();
742 clamp, isFinite, overwritePolicy, isHoldout );
static PRMAN_INLINE RixLPEToken LgtGrpIdToToken(int lightGroupId)
Convert an integer light group id to an LPE token.
pxrcore::ColorRGB RtColorRGB
PRMAN_INLINE bool GetSpecular() const
PRMAN_INLINE bool GetValid() const
void MoveLight(RixShadingContext const *sCtx, int sCtxIndex, RtColorRGB const &thruput, RtColorRGB const *lightTrans, bool firstContribution, RixLPEToken lgtLpeToken)
This struct represents the characteristics of just one lobe of a bxdf.
void SetState(const std::vector< short > &state)
PRMAN_INLINE RtColorRGB SumAtIndex(int index, bool includeUserLobes=false) const
virtual void Splat(const RixLPEState &accum, RixDisplayServices *dspy, const RtColorRGB &val, const int integratorCtxIdx, const RtColorRGB *lgtTrans, const float clamp, const bool isFinite, const OverwritePolicy overwritePolicy, const bool isHoldout) const =0
bool Test(const RixLPEToken dir, const RixLPEToken sca, const RixLPEToken custom)
PRMAN_INLINE void SplatPerLobe(RixBXActiveLobeWeights &activeLobes, int weightIndex, RtColorRGB const &thruput, bool isFinite, float clamp=1.0f, bool isHoldout=false)
void MoveCamera(RixShadingContext const *sCtx, int sCtxIndex)
PRMAN_INLINE bool GetValid() const
PRMAN_INLINE void SplatLPE(RtColorRGB const &val, RtColorRGB const *lightTrans, bool isFinite, float clamp, int lpeId=-1, OverwritePolicy overwritePolicy=k_Overwrite, bool isHoldout=false)
std::vector< short > & GetState()
PRMAN_INLINE unsigned int RixFindFirstSetBit(unsigned long long v)
short getTransition(short state, RixLPEToken symbol) const
static bool trans_comp(const Transition &a, const Transition &b)
PRMAN_INLINE unsigned char GetDiffuseLpeId(int i) const
RixLPEState(RixLPEAutomata const *automata, const int nautomata)
PRMAN_INLINE unsigned char GetNumSpecularLobes() const
std::vector< void * > m_rules
void *const * getRules(int state, int &count) const
PRMAN_INLINE unsigned char GetLpeId() const
std::vector< int > customIdVec
void MoveVertex(RixShadingContext const *sCtx, int sCtxIndex, RixLPEScatterEvent const scatterEvent, RixLPEToken lpeGroupId=RixLPE::k_BLANK)
const RixLPEAutomata * GetAutomata(int &nautomata) const
PRMAN_INLINE unsigned char GetNumDiffuseLobes() const
PRMAN_INLINE RtColorRGB const * GetDiffuseLobe(int i) const
const RtColorRGB & GetThruput() const
PRMAN_INLINE ~SplatHelper()
PRMAN_INLINE RtColorRGB const * GetUserLobe(int i) const
PRMAN_INLINE unsigned short GetSpecular() const
PRMAN_INLINE void SplatEmission(RtColorRGB const &emission, RtColorRGB const &thruput, bool isFinite, float clamp=1.0f, bool isHoldout=false)
RixDisplayServices * m_displaySvc
PRMAN_INLINE void SplatValue(RtColorRGB const &color, bool isFinite, float clamp=1.0f)
PRMAN_INLINE unsigned char GetLpeId() const
PRMAN_INLINE bool AnyLPEs() const
PRMAN_INLINE void SplatBeauty(RtColorRGB const &val, RtColorRGB &trans) const
PRMAN_INLINE unsigned char GetNumUserLobes() const
PRMAN_INLINE unsigned char GetUserLpeId(int i) const
PRMAN_INLINE RixLPEToken GetEvent() const
virtual void WriteOpacity(RixChannelId id, int iCtxIndex, float const value)=0
std::vector< Transition > m_trans
PRMAN_INLINE unsigned char GetLpeIndex() const
PRMAN_INLINE bool GetReflect() const
RixLPEToken m_lgtLpeToken
void MoveEmissiveObject(RixShadingContext const *sCtx, int sCtxIndex, RtColorRGB const &thruput, RixLPEToken lpeGroupId=RixLPE::k_BLANK)
std::vector< State > m_states
PRMAN_INLINE RtColorRGB const * GetSpecularLobe(int i) const
bool m_writeOpacityAllowed
PRMAN_INLINE bool GetUser() const
RixChannelId m_beautyChanId
PRMAN_INLINE SplatHelper(RixDisplayServices *displaySvc, int integratorCtxIndex, RixLPE &rixLpe, RixLPEState &state, int depth, RixLPEToken lightLpeToken, RixLPEToken lpeGroupId, bool isReflect, RtColorRGB const &eyeTrans, RtColorRGB const &lightTrans, RixShadingContext const *shadingCtx, int shadingCtxIndex, bool writeOpacityAllowed=true)
PRMAN_INLINE unsigned short GetDiffuse() const
PRMAN_INLINE bool GetReflect() const
PRMAN_INLINE bool AnyCustomLPEs() const
PRMAN_INLINE unsigned char GetSpecularLpeId(int i) const
RixShadingContext const * m_sCtx
PRMAN_INLINE RixLPEToken GetScatt() const
PRMAN_INLINE RixLPEScatterEvent(RixBXLobeSampled lobeSampled)
virtual bool Splat(RixChannelId id, int iCtxIndex, float const value)=0