The Pure Perl RayCaster

Index

F.A.Q.

Why Pure?

Pure because there are no third party 3D libraries / APIs in use or any kind of hardware accelaration (OpenGL, DirectX etc.). Buiding the wireframe and ray casted images is being done "from scratch" using a white empty canvas and the functions DrawPoint() and DrawLine() for painting pixels (ray casting) and lines (wireframe drawing). Furthermore, there are no third party Perl Modules related to mathematical calculations in use (eg. for matrices operations).


Why Perl?

Why not? Quoting Larry Wall from the 'Camel Book': "Perl is designed to make the easy jobs easy, without making the hard jobs impossible." Perl can do it, so here it is. This is not by any means a professional or production ready tool for 3D rendering or ray tracing. It is an application (a learning tool) for all those who want to study fundamental techniques on how things are done in 3D CG (Computer Graphics) and want to experiment techniques in a scripting language. If you are looking for a fast full featured ray tracer this is not the case for sure.


I have heard about ray tracing, but what is ray casting?

Ray casting is a special case of ray tracing. It is ray tracing, but without (the important) recursion. Ok, in ray tracing a ray that starts from the point of observation travels a scene until it hits a surface. If it does hit a surface, we assume a new ray, starting from that intersection (hit) point (this is recursion). In ray tracing, this procedure continues recursively until we get a ray that travels directly to a light source. In ray casting you don't do the recursion; rays start from your camera and in case they hit an object you get the color of the intersection point, in case of no intersection you get your scene's background color.


Where can I run this, is it portable?

Yes. WxWindows is a nice framework to create GUIs for your applications and have them run in different operating systems while using the native OS GUI Widgets without you having to do something special about it as a developer. Perl is one of the most portable programming languages today. Pure Perl RayCaster has been tested on Linux and Win32. If you run it without problems in a different OS, please send me an email to add it here.


It is SLOW!

Of course it is! Compared to a ray tracer written in C/C++ or in any other language with a compiler? Perl compiles the source to an intermediate format (bytecodes) and passes the bytecodes to an interpreter. Of course you can not expect (in the general case) any language using an interpreter to be as fast as compiled languages (though in some specific applications it might be just as fast nowadays). This is true for most "number crunching" applications in tight loops as any ray tracer is. Perl Pure RayCaster is being written without speed being the first priority. It would be meaningless to go for speed. Specific aproaches related to the problem, reductions and optimizations have also being avoided.
As said before, for someone who wants to perform state of the art and/or professional ray tracing on 3D scenes, Pure Perl Raycaster is a toy. Go and get a decent ray tracer (you can find Open Source Ray Tracers that do excelent job). Pure Perl RayCaster is an application available for anyone who wants to study basic important techniques in ray tracing and in 3D CG today. It is suitable for people who like Perl and want to understand how to create 3D images (wireframe or photorealistic) starting from a bunch of sparse points in 3D space (x,y,z triads) and who want to be able to easily tweak some lines of code in order to learn by trying things.


But, wait, I have the best video adapter on the planet!

This has nothing to do with this software and maybe you have not understood why even "Pure Perl RayCaster" exists. Even if you have the most top of the notch expensive Video Card in your computer (with the best and latest accelerations for OpenGL and special water cooling systems to make sure it will not explode!), it is completely irrelevant with how fast this software will perform. This is a simplified software (Perl) implementation of some methods that are implemented inside your video card's hardware. In Pure Perl RayCaster all calculations go through your CPU and therefore only faster CPU will make a difference.


How slow is it, can you give me some numbers/timings?

No. If you are that curious, download and try it.


What about optimizations?

Are you sure you've read the 3 previous questions?


What 3D CG techniques will I find implemented in Pure Perl RayCaster?

Everything from reading point triads from the RAW file to produce the final image: objects / data structures to use, change of coordinate systems (Object, Camera, Screen), projections, perspective transformations, scale, rotate and translation, back face culling, near and far plane clipping, productions of rays from screen to world for ray tracing, ray to triangle intersections, ray casting main algorithm, Phong shading, color table to map intensity to colors and other that might seem unimportant now but may be helpful for you in the process, but most important all the details of all the above, since you have something to tweak and play with while learning (if you can handle Perl of course).


Where can I find more objects?

On the internet, on CDs with objects or create your own by using some other program. You can convert to RAW format, from external applications too. You can find some free here: http://pdelagrange.free.fr/povlab/store.html. If you have something cool and free (objects or screenshots) and would like to share it you can contact me.
Beware that the more the polygons in your mesh, the slower the raycasting and the wireframe view will be. Running a teapot with more than 2000 polygons might be very slow on your PC.


How can I change options like the lights of the scene, use new colors, camera position etc.?

Right now in the command line arguments you can specify a predefined color to use, smooth shading, the ray casting window width and the file (RAW format) to read from. Look on the Installation and Usage page for some examples. To tweak other things like the camera options (Camera Position, lookAt vector, back and near clipping plane, frame window size etc.), colors for the ray casting output, light sources etc. you have to tweak the Pure Perl RayCaster Source Code. After all Pure Perl RayCaster is available for educational purposes and you are encouraged to do this! You can have a look on the API page for information about the classes in use.


In order to add or change light sources of your scene you can tweak the Object3D::initObjectScene() method (initObjectScene sub on Object3D.pm). Light sources are added there to an array ref. holding all object's lights. Each light source can be identified as lines of code like:
		push @{ $self->{lights} }, new Vertex( 210, -700, 800 );
	
This line adds a new light source at (210,-700,800) world coordinates to your scene. You can have as many lights you wish anywhere you want as long as you put more lines like the above in Object3D::initObjectScene(). Beware, the more the light sources in your scene, the slower the ray casting will be of course.

Camera options like near clipping plane, frame width etc. can be found at the constructor of the Camera - Camera::new(). Feel free to change them to see their use.

Will it be a next version?

For the time being no new version is planned. Since no extensive testing has been done I will fix bugs that may arise (can not promise when), but except that there is no new version planned. If you find any bugs, please send me some details at the email address found at the home page.
Of course, if you want, you can make Pure Perl Raycaster better and your work can be its next version (look at the next question, too).


Can I add new features on Pure Perl RayCaster or make any kind of enhancements or fixes?

Of course. This is open source software. It would be nice to hear from you. If you create something worth to include you could become a PPRC developer and we can create a new release with the new features. Here is a list of some nice things that can be done (some of them quite easily). Of course there are more nice ideas, you might come up:


Can I use Code / Classes of the Pure Perl RayCaster to create something new, and if yes, how?

You can use existing code for almost any purpose you want. Pure Perl RayCaster is free / open source software released under the Artistic License. Take a look at the LICENSE.txt in the source distribution for more information. If you do use it to create something nice, I would like to know it.
The best way to learn something in programming is to do it. Of course you are encouraged to use the existing code to study techniques on 3D Computer Graphics either by studying the existing code, or by trying new things. Take a look at the API link for more info.
Keep in mind that no extensive tests of any kind of the software have been performed. And it is not supported (at least by any official means).


Can you give some info about the source and Classes in use?

Look at the API page.


How did Pure Perl RayCaster start?

Pure Perl RayCaster started as an assignment for the postgraduate class "Graphics, Visualization, Fractals" while attending the MSc program "Advanced Information Systems" of the Department of Informatics of the University of Athens some years ago. The assignment was completed, but I thought why not making this public available? Having being busy for a long time I didn't do anything about it, until the first days of 2006 while I've managed to release PPRC. I decided to add some features, do some tests and fixes and set up a web page for it. So, here is it.


How can I contact you about Pure Perl Renderer?

Send mail to the email address found at the home page of this site.



Valid XHTML 1.0 Transitional