38 #ifndef _RIX_PHOTON_GUIDING_H_ 39 #define _RIX_PHOTON_GUIDING_H_ 49 #define SAMPLING_STABILITY_FACTOR 1e-4f 64 float enlarge = 0.1f);
96 friend class RixPhotonGuiding;
102 const RixPhotonGuiding* photonGuiding);
257 : m_probability(probability)
259 assert(m_probability >= 0.0f && m_probability <= 1.0f);
271 m_boundingBox = boundingBox;
278 return m_boundingBox;
285 return m_probability;
292 return m_hasVolume && m_probability > 0.0f;
301 if (sample < m_probability)
303 sample = sample / m_probability;
308 sample = (sample - m_probability) / (1.0f - m_probability);
324 return !(m_boundingBox.
Contains(origin)) &&
326 !(Dot(normal, m_boundingBox.
min - origin) < 0.0f &&
327 Dot(normal, m_boundingBox.
max - origin) < 0.0f));
335 return !m_boundingBox.
Contains(origin);
358 direction = posOnPlane - origin;
360 float dist2 = Dot(direction, direction);
361 direction.Normalize();
362 cosTheta = AbsDot(direction, normal);
379 float nvInv = 1.0f / Dot(bbp.
m_n, direction);
381 float dno = bbp.
m_d - Dot(bbp.
m_n, origin);
383 RtVector3 hitRay = dno * nvInv * direction + origin - bbp.
m_c;
384 float hitS = Dot(hitRay, bbp.
m_s);
385 float hitT = Dot(hitRay, bbp.
m_t);
426 hitRay -= bbp.
m_n * bbp.
m_n.Dot(hitRay);
430 assert(AbsDot(hrn, bbp.
m_n) < 0.001f);
432 float hitS = Dot(hitRay, bbp.
m_s);
433 float hitT = Dot(hitRay, bbp.
m_t);
457 float otherPdf =
directionPdf(position, bboxProjection, direction);
480 RtVector3 projectionPoint = v * 2.0f + center;
486 float dno = bbp.
m_d - Dot(bbp.
m_n, posInScene);
514 RixPhotonGuiding::init(
float enlarge)
521 m_boundingBox.
min -= expand;
522 m_boundingBox.
min += expand;
526 m_corners[0] = m_boundingBox.
min;
527 m_corners[1] = m_boundingBox.
max,
528 m_corners[2] =
RtPoint3(m_boundingBox.
min.x, m_boundingBox.
min.y, m_boundingBox.
max.z);
529 m_corners[3] =
RtPoint3(m_boundingBox.
min.x, m_boundingBox.
max.y, m_boundingBox.
min.z);
530 m_corners[4] =
RtPoint3(m_boundingBox.
max.x, m_boundingBox.
min.y, m_boundingBox.
min.z);
531 m_corners[5] =
RtPoint3(m_boundingBox.
min.x, m_boundingBox.
max.y, m_boundingBox.
max.z);
532 m_corners[6] =
RtPoint3(m_boundingBox.
max.x, m_boundingBox.
min.y, m_boundingBox.
max.z);
533 m_corners[7] =
RtPoint3(m_boundingBox.
max.x, m_boundingBox.
max.y, m_boundingBox.
min.z);
534 m_center = (m_boundingBox.
max + m_boundingBox.
min) * 0.5f;
535 m_hasVolume = m_boundingBox.
Volume() > 0.0f;
544 : m_photonGuiding(photonGuiding)
567 m_c = cpp + projectionPoint;
575 float dno =
m_d - Dot(
m_n, projectionPoint);
580 for (
int i = 0; i < 8; ++i)
584 float nvInv = 1.0f / Dot(
m_n, v);
586 RtVector3 hitRay = dno * nvInv * v - cpp;
587 float hitS = Dot(hitRay,
m_s);
588 float hitT = Dot(hitRay,
m_t);
596 m_sizeT = m_stCoords[3] - m_stCoords[1];
628 for (
int i = 0; i < 8; ++i)
631 float dist = Dot(
m_n, (cornerpt - c));
633 float hitS = Dot(hitRay,
m_s);
634 float hitT = Dot(hitRay,
m_t);
642 m_sizeT = m_stCoords[3] - m_stCoords[1];
707 #endif // _RIX_PHOTON_GUIDING_H_ static PRMAN_INLINE void computeOrthonormalBasis(RtVector3 &n, RtVector3 &s, RtVector3 &t)
PRMAN_INLINE float positionPdf(const RtPoint3 &position, const BoundingBoxProjection &bbp) const
PRMAN_INLINE bool isPositionOnPlane(float cs, float ct) const
PRMAN_INLINE BoundingBoxProjection(const RixPhotonGuiding *photonGuiding)
const RixPhotonGuiding * m_photonGuiding
PRMAN_INLINE float samplingPdf() const
PRMAN_INLINE bool canSample(const RtPoint3 &origin, const RtNormal3 &normal, bool onesided) const
PRMAN_INLINE float MISEnvLightPdf(const RtVector3 &dirToEnv, const RtPoint3 &posInScene, const RtPoint3 ¢er, float radius, float posPdf) const
PRMAN_INLINE void stabilizeSampling(float min)
PRMAN_INLINE float MISAreaLightPdf(const RtPoint3 &position, const RtNormal3 &normal, const RtVector3 &direction, bool onesided, float dirPdf) const
PRMAN_INLINE RixPhotonGuiding(float probability)
PRMAN_INLINE RtPoint3 generatePositionOnPlane(float sx, float sy) const
PRMAN_INLINE bool isEnabled() const
PRMAN_INLINE float projectionArea() const
PRMAN_INLINE float directionPdf(const RtPoint3 &origin, const BoundingBoxProjection &bbp, const RtVector3 &direction) const
PRMAN_INLINE void samplePosition(const BoundingBoxProjection &bbp, float samplex, float sampley, RtPoint3 &position, float &pdf) const
PRMAN_INLINE void setBoundingBox(const RtBBox &boundingBox, float enlarge=0.1f)
PRMAN_INLINE void sampleDirection(const RtPoint3 &origin, const RtNormal3 &normal, const BoundingBoxProjection &bbp, float samplex, float sampley, RtVector3 &direction, float &cosTheta, float &pdf) const
PRMAN_INLINE void computeProjection(const RtPoint3 &projectionPoint)
bool Contains(const RtPoint3 &pt) const
PRMAN_INLINE bool pickPhotonGuiding(float &sample) const
PRMAN_INLINE const RtBBox & getBoundingBox() const
RtPoint3 m_projectionPoint
PRMAN_INLINE RtPoint3 getPositionOnPlane(float cs, float ct) const
#define SAMPLING_STABILITY_FACTOR