37 #ifndef RixLPEInline_h
38 #define RixLPEInline_h
50 #include "RiTypesHelper.h"
57 static const unsigned char k_numScatterTypes = k_RixBXMaxNumDiffuseLobes +
58 k_RixBXMaxNumSpecularLobes +
59 k_RixBXMaxNumUserLobes;
62 static const unsigned char k_diffStart = 0;
63 static const unsigned char k_specStart = k_diffStart + k_RixBXMaxNumDiffuseLobes;
64 static const unsigned char k_userStart = k_specStart + k_RixBXMaxNumSpecularLobes;
78 const Transition *middle = begin + ((end - begin)>>1);
79 if (symbol < middle->symbol)
81 else if (middle->
symbol < symbol)
89 void *
const *
getRules(
int state,
int &count)
const
153 : m_automata( automata ), m_nautomata( nautomata )
166 m_state.resize(m_nautomata);
167 std::fill(m_state.begin(), m_state.end(), 0);
171 PRMAN_INLINE std::vector<short>&
177 PRMAN_INLINE
const std::vector<short>&
192 if( !m_automata )
return true;
193 for(
int i = 0; i < m_nautomata; i++ ) if(m_state[i] >=0)
return false;
201 std::vector<short> saveState =
GetState();
202 move(dir, sca, custom);
208 PRMAN_INLINE
const RtColorRGB&
217 nautomata = m_nautomata;
225 PIXAR_ARGUSED(sCtxIndex);
231 const RtColorRGB& thruput)
234 PIXAR_ARGUSED(sCtxIndex);
236 m_thruput *= thruput;
243 RtColorRGB
const& thruput,
247 PIXAR_ARGUSED(sCtxIndex);
248 PIXAR_ARGUSED(thruput);
256 RtColorRGB
const& thruput,
257 RtColorRGB
const* lightTrans,
258 bool firstContribution,
262 PIXAR_ARGUSED(sCtxIndex);
263 PIXAR_ARGUSED(thruput);
264 PIXAR_ARGUSED(lightTrans);
265 PIXAR_ARGUSED(firstContribution);
277 PIXAR_ARGUSED(sCtxIndex);
283 move( event, scatt, lpeGroupId );
292 const RtColorRGB& thruput,
294 bool doStateTransition)
297 PIXAR_ARGUSED(sCtxIndex);
303 if( doStateTransition )
305 move( event, scatt, lpeGroupId );
308 m_thruput *= thruput;
319 for(
int i = 0; i < m_nautomata; i++ )
326 m_state[i] = m_automata[i].
getTransition(m_state[i], custom);
339 bool isSpecular,
unsigned char lpeId)
341 m_isReflect = isReflect;
346 m_lpeIndex =
static_cast<unsigned char>(k_userStart + m_lpeId);
348 else if( isSpecular )
351 m_lpeIndex =
static_cast<unsigned char>(k_specStart + m_lpeId);
356 m_lpeIndex =
static_cast<unsigned char>(k_diffStart + m_lpeId);
371 else if( lobeSampled.
GetUser() )
374 m_lpeIndex =
static_cast<unsigned char>(k_userStart + m_lpeId);
379 m_lpeIndex =
static_cast<unsigned char>(k_specStart + m_lpeId);
385 m_lpeIndex =
static_cast<unsigned char>(k_diffStart + m_lpeId);
399 assert((dl && !sl) ||
403 if( (dl && sl) || (!dl && !sl) )
408 m_lpeId = m_lpeIndex = 0;
416 bool isDiffuse = (dl != 0);
422 m_lpeIndex = isDiffuse ? k_diffStart : k_specStart;
423 m_lpeIndex =
static_cast<unsigned char>(m_lpeIndex + m_lpeId);
426 m_scatter += m_lpeId;
442 PRMAN_INLINE
unsigned char
448 PRMAN_INLINE
unsigned char
451 return !
GetValid() ? 0 : m_lpeIndex;
467 int integratorCtxIdx,
474 RtColorRGB
const& eyeTrans,
475 RtColorRGB
const& lgtTrans,
478 bool writeOpacityAllowed)
480 m_lgtLpeToken(lgtLpeToken),
481 m_lpeGrpId(lpeGrpId),
482 m_isReflect(isReflect),
483 m_lgtTrans(lgtTrans),
484 m_displaySvc(displaySvc),
485 m_integratorCtxIdx(integratorCtxIdx),
489 m_shadingCtxIdx(shadingCtxIdx),
490 m_writeOpacityAllowed(writeOpacityAllowed),
491 m_worldXform(nullptr),
492 m_objectXform(nullptr),
493 m_cameraXform(nullptr)
500 const RtMatrix4x4* worldXform =
nullptr;
502 if (worldXform && numMatrices > 0)
507 const RtMatrix4x4* objectXform =
nullptr;
509 if (objectXform && numMatrices > 0)
514 const RtMatrix4x4* cameraXform =
nullptr;
516 if (cameraXform && numMatrices > 0)
531 RtColorRGB
const& thruput,
537 RixLPE const& rixLpe = m_rixLpe;
543 bool isReflect = m_isReflect;
546 bool firstContribution =
true;
549 std::vector<short>& state = m_state.GetState();
550 size_t stateSize = state.size();
551 short stateBuffer[1<<16];
553 short* stateBackup = stateBuffer;
554 if (stateSize > 1<<16)
556 stateBackup = (
short*)malloc(stateSize*
sizeof(
short));
558 memcpy(stateBackup, state.data(), stateSize*
sizeof(short));
563 RtColorRGB
const& diffuse = activeLobes.
GetDiffuseLobe(i)[weightIndex];
565 firstContribution =
false;
568 int diffLpeId = k_diffStart + lpeId;
571 m_sCtx, m_shadingCtxIdx, lpeEvent,
574 m_sCtx, m_shadingCtxIdx, diffuse, &m_lgtTrans,
575 firstContribution, lgtLpeToken);
577 diffuse, &m_lgtTrans, isFinite, clamp, diffLpeId,
581 memcpy(state.data(), stateBackup, stateSize*
sizeof(short));
587 RtColorRGB
const& specular = activeLobes.
GetSpecularLobe(i)[weightIndex];
589 firstContribution =
false;
592 int specLpeId = k_specStart + lpeId;
595 m_sCtx, m_shadingCtxIdx, lpeEvent,
598 m_sCtx, m_shadingCtxIdx, specular, &m_lgtTrans,
599 firstContribution, lgtLpeToken);
601 specular, &m_lgtTrans, isFinite, clamp, specLpeId,
605 memcpy(state.data(), stateBackup, stateSize*
sizeof(short));
611 RtColorRGB
const& user = activeLobes.
GetUserLobe(i)[weightIndex];
613 firstContribution =
false;
616 int userLpeId = k_userStart + lpeId;
619 m_sCtx, m_shadingCtxIdx, lpeEvent,
622 m_sCtx, m_shadingCtxIdx, user, &m_lgtTrans, firstContribution,
625 user, &m_lgtTrans, isFinite, clamp, userLpeId,
k_Overwrite,
629 memcpy(state.data(), stateBackup, stateSize*
sizeof(short));
632 if (stateBackup != stateBuffer) free(stateBackup);
640 RtColorRGB val = isFinite
641 ? activeLobes.
SumAtIndex(weightIndex) * thruput * m_lgtTrans * clamp
642 : RixConstants::k_ZeroRGB;
644 SplatBeauty(val, m_eyeTrans);
646 else if (m_writeOpacityAllowed && (m_depth == 0))
648 float trans1 = m_eyeTrans.ChannelAvg();
651 m_displaySvc->WriteOpacity(
652 m_rixLpe.m_beautyChanId, m_integratorCtxIdx, 1.0f - trans1);
660 RtColorRGB
const& emission,
661 RtColorRGB
const& thruput,
667 RixLPE const& rixLpe = m_rixLpe;
674 std::vector<short>& state = m_state.GetState();
675 size_t stateSize = state.size();
676 short stateBuffer[1<<16];
678 short* stateBackup = stateBuffer;
679 if (stateSize > 1<<16)
681 stateBackup = (
short*)malloc(stateSize*
sizeof(
short));
683 memcpy(stateBackup, state.data(), stateSize*
sizeof(short));
685 m_state.MoveEmissiveObject(
686 m_sCtx, m_shadingCtxIdx, emission, m_lpeGrpId);
692 memcpy(state.data(), stateBackup, stateSize*
sizeof(short));
694 if (stateBackup != stateBuffer) free(stateBackup);
704 ? (emission * thruput * m_lgtTrans * clamp)
705 : RixConstants::k_ZeroRGB,
708 else if (m_writeOpacityAllowed && (m_depth == 0))
710 float trans1 = m_eyeTrans.ChannelAvg();
713 m_displaySvc->WriteOpacity(
714 m_rixLpe.m_beautyChanId, m_integratorCtxIdx, 1.0f - trans1);
722 RtColorRGB
const& color,
729 if (m_rixLpe.m_anyLPEs)
731 SplatLPE(color, &m_lgtTrans, isFinite, clamp, -1);
736 ? (color * m_lgtTrans * clamp)
737 : RixConstants::k_ZeroRGB,
744 m_displaySvc->Splat(m_rixLpe.m_beautyChanId, m_integratorCtxIdx, val);
746 float trans1 = trans.ChannelAvg();
747 if (m_writeOpacityAllowed && (m_depth == 0) && (trans1 != 1.0f))
749 m_displaySvc->WriteOpacity(
750 m_rixLpe.m_beautyChanId, m_integratorCtxIdx, 1.0f - trans1);
756 RtColorRGB
const& val,
757 RtColorRGB
const* lgtTrans,
764 PIXAR_ARGUSED(lpeId);
765 m_rixLpe.Splat(m_state, m_displaySvc, val, m_integratorCtxIdx, lgtTrans, clamp, isFinite,
766 overwritePolicy, isHoldout, m_worldXform, m_objectXform, m_cameraXform);