Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TransformedIntersectable.h
Go to the documentation of this file.
1#pragma once
2
5#include "Core/Ray.h"
6#include "Core/HitDetail.h"
7#include "Core/HitProbe.h"
8
9#include <Common/assertion.h>
10
11namespace ph
12{
13
17{
18 // FIXME: intersecting routines' time correctness
19public:
21
23 const Intersectable* intersectable,
24 const math::Transform* localToWorld,
25 const math::Transform* worldToLocal);
26
27 bool isIntersecting(const Ray& ray, HitProbe& probe) const override
28 {
29 Ray localRay;
30 m_worldToLocal->transform(ray, &localRay);
31 if(m_intersectable->isIntersecting(localRay, probe))
32 {
33 probe.pushIntermediateHit(this);
34 return true;
35 }
36 else
37 {
38 return false;
39 }
40 }
41
43 const Ray& ray,
44 HitProbe& probe,
45 const Ray& srcRay,
46 HitProbe& srcProbe) const override
47 {
48 PH_ASSERT(srcProbe.getTopHit() == this);
49 srcProbe.popHit();
50
51 Ray localRay, localSrcRay;
52 m_worldToLocal->transform(ray, &localRay);
53 m_worldToLocal->transform(srcRay, &localSrcRay);
54 if(srcProbe.getTopHit()->reintersect(localRay, probe, localSrcRay, srcProbe))
55 {
56 probe.pushIntermediateHit(this);
57 return true;
58 }
59 else
60 {
61 return false;
62 }
63 }
64
66 const Ray& ray,
67 HitProbe& probe,
68 HitDetail* const out_detail) const override
69 {
70 // If failed, it is likely to be caused by: 1. mismatched/missing probe push or pop in
71 // the hit stack; 2. the hit event is invalid
72 PH_ASSERT(probe.getTopHit() == this);
73 probe.popHit();
74
75 Ray localRay;
76 m_worldToLocal->transform(ray, &localRay);
77
78 // Current hit is not necessary `m_intersectable`. For example, if `m_intersectable` contains
79 // multiple instances then it could simply skip over to one of them.
80 PH_ASSERT(probe.getTopHit());
81 HitDetail localDetail;
82 probe.getTopHit()->calcHitDetail(localRay, probe, &localDetail);
83
84 *out_detail = localDetail;
86 localDetail.getHitInfo(ECoordSys::World), &(out_detail->getHitInfo(ECoordSys::World)));
87
88 const auto [meanFactor, maxFactor] = out_detail->getDistanceErrorFactors();
89 out_detail->setDistanceErrorFactors(meanFactor, maxFactor * 1.25_r);
90 }
91
92 bool isOccluding(const Ray& ray) const override
93 {
94 Ray localRay;
95 m_worldToLocal->transform(ray, &localRay);
96 return m_intersectable->isOccluding(localRay);
97 }
98
99 bool mayOverlapVolume(const math::AABB3D& aabb) const override;
100 math::AABB3D calcAABB() const override;
101
102protected:
106};
107
108}// end namespace ph
Detailed information regarding a ray-primitive intersection.
Definition HitDetail.h:26
void setDistanceErrorFactors(real meanFactor, real maxFactor)
Definition HitDetail.h:192
std::pair< real, real > getDistanceErrorFactors() const
Definition HitDetail.h:185
const HitInfo & getHitInfo(ECoordSys coordSys=ECoordSys::World) const
Definition HitDetail.h:173
Lightweight ray intersection testing and reporting object. If an intersection is found,...
Definition HitProbe.h:27
const Intersectable * getTopHit() const
Definition HitProbe.h:154
void popHit()
Removes the most recent hit target from the stack.
Definition HitProbe.h:127
void pushIntermediateHit(const Intersectable *hitTarget)
Adds a hit target that will participate in hit detail's calculation to the stack.
Definition HitProbe.h:112
An object in the scene that a ray can intersect with.
Definition Intersectable.h:31
virtual bool reintersect(const Ray &ray, HitProbe &probe, const Ray &srcRay, HitProbe &srcProbe) const =0
Intersect the intersected object again with a different ray.
virtual bool isOccluding(const Ray &ray) const
Determines whether this object blocks the ray.
Definition Intersectable.cpp:8
virtual void calcHitDetail(const Ray &ray, HitProbe &probe, HitDetail *out_detail) const =0
Calculates properties of a hit, such as coordinates and normal.
virtual bool isIntersecting(const Ray &ray, HitProbe &probe) const =0
Determine whether a given ray hits the object.
Represents a ray in space.
Definition Ray.h:21
Applies general transformation to an intersectable.
Definition TransformedIntersectable.h:17
const Intersectable * m_intersectable
Definition TransformedIntersectable.h:103
const math::Transform * m_worldToLocal
Definition TransformedIntersectable.h:105
bool isOccluding(const Ray &ray) const override
Determines whether this object blocks the ray.
Definition TransformedIntersectable.h:92
TransformedIntersectable()
Definition TransformedIntersectable.cpp:7
bool isIntersecting(const Ray &ray, HitProbe &probe) const override
Determine whether a given ray hits the object.
Definition TransformedIntersectable.h:27
bool reintersect(const Ray &ray, HitProbe &probe, const Ray &srcRay, HitProbe &srcProbe) const override
Intersect the intersected object again with a different ray.
Definition TransformedIntersectable.h:42
void calcHitDetail(const Ray &ray, HitProbe &probe, HitDetail *const out_detail) const override
Calculates properties of a hit, such as coordinates and normal.
Definition TransformedIntersectable.h:65
bool mayOverlapVolume(const math::AABB3D &aabb) const override
Conservatively checks whether this object overlaps a volume.
Definition TransformedIntersectable.cpp:30
const math::Transform * m_localToWorld
Definition TransformedIntersectable.h:104
math::AABB3D calcAABB() const override
Calculates Axis-Aligned Bounding Box (AABB) of itself.
Definition TransformedIntersectable.cpp:39
Definition Transform.h:21
void transform(const Ray &ray, Ray *out_ray) const
Definition Transform.cpp:50
The root for all renderer implementations.
Definition EEngineProject.h:6