Skip to content

Conversation

@juliohm
Copy link
Member

@juliohm juliohm commented Jul 10, 2025

I refactored the code to follow the exact same steps of the non-culling branch described in the Möller, T. & Trumbore, B. 1997 paper. I understand that this branch will compute the correct intersection even when triangles are back-faces.

The new implementation avoids unnecessary intermediate computations like the variable T that is only computed after the determinant check. It also follows the notation of the paper more closely to facilitate future maintenance.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 10, 2025

Benchmark Results (Julia vlts)

Time benchmarks
master 2d78249... master / 2d78249...
clipping/SutherlandHodgman 3.92 ± 1.6 μs 3.69 ± 0.16 μs 1.06 ± 0.44
discretization/simplexify 27.5 ± 2.2 ms 25.9 ± 1.9 ms 1.06 ± 0.12
intersection/ray-triangle 0.06 ± 0 μs 0.05 ± 0.001 μs 1.2 ± 0.024
sideof/ring/large 6.53 ± 0.01 μs 6.53 ± 0.01 μs 1 ± 0.0022
sideof/ring/small 0.05 ± 0.001 μs 0.05 ± 0.01 μs 1 ± 0.2
winding/mesh 0.0427 ± 0.0021 s 0.0421 ± 0.002 s 1.01 ± 0.07
time_to_load 1.52 ± 0.013 s 1.48 ± 0.033 s 1.02 ± 0.024
Memory benchmarks
master 2d78249... master / 2d78249...
clipping/SutherlandHodgman 0.053 k allocs: 4.97 kB 0.053 k allocs: 4.97 kB 1
discretization/simplexify 0.226 M allocs: 21.8 MB 0.226 M allocs: 21.8 MB 1
intersection/ray-triangle 0 allocs: 0 B 0 allocs: 0 B
sideof/ring/large 0 allocs: 0 B 0 allocs: 0 B
sideof/ring/small 0 allocs: 0 B 0 allocs: 0 B
winding/mesh 0.231 M allocs: 23 MB 0.231 M allocs: 23 MB 1
time_to_load 0.153 k allocs: 14.5 kB 0.153 k allocs: 14.5 kB 1

@github-actions
Copy link
Contributor

github-actions bot commented Jul 10, 2025

Benchmark Results (Julia v1)

Time benchmarks
master 2d78249... master / 2d78249...
clipping/SutherlandHodgman 3.45 ± 0.28 μs 3.44 ± 0.26 μs 1 ± 0.11
discretization/simplexify 25.9 ± 4 ms 25.5 ± 4.2 ms 1.02 ± 0.23
intersection/ray-triangle 0.07 ± 0.001 μs 0.06 ± 0.01 μs 1.17 ± 0.2
sideof/ring/large 6.85 ± 0.071 μs 6.78 ± 0.021 μs 1.01 ± 0.011
sideof/ring/small 0.06 ± 0 μs 0.06 ± 0.009 μs 1 ± 0.15
winding/mesh 0.044 ± 0.0034 s 0.0435 ± 0.0033 s 1.01 ± 0.11
time_to_load 1.63 ± 0.012 s 1.63 ± 0.0093 s 1 ± 0.0094
Memory benchmarks
master 2d78249... master / 2d78249...
clipping/SutherlandHodgman 0.053 k allocs: 4.83 kB 0.053 k allocs: 4.83 kB 1
discretization/simplexify 0.324 M allocs: 21.8 MB 0.324 M allocs: 21.8 MB 1
intersection/ray-triangle 0 allocs: 0 B 0 allocs: 0 B
sideof/ring/large 0 allocs: 0 B 0 allocs: 0 B
sideof/ring/small 0 allocs: 0 B 0 allocs: 0 B
winding/mesh 0.329 M allocs: 22.9 MB 0.329 M allocs: 22.9 MB 1
time_to_load 0.159 k allocs: 11.2 kB 0.159 k allocs: 11.2 kB 1

@codecov
Copy link

codecov bot commented Jul 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.93%. Comparing base (04d0330) to head (2d78249).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1229      +/-   ##
==========================================
- Coverage   87.94%   87.93%   -0.01%     
==========================================
  Files         196      196              
  Lines        6222     6218       -4     
==========================================
- Hits         5472     5468       -4     
  Misses        750      750              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@juliohm
Copy link
Member Author

juliohm commented Jul 10, 2025

@halleysfifthinc given that you touched this code recently to improve type stability, I appreciate if you could take a look to make sure we are not missing something. Please let me know if you are busy and I can try to ping other contributors for review 🙂

Copy link
Contributor

Copilot AI left a 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 PR refactors the ray–triangle intersection implementation to match the non-culling branch of the Möller–Trumbore (1997) algorithm, removing intermediate computations and aligning notation with the paper.

  • Rewrote intersection to use the paper’s step-by-step notation
  • Removed the T intermediate until after determinant inversion
  • Updated test comment for clarity

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
test/intersections.jl Fixed grammar in a test comment
src/intersections/rays.jl Refactored triangle intersection to follow Möller–Trumbore non-culling algorithm

Copy link
Contributor

@halleysfifthinc halleysfifthinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@halleysfifthinc
Copy link
Contributor

Is this intersection benchmarked by CI yet? Probably a good idea to add now given that the intent of this PR is at least partially to improve performance, afaict?

@juliohm
Copy link
Member Author

juliohm commented Jul 10, 2025

Is this intersection benchmarked by CI yet? Probably a good idea to add now given that the intent of this PR is at least partially to improve performance, afaict?

That is a good idea. I will add a benchmark to make sure we don't introduce regressions.

@juliohm
Copy link
Member Author

juliohm commented Jul 10, 2025

Benchmarks show great speedups when the ray and the triangle do not intersect. Given that this is the most likely configuration, this can make a real difference in practice.

@juliohm juliohm merged commit f10a253 into master Jul 10, 2025
18 checks passed
@juliohm juliohm deleted the ray-triangle-intersection branch July 10, 2025 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants