Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TransformedPrimitive.h
Go to the documentation of this file.
1#pragma once
2
5#include "Core/HitDetail.h"
6#include "Core/HitProbe.h"
7#include "Core/Ray.h"
8
9#include <Common/assertion.h>
10
11namespace ph::math { class RigidTransform; }
12
13namespace ph
14{
15
22{
23 // FIXME: intersecting routines' time correctness
24public:
26 const Primitive* primitive,
27 const math::RigidTransform* localToWorld,
28 const math::RigidTransform* worldToLocal);
29
30 bool isOccluding(const Ray& ray) const override
31 {
32 Ray localRay;
33 m_worldToLocal->transform(ray, &localRay);
34 return m_primitive->isOccluding(localRay);
35 }
36
37 bool isIntersecting(const Ray& ray, HitProbe& probe) const override
38 {
39 Ray localRay;
40 m_worldToLocal->transform(ray, &localRay);
41 if(m_primitive->isIntersecting(localRay, probe))
42 {
43 probe.pushIntermediateHit(this);
44 return true;
45 }
46 else
47 {
48 return false;
49 }
50 }
51
53 const Ray& ray,
54 HitProbe& probe,
55 const Ray& srcRay,
56 HitProbe& srcProbe) const override
57 {
58 PH_ASSERT(srcProbe.getTopHit() == this);
59 srcProbe.popHit();
60
61 Ray localRay, localSrcRay;
62 m_worldToLocal->transform(ray, &localRay);
63 m_worldToLocal->transform(srcRay, &localSrcRay);
64 if(srcProbe.getTopHit()->reintersect(localRay, probe, localSrcRay, srcProbe))
65 {
66 probe.pushIntermediateHit(this);
67 return true;
68 }
69 else
70 {
71 return false;
72 }
73 }
74
76 const Ray& ray,
77 HitProbe& probe,
78 HitDetail* const out_detail) const override
79 {
80 // If failed, it is likely to be caused by: 1. mismatched/missing probe push or pop in
81 // the hit stack; 2. the hit event is invalid
82 PH_ASSERT(probe.getTopHit() == this);
83 probe.popHit();
84
85 Ray localRay;
86 m_worldToLocal->transform(ray, &localRay);
87
88 // Current hit is not necessary `m_primitive`. For example, if `m_primitive` contains
89 // multiple instances then it could simply skip over to one of them.
90 PH_ASSERT(probe.getTopHit());
91 HitDetail localDetail;
92 probe.getTopHit()->calcHitDetail(localRay, probe, &localDetail);
93
94 *out_detail = localDetail;
95 m_localToWorld->transform(
96 localDetail.getHitInfo(ECoordSys::World), &(out_detail->getHitInfo(ECoordSys::World)));
97
98 const auto [meanFactor, maxFactor] = out_detail->getDistanceErrorFactors();
99 out_detail->setDistanceErrorFactors(meanFactor, maxFactor * 1.25_r);
100
101 // This is a representative of the original primitive
102 out_detail->setHitIntrinsics(
103 this,
104 out_detail->getUVW(),
105 out_detail->getRayT(),
106 out_detail->getFaceID(),
107 out_detail->getFaceTopology());
108 }
109
110 bool mayOverlapVolume(const math::AABB3D& aabb) const override;
111 math::AABB3D calcAABB() const override;
112
113 void genPosSample(
115 SampleFlow& sampleFlow,
116 HitProbe& probe) const override;
117
118 void calcPosPdf(PrimitivePosPdfQuery& query) const override;
119
120 real calcExtendedArea() const override
121 {
122 // Does not change under rigid transform
123 return m_primitive->calcExtendedArea();
124 }
125
126 const PrimitiveMetadata* getMetadata() const override
127 {
128 return m_primitive->getMetadata();
129 }
130
131private:
132 const Primitive* m_primitive;
133 const math::RigidTransform* m_localToWorld;
134 const math::RigidTransform* m_worldToLocal;
135};
136
137}// end namespace ph
Detailed information regarding a ray-primitive intersection.
Definition HitDetail.h:26
uint64 getFaceID() const
Get the face ID associated to the hit.
Definition HitDetail.h:153
math::Vector3R getUVW() const
Definition HitDetail.h:168
void setDistanceErrorFactors(real meanFactor, real maxFactor)
Definition HitDetail.h:192
std::pair< real, real > getDistanceErrorFactors() const
Definition HitDetail.h:185
real getRayT() const
Get the parametric distance from the incident ray's origin. Notice that parametric distance is not or...
Definition HitDetail.h:148
FaceTopology getFaceTopology() const
Definition HitDetail.h:158
HitDetail & setHitIntrinsics(const Primitive *primitive, const math::Vector3R &uvw, real rayT, uint64 faceID=NO_FACE_ID, FaceTopology faceTopology=FaceTopology(EFaceTopology::General))
Set essential attributes that are independent to the coordinate system.
Definition HitDetail.cpp:23
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
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.
A physical shape in the scene.
Definition Primitive.h:23
virtual real calcExtendedArea() const
Calculates the area extended by this primitive. The term "extended" implies single-sided,...
Definition Primitive.h:69
virtual const PrimitiveMetadata * getMetadata() const
Definition Primitive.h:74
bool isIntersecting(const Ray &ray, HitProbe &probe) const override=0
Determine whether a given ray hits the object.
Collection of attached components to a primitive. This type effectively "glues" various components th...
Definition PrimitiveMetadata.h:22
Information for the probability of generating a specific sample point on a primitive.
Definition PrimitivePosPdfQuery.h:91
Information for generating a sample point on a primitive.
Definition PrimitivePosSampleQuery.h:132
Represents a ray in space.
Definition Ray.h:21
A sample with arbitrary dimensions with fine-grained sampling control.
Definition SampleFlow.h:19
Applies rigid transformation to a primitive. A transformed primitive accepts only rigid transformatio...
Definition TransformedPrimitive.h:22
real calcExtendedArea() const override
Calculates the area extended by this primitive. The term "extended" implies single-sided,...
Definition TransformedPrimitive.h:120
const PrimitiveMetadata * getMetadata() const override
Definition TransformedPrimitive.h:126
bool isOccluding(const Ray &ray) const override
Determines whether this object blocks the ray.
Definition TransformedPrimitive.h:30
bool reintersect(const Ray &ray, HitProbe &probe, const Ray &srcRay, HitProbe &srcProbe) const override
Intersect the intersected object again with a different ray.
Definition TransformedPrimitive.h:52
TransformedPrimitive(const Primitive *primitive, const math::RigidTransform *localToWorld, const math::RigidTransform *worldToLocal)
Definition TransformedPrimitive.cpp:9
math::AABB3D calcAABB() const override
Calculates Axis-Aligned Bounding Box (AABB) of itself.
Definition TransformedPrimitive.cpp:34
bool isIntersecting(const Ray &ray, HitProbe &probe) const override
Determine whether a given ray hits the object.
Definition TransformedPrimitive.h:37
void calcHitDetail(const Ray &ray, HitProbe &probe, HitDetail *const out_detail) const override
Calculates properties of a hit, such as coordinates and normal.
Definition TransformedPrimitive.h:75
bool mayOverlapVolume(const math::AABB3D &aabb) const override
Conservatively checks whether this object overlaps a volume.
Definition TransformedPrimitive.cpp:25
void genPosSample(PrimitivePosSampleQuery &query, SampleFlow &sampleFlow, HitProbe &probe) const override
Generates a sample point on the surface of this primitive.
Definition TransformedPrimitive.cpp:45
void calcPosPdf(PrimitivePosPdfQuery &query) const override
Given a point on the surface of this primitive, calculates the PDF of sampling this point.
Definition TransformedPrimitive.cpp:90
Definition RigidTransform.h:14
void transform(const Ray &ray, Ray *out_ray) const
Definition Transform.cpp:50
Math functions and utilities.
Definition TransformInfo.h:10
The root for all renderer implementations.
Definition EEngineProject.h:6