Sign in to follow this  
Radiocreed

Ray fractal intersection

Recommended Posts

Generate a mesh from a particular resolution and intersect that :)

To do direct intersection you'll have to give a bit more detail on how the fractal has been defined, what equations and process are used to generate it?

Share this post


Link to post
Share on other sites
Do we have to generate it first? Don't we just trace the mountain directly, because that's what I do with other primitives unless this one works differently.

Share this post


Link to post
Share on other sites
Quote:
Original post by Radiocreed
Do we have to generate it first? Don't we just trace the mountain directly, because that's what I do with other primitives unless this one works differently.


I suppose that all depends on how you are rendering? It sounds like you are trying to raytrace a 'fractal mountain'. In order to compute the intersection, we need to know how you are generating this 'fractal mountain'. Pleaase give us more information on what you are trying to accomplish.

Share this post


Link to post
Share on other sites
Look up QAEB (quasi-analytic error bounded) tracing (published by Musgrave, I invented this independently ages ago but didn't have the coding skills to get my leet qbasic version working :P ). Example image that I made ages ago using a simple QAEB-type tracer.

Share this post


Link to post
Share on other sites
You can ray trace it directly provided that you can represent it as a mathematical function satisfying certain properties (In particular, an implicit surface with a Lipshitz bound). See "Sphere Tracing" by John Hart at http://graphics.cs.uiuc.edu/~jch/papers/. There are also a number of variants of sphere tracing that are designed specifically for terrain.

Share this post


Link to post
Share on other sites
Alternatively, if you don't have a "convenient" fractal function that can be used for analytical intersection testing, you can use simple iterative techniques. To be efficient, generate a bounding box that fully contains the fractal you want to trace. Find the entry and exit points of the ray on that bounding box, and use them as boundaries for your iterations.

The easiest solution would be to do some simple ray marching. Start with the entry point of the ray and bounding box. Iterate the fractal function at this point and see if it meets your intersection criteria (e.g. a Mandelbrot set can be rendered by iterating the function and checking the maximum distance between a given iteration and the origin point; a distance less than a certain threshold meets the intersection criteria). If the point fails, step forward a fraction of a unit along the ray and sample again. Repeat until you meet (or pass) the edge of the bounding box.

Be warned though that iterative rendering is going to be very slow, especially if you are not working in a highly optimized rendering framework. Once you get the basics working there are some tricks you can do to speed it up, but those are pretty complicated and probably aren't worth worrying about until you've got the basics nailed down.


If you're curious, here's a quick off-the-top-of-my-head idea for speeding up rendering: in a pre-rendering pass, find the exact center of the bounding box for the fractal. Divide the bounding box into four parts based on this point (split into half left/right, then split again top/bottom). Find the center of each of the four boxes; sample these center points to see if they intersect with the fractal. If so, mark the four boxes as "hit" (where appropriate); otherwise mark them as "missed." Now repeat the process recursively within each sub box. When you reach a depth of 4 or 5 iterations you should have a pretty good "grid." Take all of the boxes in the final generation that were marked as hit, and all of their neighboring boxes, and store them. Build a bounding volume hierarchy (there are plenty of well-documented techniques for doing this) that wraps those boxes. Now test your rays for intersections against the box hierarchy, and only sample the fractal at points lying inside those boxes.

On a random side note, you could probably iterate that function down 15-20 times and visualize the results for some interesting "abstract" geometry.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this