Is ray tracing hard or is it just me?

Started by
11 comments, last by BadEggGames 8 years, 7 months ago

Hi all

I have the humble goal of writing the most simple ray tracer possible.

No shadows or specularity, just primary rays that intersect a single sphere so I end up with a 2d circle on a plain background.

The ray tracing algorithm is simple and easy to understand, but every time I look at some code or read whatever snippet on the web I can find, I just get lost.

What are the odds of a decent programmer figuring this out without a math degree?

Does anyone know of a simple code example or an easy to follow tutorial?

I think most just assume a great deal of prerequisite knowledge and am not sure where to start.

Any info getting this done would be greatly appreciated.

Thanks

Advertisement

I'm not a graphics programmer, but in listening to people who do this often, raytracing is like pimpin'. It ain't easy. Also, based on what they say, if you know the maths, it should be most of the battle.

I'm shocked though that google hasn't led to you a solution though.

------

This is the first link I found. Seems to have everything you want.

Google search.

Beginner in Game Development?  Read here. And read here.

 

Thanks Alpha

Yes, I assure you I have read all that, cant say I understood it all :P

I think the raytracing is the easy part, obviously struggling with the math.

Most of these sites explain raytracing down to a T but gloss over sphere ray intersections etc.

"Somebody was able to put a raytracer on a business card, so it can't be all that hard", says the guy who's never written a raytracer. ;)

Raytracing is dead simple. Efficient raytracing is not.

I think it's appropriate here to link to Bacterius' journal: http://www.gamedev.net/blog/2031-ray-tracing-devlog/. I think he does a good job at thoroughly explaining the process of writing a raytracer.

Maybe start with a box? Ray intersection with a box is simpler than with a sphere, I think.

A sphere is nearly the simplest thing you can imagine, its just a point with a radius attached. A box got 8 points. Thats probably why many pictures from people starting to write a raytracer show spheres.

Just take the point of the viewer, calculate a vector to one of the points on the view rectangle (thats the ray), then calculate the smallest distance of the spheres midpoint to the line, then check if its smaller than the radius and not the wrong half of the line. If it hit the sphere, set the point to the spheres color, otherwise the background color. Repeat for all points. Most basic raytracer is done.

Refine with handling more than a single sphere, lighting, secondary or shadow rays, if you like to.

IMHO stick to Pythagoras and avoid trigonometric functions. This is like 10th grade school math? Some people even associated pixel coordinates with angels :-(
With regard to ray sphere intersection I cannot help, but think of inner products, which are more 12th grade, aren't they?


IMHO stick to Pythagoras and avoid trigonometric functions. This is like 10th grade school math? Some people even associated pixel coordinates with angels :-(

I know that DirectX vs OpenGL is the equivalent of a religious war. But I didn't know pixel coordinates had become so sectarian themselves.

Beginner in Game Development?  Read here. And read here.

 

This topic is closed to new replies.

Advertisement