Kore Nordmann - PHP / Projects / Politics ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Author: Kore Nordmann :Date: Fri, 27 Jul 2007 20:26:41 +0200 :Revision: 6 :Copyright: CC by-sa ======================== Raytracing with Image_3D ======================== :Description: The last two days I tested how fast raytracing would be, and which nice effects could be done with this algorithms. 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. .. image:: image_3d_raytrace.png :alt: Raytraced 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. __ http://en.wikipedia.org/wiki/Ray_tracing __ http://de.wikipedia.org/wiki/Raytracing __ http://pear.php.net/package/Image_3D 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. __ http://schlitt.info/applications/blog/index.php?/archives/436-More-3D-fun-with-PHP.html 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. __ http://cvs.php.net/viewcvs.cgi/pear/Image_3D/ __ http://kore-nordmann.de/home/3d_library_for_php/todo_list Trackbacks ========== Comments ======== - Toby at Wed, 05 Apr 2006 00:10:00 +0200 Agreed, you are totally mad... But thats what we love about you! :) - Sune at Wed, 05 Apr 2006 09:48:00 +0200 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 Wed, 05 Apr 2006 10:22:00 +0200 What's next? - rod at Wed, 05 Dec 2007 01:26:12 +0100 Very g()0d!!! - John at Wed, 20 Aug 2008 22:00:46 +0200 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?