Raytracing with Image_3D

First published at Tuesday, 4 April 2006

Warning: This blog post is more then 16 years old – read and use with care.

Raytracing with Image_3D

I wasn't sure to blog about this, because you must think I am totally wacky now. But, on the other hand, you surely already think this, so that this won't cause any changes.

Raytraced image with Image_3DRaytraced image with Image_3D

I was always writing, that implementing a raytracer (or the better german description ) in PHP would be far to slow. And then, two days ago, I had the feeling I should prove this ... this was also the way Image_3D was born. With the infrastructure Image_3D offers, all the existing models, the abstraction etc. it wasn't such a big thing. You mainly need to write a short algorithm which gets the intersection point for a polygon with a line, and that's it. For sure, you should optimze the algorithm a bit. :-) And it is really fun to implement such a simple mathematical model like raytracing is.

Some features, hard to implement with the normal renderers, are no problem with raytracing, like:

  • shadows

  • colored shadows

  • reflections

  • anti aliasing

  • phong shading

But I have to admit, the image took about 7 minutes to render with the raytracer on my machine. Let's see this as a prove for PHP beeing to slow for a raytracer. ;-) If you are google and have thousands of computers, you can perhaps even use PHP for raytracing ... but as always, there is really no valid reason to use PHP for generation of any 3d graphics, respectively I don't know any.

One good thing about implementing the raytracer was, that I discovered several minor bugs in Image_3D - mainly an error in the enlightenment code, so that the colors shouldn't look so pale any more. While fixing, some funny errors occured, like this one toby metioned yesterday.

As always this code is in CVS and will be in version 0.5 - but there is still quite a long way to go before Image_3D can be beta.

Comments

Toby at Tuesday, 4.4. 2006

Agreed, you are totally mad... But thats what we love about you! :)

Sune at Wednesday, 5.4. 2006

7 minutes you say. maybe an online 3d game written in php with raytracing and shadows is a bad idea.

Nice made anyway, it just again shows how cool PHP is

Sebastian at Wednesday, 5.4. 2006

What's next?

rod at Wednesday, 5.12. 2007

Very g()0d!!!

John at Wednesday, 20.8. 2008

Actually I have a need for a PHP raytracer. I would like to add products to an e-commerce site which were designed with cad and output an stl file. I would like to just upload this file to my site and have it generate the renderings and save them with a naming convention and hook them in tp the web site automatically. I could do that with the command line version of pov-ray, and it would be a lot faster, but I don't have hosting where I have command line access to compile programs and such. But I can upload php files. It's not something that would happen all the time so it would be no big deal for it to be slow. Does that make sense or perhaps I am missing an obvious point?