-
Notifications
You must be signed in to change notification settings - Fork 1
workaround for incorrect ray intersections with open cones #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cpp-linter Review
Used clang-format v16.0.6
Click here for the full clang-format patch
diff --git a/CSG/csg_intersect_leaf_newcone.h b/CSG/csg_intersect_leaf_newcone.h
index 740ac5a..9801725 100644
--- a/CSG/csg_intersect_leaf_newcone.h
+++ b/CSG/csg_intersect_leaf_newcone.h
@@ -101,2 +101,2 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
- const float t_cand = fminf(roots) ;
-
+ const float t_cand = fminf(roots) ;
+
@@ -104 +104 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
- float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z)*tth2));
+ float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2));
@@ -111,2 +110,0 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
-
-
Have any feedback or feature suggestions? Share it here.
d561f7b to
628d53b
Compare
628d53b to
b26739f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cpp-linter Review
Used clang-format v18.1.3
Click here for the full clang-format patch
diff --git a/CSG/csg_intersect_leaf_newcone.h b/CSG/csg_intersect_leaf_newcone.h
index 740ac5a..9801725 100644
--- a/CSG/csg_intersect_leaf_newcone.h
+++ b/CSG/csg_intersect_leaf_newcone.h
@@ -101,2 +101,2 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
- const float t_cand = fminf(roots) ;
-
+ const float t_cand = fminf(roots) ;
+
@@ -104 +104 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
- float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z)*tth2));
+ float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2));
@@ -111,2 +110,0 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
-
-
Have any feedback or feature suggestions? Share it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cpp-linter Review
Used clang-format v18.1.3
Click here for the full clang-format patch
diff --git a/CSG/csg_intersect_leaf_newcone.h b/CSG/csg_intersect_leaf_newcone.h
index 2967d49..3bc042d 100644
--- a/CSG/csg_intersect_leaf_newcone.h
+++ b/CSG/csg_intersect_leaf_newcone.h
@@ -101 +101 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
- const float t_cand = fminf(roots) ;
+ const float t_cand = fminf(roots);
@@ -111,2 +110,0 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
-
-
Have any feedback or feature suggestions? Share it here.
77c33d5 to
5cb7458
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cpp-linter Review
Used clang-format v18.1.3
Click here for the full clang-format patch
diff --git a/CSG/csg_intersect_leaf_newcone.h b/CSG/csg_intersect_leaf_newcone.h
index 2967d49..3bc042d 100644
--- a/CSG/csg_intersect_leaf_newcone.h
+++ b/CSG/csg_intersect_leaf_newcone.h
@@ -101 +101 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
- const float t_cand = fminf(roots) ;
+ const float t_cand = fminf(roots);
@@ -111,2 +110,0 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
-
-
Have any feedback or feature suggestions? Share it here.
CSG/csg_intersect_leaf_newcone.h
Outdated
| } | ||
| isect.w = t_cand ; | ||
| } | ||
| const float t_cand = fminf(roots) ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggestion
| const float t_cand = fminf(roots) ; | |
| const float t_cand = fminf(roots); |
5cb7458 to
94857f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cpp-linter Review
Used clang-format v18.1.3
Click here for the full clang-format patch
diff --git a/CSG/csg_intersect_leaf_newcone.h b/CSG/csg_intersect_leaf_newcone.h
index 2967d49..3bc042d 100644
--- a/CSG/csg_intersect_leaf_newcone.h
+++ b/CSG/csg_intersect_leaf_newcone.h
@@ -101 +101 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
- const float t_cand = fminf(roots) ;
+ const float t_cand = fminf(roots);
@@ -111,2 +110,0 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
-
-
Have any feedback or feature suggestions? Share it here.
CSG/csg_intersect_leaf_newcone.h
Outdated
| } | ||
| isect.w = t_cand ; | ||
| } | ||
| const float t_cand = fminf(roots) ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggestion
| const float t_cand = fminf(roots) ; | |
| const float t_cand = fminf(roots); |
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggestion
Please remove the line(s)
- 111
- 112
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request attempts to fix incorrect ray intersections with open cones by simplifying the intersection logic. However, the implementation introduces several critical bugs that will cause incorrect rendering behavior.
Key changes:
- Removed validation logic that checks if
t_candrepresents a valid intersection - Eliminated cap-specific normal calculations (normals for end cap intersections)
- Simplified to always compute cone surface normals regardless of intersection type
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CSG/csg_intersect_leaf_newcone.h
Outdated
| float3 intersection_point = make_float3(o.x + t_cand * d.x, o.y + t_cand * d.y, o.z + t_cand * d.z); | ||
| float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2)); | ||
|
|
||
| isect.x = n.x; | ||
| isect.y = n.y; | ||
| isect.z = n.z; | ||
| isect.w = t_cand; |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The valid_isect output parameter is never set, which will cause incorrect behavior in calling code. All other intersection functions (e.g., intersect_leaf_sphere, intersect_leaf_cylinder) validate t_cand and set valid_isect = t_cand > t_min && t_cand < RT_DEFAULT_MAX before populating the intersection result. Without this check, invalid intersections (when all roots are disqualified and t_cand == RT_DEFAULT_MAX) will be processed as valid.
| float3 intersection_point = make_float3(o.x + t_cand * d.x, o.y + t_cand * d.y, o.z + t_cand * d.z); | |
| float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2)); | |
| isect.x = n.x; | |
| isect.y = n.y; | |
| isect.z = n.z; | |
| isect.w = t_cand; | |
| valid_isect = t_cand > t_min && t_cand < RT_DEFAULT_MAX ; | |
| if (valid_isect) | |
| { | |
| float3 intersection_point = make_float3(o.x + t_cand * d.x, o.y + t_cand * d.y, o.z + t_cand * d.z); | |
| float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2)); | |
| isect.x = n.x; | |
| isect.y = n.y; | |
| isect.z = n.z; | |
| isect.w = t_cand; | |
| } | |
| else | |
| { | |
| isect = make_float4(0.f, 0.f, 0.f, RT_DEFAULT_MAX); | |
| } |
CSG/csg_intersect_leaf_newcone.h
Outdated
| float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2)); | ||
|
|
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The normal calculation always uses the cone surface formula, even when the intersection is with a cap (t_cand == t_cap1 or t_cap2). The removed code correctly handled cap normals as (0, 0, ±1), which point along the z-axis. Using the cone surface normal formula for cap intersections will produce incorrect normals. Cap intersections should be detected and handled separately, as done in the original code and in intersect_leaf_cylinder (line 79).
| float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2)); | |
| float3 n; | |
| if (t_cand == t_cap1) { | |
| n = make_float3(0.f, 0.f, -1.f); // lower cap normal | |
| } else if (t_cand == t_cap2) { | |
| n = make_float3(0.f, 0.f, 1.f); // upper cap normal | |
| } else { | |
| n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2)); | |
| } |
CSG/csg_intersect_leaf_newcone.h
Outdated
| float3 intersection_point = make_float3(o.x + t_cand * d.x, o.y + t_cand * d.y, o.z + t_cand * d.z); | ||
| float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2)); | ||
|
|
||
| isect.x = n.x; | ||
| isect.y = n.y; | ||
| isect.z = n.z; | ||
| isect.w = t_cand; |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When t_cand == RT_DEFAULT_MAX (no valid intersection found), the normal calculation can produce undefined results. Specifically, if the intersection point computed with RT_DEFAULT_MAX happens to be at or near the cone apex (where x=0, y=0, z=z0), the vector passed to normalize() will be zero or near-zero, causing normalization of a zero-length vector. The computation should only proceed if t_cand represents a valid intersection (i.e., t_cand < RT_DEFAULT_MAX).
| float3 intersection_point = make_float3(o.x + t_cand * d.x, o.y + t_cand * d.y, o.z + t_cand * d.z); | |
| float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2)); | |
| isect.x = n.x; | |
| isect.y = n.y; | |
| isect.z = n.z; | |
| isect.w = t_cand; | |
| if (t_cand < RT_DEFAULT_MAX) | |
| { | |
| float3 intersection_point = make_float3(o.x + t_cand * d.x, o.y + t_cand * d.y, o.z + t_cand * d.z); | |
| float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2)); | |
| isect.x = n.x; | |
| isect.y = n.y; | |
| isect.z = n.z; | |
| isect.w = t_cand; | |
| valid_isect = true; | |
| } | |
| else | |
| { | |
| isect.x = 0.f; | |
| isect.y = 0.f; | |
| isect.z = 0.f; | |
| isect.w = RT_DEFAULT_MAX; | |
| valid_isect = false; | |
| } |
|
@ggalgoczi Are you going to run this workaround by Simon? |
|
Will ask him about it later on, after finished with the photon leakage. However this is a special case of a cone in question here. I think for now we should not merge since it opens up even closed cones. |
94857f9 to
1ec9ad7
Compare
Cpp-Linter Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cpp-linter Review
Used clang-format v18.1.3
Click here for the full clang-format patch
diff --git a/CSG/csg_intersect_leaf_newcone.h b/CSG/csg_intersect_leaf_newcone.h
index 371c713..a4e7aa3 100644
--- a/CSG/csg_intersect_leaf_newcone.h
+++ b/CSG/csg_intersect_leaf_newcone.h
@@ -101,2 +101,2 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
- const float t_cand = fminf(roots) ;
-
+ const float t_cand = fminf(roots) ;
+
@@ -107 +107,2 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c
- float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z)*tth2));
+ float3 n =
+ normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2));
Have any feedback or feature suggestions? Share it here.
| const float t_cand = fminf(roots) ; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggestion
| const float t_cand = fminf(roots) ; | |
| const float t_cand = fminf(roots) ; | |
| } | ||
| isect.w = t_cand ; | ||
| float3 intersection_point = make_float3(o.x + t_cand * d.x, o.y + t_cand * d.y, o.z + t_cand * d.z); | ||
| float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z)*tth2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format suggestion
| float3 n = normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z)*tth2)); | |
| float3 n = | |
| normalize(make_float3(intersection_point.x, intersection_point.y, (z0 - intersection_point.z) * tth2)); |
No description provided.