No need to cache direction
This commit is contained in:
parent
3ee3931824
commit
3606ab9b93
@ -227,7 +227,8 @@ void compute_normalmap(Span<const transvoxel::CellInfo> cell_infos, const transv
|
||||
const float NO_HIT = 999999.f;
|
||||
float nearest_hit_distance = NO_HIT;
|
||||
for (unsigned int ti = 0; ti < triangle_count; ++ti) {
|
||||
const math::TriangleIntersectionResult result = baked_triangles[ti].intersect(ray_origin_mesh);
|
||||
const math::TriangleIntersectionResult result =
|
||||
baked_triangles[ti].intersect(ray_origin_mesh, direction);
|
||||
if (result.case_id == math::TriangleIntersectionResult::INTERSECTION &&
|
||||
result.distance < nearest_hit_distance) {
|
||||
nearest_hit_distance = result.distance;
|
||||
|
@ -79,7 +79,6 @@ inline TriangleIntersectionResult ray_intersects_triangle(const Vector3f &p_from
|
||||
|
||||
// If you need to do a lot of raycasts on a triangle using the same direction every time
|
||||
struct BakedIntersectionTriangleForFixedDirection {
|
||||
Vector3f dir;
|
||||
Vector3f v0;
|
||||
Vector3f e1;
|
||||
Vector3f e2;
|
||||
@ -87,12 +86,11 @@ struct BakedIntersectionTriangleForFixedDirection {
|
||||
float f;
|
||||
|
||||
bool bake(Vector3f p_v0, Vector3f p_v1, Vector3f p_v2, Vector3f p_dir) {
|
||||
dir = p_dir;
|
||||
v0 = p_v0;
|
||||
|
||||
e1 = p_v1 - v0;
|
||||
e2 = p_v2 - v0;
|
||||
h = math::cross(dir, e2);
|
||||
h = math::cross(p_dir, e2);
|
||||
const float a = math::dot(e1, h);
|
||||
if (Math::abs(a) < 0.00001f) {
|
||||
// Parallel, will never hit
|
||||
@ -102,7 +100,7 @@ struct BakedIntersectionTriangleForFixedDirection {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline TriangleIntersectionResult intersect(const Vector3f &p_from) {
|
||||
inline TriangleIntersectionResult intersect(const Vector3f &p_from, const Vector3f &p_dir) {
|
||||
const Vector3f s = p_from - v0;
|
||||
const float u = f * math::dot(s, h);
|
||||
|
||||
@ -112,7 +110,7 @@ struct BakedIntersectionTriangleForFixedDirection {
|
||||
|
||||
const Vector3f q = math::cross(s, e1);
|
||||
|
||||
const float v = f * math::dot(dir, q);
|
||||
const float v = f * math::dot(p_dir, q);
|
||||
|
||||
if ((v < 0.0f) || (u + v > 1.0f)) {
|
||||
return { TriangleIntersectionResult::NO_INTERSECTION, -1 };
|
||||
|
Loading…
x
Reference in New Issue
Block a user