37 #ifndef _RIX_PHOTON_GUIDING_H_ 38 #define _RIX_PHOTON_GUIDING_H_ 48 #define SAMPLING_STABILITY_FACTOR 1e-4f 63 float enlarge = 0.1f);
256 : m_probability(probability)
258 assert(m_probability >= 0.0f && m_probability <= 1.0f);
270 m_boundingBox = boundingBox;
277 return m_boundingBox;
284 return m_probability;
291 return m_hasVolume && m_probability > 0.0f;
300 if (sample < m_probability)
302 sample = sample / m_probability;
307 sample = (sample - m_probability) / (1.0f - m_probability);
323 return !(m_boundingBox.
Contains(origin)) &&
325 !(Dot(normal, m_boundingBox.
min - origin) < 0.0f &&
326 Dot(normal, m_boundingBox.
max - origin) < 0.0f));
334 return !m_boundingBox.
Contains(origin);
357 direction = posOnPlane - origin;
359 float dist2 = Dot(direction, direction);
360 direction.Normalize();
361 cosTheta = AbsDot(direction, normal);
378 float nvInv = 1.0f / Dot(bbp.
m_n, direction);
380 float dno = bbp.
m_d - Dot(bbp.
m_n, origin);
382 RtVector3 hitRay = dno * nvInv * direction + origin - bbp.
m_c;
383 float hitS = Dot(hitRay, bbp.
m_s);
384 float hitT = Dot(hitRay, bbp.
m_t);
425 hitRay -= bbp.
m_n * bbp.
m_n.Dot(hitRay);
429 assert(AbsDot(hrn, bbp.
m_n) < 0.001f);
431 float hitS = Dot(hitRay, bbp.
m_s);
432 float hitT = Dot(hitRay, bbp.
m_t);
456 float otherPdf =
directionPdf(position, bboxProjection, direction);
479 RtVector3 projectionPoint = v * 2.0f + center;
485 float dno = bbp.
m_d - Dot(bbp.
m_n, posInScene);
513 RixPhotonGuiding::init(
float enlarge)
520 m_boundingBox.
min -= expand;
521 m_boundingBox.
min += expand;
525 m_corners[0] = m_boundingBox.
min;
526 m_corners[1] = m_boundingBox.
max,
527 m_corners[2] =
RtPoint3(m_boundingBox.
min.x, m_boundingBox.
min.y, m_boundingBox.
max.z);
528 m_corners[3] =
RtPoint3(m_boundingBox.
min.x, m_boundingBox.
max.y, m_boundingBox.
min.z);
529 m_corners[4] =
RtPoint3(m_boundingBox.
max.x, m_boundingBox.
min.y, m_boundingBox.
min.z);
530 m_corners[5] =
RtPoint3(m_boundingBox.
min.x, m_boundingBox.
max.y, m_boundingBox.
max.z);
531 m_corners[6] =
RtPoint3(m_boundingBox.
max.x, m_boundingBox.
min.y, m_boundingBox.
max.z);
532 m_corners[7] =
RtPoint3(m_boundingBox.
max.x, m_boundingBox.
max.y, m_boundingBox.
min.z);
533 m_center = (m_boundingBox.
max + m_boundingBox.
min) * 0.5f;
534 m_hasVolume = m_boundingBox.
Volume() > 0.0f;
543 : m_photonGuiding(photonGuiding)
558 assert(!m_photonGuiding->m_boundingBox.Contains(projectionPoint));
559 assert(m_photonGuiding != NULL);
561 m_projectionPoint = projectionPoint;
563 m_n = m_photonGuiding->m_center - projectionPoint;
566 m_c = cpp + projectionPoint;
574 float dno = m_d - Dot(m_n, projectionPoint);
576 m_stCoords[0] = m_stCoords[1] = FLT_MAX;
577 m_stCoords[2] = m_stCoords[3] = -FLT_MAX;
579 for (
int i = 0; i < 8; ++i)
581 RtVector3 v = m_photonGuiding->m_corners[i] - projectionPoint;
583 float nvInv = 1.0f / Dot(m_n, v);
585 RtVector3 hitRay = dno * nvInv * v - cpp;
586 float hitS = Dot(hitRay, m_s);
587 float hitT = Dot(hitRay, m_t);
588 m_stCoords[0] = std::min(m_stCoords[0], hitS);
589 m_stCoords[1] = std::min(m_stCoords[1], hitT);
590 m_stCoords[2] = std::max(m_stCoords[2], hitS);
591 m_stCoords[3] = std::max(m_stCoords[3], hitT);
594 m_sizeS = m_stCoords[2] - m_stCoords[0];
595 m_sizeT = m_stCoords[3] - m_stCoords[1];
610 assert(m_photonGuiding != NULL);
611 assert(!m_photonGuiding->m_boundingBox.Contains(projectionPoint));
613 m_projectionPoint = projectionPoint;
624 m_stCoords[0] = m_stCoords[1] = FLT_MAX;
625 m_stCoords[2] = m_stCoords[3] = -FLT_MAX;
627 for (
int i = 0; i < 8; ++i)
629 RtPoint3 cornerpt = m_photonGuiding->m_corners[i];
630 float dist = Dot(m_n, (cornerpt - c));
631 RtVector3 hitRay = cornerpt - dist * m_n - c;
632 float hitS = Dot(hitRay, m_s);
633 float hitT = Dot(hitRay, m_t);
634 m_stCoords[0] = std::min(m_stCoords[0], hitS);
635 m_stCoords[1] = std::min(m_stCoords[1], hitT);
636 m_stCoords[2] = std::max(m_stCoords[2], hitS);
637 m_stCoords[3] = std::max(m_stCoords[3], hitT);
640 m_sizeS = m_stCoords[2] - m_stCoords[0];
641 m_sizeT = m_stCoords[3] - m_stCoords[1];
649 return m_sizeS * m_sizeT;
659 return m_c + (m_sizeS * sx + m_stCoords[0]) * m_s +
660 (m_sizeT * sy + m_stCoords[1]) * m_t;
670 return m_c + cs * m_s + ct * m_t;
681 return (cs >= m_stCoords[0] && cs <= m_stCoords[2] &&
682 ct >= m_stCoords[1] && ct <= m_stCoords[3]);
692 float mid = 0.5f * (m_stCoords[2] + m_stCoords[0]);
694 m_stCoords[2] = mid + min * 0.5f;
695 m_stCoords[0] = mid - min * 0.5f;
699 float mid = 0.5f * (m_stCoords[3] + m_stCoords[1]);
701 m_stCoords[3] = mid + min * 0.5f;
702 m_stCoords[1] = mid - min * 0.5f;
706 #endif // _RIX_PHOTON_GUIDING_H_ #define SAMPLING_STABILITY_FACTOR
Definition: RixPhotonGuiding.h:48
Definition: RixPhotonGuiding.h:51
PRMAN_INLINE bool pickPhotonGuiding(float &sample) const
Definition: RixPhotonGuiding.h:298
PRMAN_INLINE float samplingPdf() const
Definition: RixPhotonGuiding.h:282
PRMAN_INLINE bool isPositionOnPlane(float cs, float ct) const
Definition: RixPhotonGuiding.h:677
RtPoint3 m_projectionPoint
Definition: RixPhotonGuiding.h:144
PRMAN_INLINE float MISEnvLightPdf(const RtVector3 &dirToEnv, const RtPoint3 &posInScene, const RtPoint3 ¢er, float radius, float posPdf) const
Definition: RixPhotonGuiding.h:468
PRMAN_INLINE bool isEnabled() const
Definition: RixPhotonGuiding.h:289
RtFloat3 RtPoint3
Definition: RiTypesHelper.h:70
PRMAN_INLINE RtPoint3 getPositionOnPlane(float cs, float ct) const
Definition: RixPhotonGuiding.h:666
float m_sizeT
Definition: RixPhotonGuiding.h:159
PRMAN_INLINE bool canSample(const RtPoint3 &origin, const RtNormal3 &normal, bool onesided) const
Definition: RixPhotonGuiding.h:318
RtVector3 m_s
Definition: RixPhotonGuiding.h:147
RtPoint3 min
Definition: RiTypesHelper.h:330
float Volume() const
Definition: RiTypesHelper.h:365
bool Contains(const RtPoint3 &pt) const
Definition: RiTypesHelper.h:430
RtVector3 m_t
Definition: RixPhotonGuiding.h:148
PRMAN_INLINE void samplePosition(const BoundingBoxProjection &bbp, float samplex, float sampley, RtPoint3 &position, float &pdf) const
Definition: RixPhotonGuiding.h:402
float m_d
Definition: RixPhotonGuiding.h:153
RtPoint3 max
Definition: RiTypesHelper.h:330
Definition: RiTypesHelper.h:327
PRMAN_INLINE void sampleDirection(const RtPoint3 &origin, const RtNormal3 &normal, const BoundingBoxProjection &bbp, float samplex, float sampley, RtVector3 &direction, float &cosTheta, float &pdf) const
Definition: RixPhotonGuiding.h:343
const RixPhotonGuiding * m_photonGuiding
Definition: RixPhotonGuiding.h:142
static PRMAN_INLINE void computeOrthonormalBasis(RtVector3 &n, RtVector3 &s, RtVector3 &t)
Definition: RixPhotonGuiding.h:496
PRMAN_INLINE void computeProjection(const RtPoint3 &projectionPoint)
Definition: RixPhotonGuiding.h:555
RtPoint3 m_c
Definition: RixPhotonGuiding.h:150
PRMAN_INLINE const RtBBox & getBoundingBox() const
Definition: RixPhotonGuiding.h:275
PRMAN_INLINE RtPoint3 generatePositionOnPlane(float sx, float sy) const
Definition: RixPhotonGuiding.h:655
float m_sizeS
Definition: RixPhotonGuiding.h:158
RtFloat3 RtNormal3
Definition: RiTypesHelper.h:73
#define PRMAN_INLINE
Definition: prmanapi.h:99
PRMAN_INLINE void setBoundingBox(const RtBBox &boundingBox, float enlarge=0.1f)
Definition: RixPhotonGuiding.h:268
PRMAN_INLINE float MISAreaLightPdf(const RtPoint3 &position, const RtNormal3 &normal, const RtVector3 &direction, bool onesided, float dirPdf) const
Definition: RixPhotonGuiding.h:445
float m_stCoords[4]
Definition: RixPhotonGuiding.h:156
PRMAN_INLINE float directionPdf(const RtPoint3 &origin, const BoundingBoxProjection &bbp, const RtVector3 &direction) const
Definition: RixPhotonGuiding.h:372
PRMAN_INLINE RixPhotonGuiding(float probability)
Definition: RixPhotonGuiding.h:255
RtVector3 m_n
Definition: RixPhotonGuiding.h:146
PRMAN_INLINE float projectionArea() const
Definition: RixPhotonGuiding.h:647
Definition: RixPhotonGuiding.h:93
PRMAN_INLINE void stabilizeSampling(float min)
Definition: RixPhotonGuiding.h:688
RtFloat3 RtVector3
Definition: RiTypesHelper.h:72
PRMAN_INLINE float positionPdf(const RtPoint3 &position, const BoundingBoxProjection &bbp) const
Definition: RixPhotonGuiding.h:420
PRMAN_INLINE BoundingBoxProjection(const RixPhotonGuiding *photonGuiding)
Definition: RixPhotonGuiding.h:541