Jump to content
• Advertisement

# Cylinder Raytracing

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I've been working through the math for raytracing a cylinder and I've come up with 2 options and need to know which is best. I've got one method where to find the determinant (before the sqrt) I've only done 9 multiplies and 2 adds. However for the full calclation it needs 16 multiplications, 5 adds, 1 division, and 1 sqrt. The other method has 11 multiplications and 4 adds before the determinant, but in total it has 12 multiplications, 5 adds, 1 division, and 1 sqrt. So which is best? Faster early exit or faster overall?

#### Share this post

##### Share on other sites
Advertisement
In a brute-force renderer where you check all scene objects for a given ray for intersection, the early-exit version would be the one to prefer, because most of the time there wouldn't be an intersection anyway.

But as you're obviously caring for performance you're most likely using some sort of spatial subdivision to speed up the raytracing process. In this case I'd vote for the second method because after scene graph traversal the probability that the cylinder in question is hit by the ray is high.

#### Share this post

##### Share on other sites
Makes sense, and in fact I'm using adaptive-depth octrees, so second method it is. Thanks for the info.

#### Share this post

##### Share on other sites
It depends on several things. If you're using SSE the div/sqrt combined will cost just as much as a multiply (because rsqrt is just an approximation accurate to 12-bits), if you're not then the div/sqrt will cost more than twice as much as all the other ops combined.

A mis-predicted branch is also very expensive, but not as bad as div or sqrt. So if you can branch to avoid a div and sqrt, it is definitely worth it with non-SSE. With SSE, it is likely that the non-branching version is faster.

When raytracing, spatial subdivision is important because it's like trivially rejecting half your primitives with one tree traversal step (which is generally faster than the ray/prim test). So, everything in perspective, spatial subdiv algo (k-d tree) is more important than speeding up ray/prim test.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
• Advertisement

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633271
• Total Posts
3011161
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!