Sign in to follow this  
RubyNL

Realtime raytracing with fixed point math

Recommended Posts

Hello I'm trying to do fixed point math. Can you help me a bit, I'm not that good at fixed point math. I can use it but not with fractals and raytracing. Does anyone have experience with it? I'm using QBASIC. And only software rendering. (that may sound fool to you :P). Anyway, I use 16-bit integers, but I keep on having overflow errors. Hope you can help me.

Share this post


Link to post
Share on other sites
Uh, that's not much of a question. Fixed-point is constant juggling of precision, there are no easy ways around it.

I remember floating point in QBasic being ridiculously slow on my 386, but that machine lacked floating point hardware. Surely there's some version of QBasic, or PowerBasic or whatever, you can use which handles it decently?

Also, DEFINT A-Z FTW! (man, I thought I had buried those BASIC memories long ago)

Share this post


Link to post
Share on other sites
With only 16 bits of precisions it's clear that you would get overflow problems. Use a 32 bit integer instead. A 32 bit integer is the processors native data type and thus it will also be faster with 32 bit ints versus 16 bit ints.
Also, for ray tracing I would never use fixed point math. It's to troublesome because of the precision problems and using floating point is most likely faster anyway. And without SSE and other optimizations you will never get to realtime raytracing.

Share this post


Link to post
Share on other sites
Quote:
Original post by Trenki
With only 16 bits of precisions it's clear that you would get overflow problems. Use a 32 bit integer instead. A 32 bit integer is the processors native data type and thus it will also be faster with 32 bit ints versus 16 bit ints.
Not in a 16-bit QBASIC environment it won't be. Of course you'll still need the occasional long integer but if speed is an issue (obviously, otherwise he wouldn't be using fixed-point) then keep to 16-bit precision. Of course switching to a modern version of PowerBasic, or FreeBasic or even VB.NET would give you far better performance on modern systems anyway.

Share this post


Link to post
Share on other sites
Thanks for the reactions. I found some Qbasic source that does realtime raytracing at 10 fps. I read somewhere (the source?) that the C++ version is 4 times faster. I found the source and .EXE on Antoni Gual's Qbasic site(it's made by Texel):
http://www.geocities.com/antonigual/qbasic.html
Here is the file:
http://www.geocities.com/antonigual/qbsource/texelrtr.zip

I hope this can help you like it did to me. What a poetrical text XD.

Share this post


Link to post
Share on other sites
Back in the DOS days, I used fixed point math to speed up graphics calculations. It's not hard to do. Let's say you are storing positions in meters. Just make one meter equal to 32768 (negative one meter would be -32768) and store the values in a 32-bit integer (LONG type in QBasic). This would give you a range of -32768 to 32767 meters with an accuracy of 1/32768 of a meter. The only caveat is that you may have to convert fixed-point values to integer values, in which case you would simply use QBasic's SHR command to shift the result 15 bits. With QBasic, however, you're still going to run into overflow problems because it only supports a maximum of 32-bit integers (16-bit based).
Quote:
Original post by implicit
Of course switching to a modern version of PowerBasic, or FreeBasic or even VB.NET would give you far better performance on modern systems anyway.
I recommend that the OP follow this advice. I used QBasic years ago for prototyping and recently discovered FreeBasic. It's easy to install, easy to use, fast (compiled), supports up to 64-bit values, almost 100% compatible with QuickBasic code, adds many features that QuickBasic was sorely lacking (including pointers) and allows you to link in to many third-party libraries such as Ogre3D, ODE, etc.

QBasic may still be good for getting an idea up and running quickly but it's very outdated. For what you're trying to accomplish, QBasic is seriously underpowered and may not even be able to handle it (reliably, at least). Either stick to floating point operations or upgrade to FreeBasic or any of the other versions of Basic mentioned (in which case, there would be no need to use fixed-point anyway).

FreeBasic - You can get FBIDE as a seperate download from the same site.

Share this post


Link to post
Share on other sites
I already have Freebasic, but I like Qbasic much more. Just because I'm used to it. I try to optimize my programs in qbasic so that I can still make fast running demo effects (oldskool: rotozoomer, water, fire, plasma of course and in the future some 3d stuff).
Also I don't like the fact that you can't run from interpreter in FB(probably because FB is a compiler :P). I know FBIde too. Much programs work in the IDE, while they don't (or give an error) when I compile it from the IDE. Thanks for the help BTW. I will send some qbasic source when I finished my program. I think I will try a animating Julia fractal first. Of course in fixed point math and with some other hacks.

Share this post


Link to post
Share on other sites
Yeah it's not that hard to do. Just draw a 3d cube and do a fire filter on it. Easy. It looks better if you distortion filter on it. :P. I prefer better effects, though. You can do some pretty cool effects in qbasic. You know, mandelbrot zoomer, but I like especially rotozoomers and then I focus on rotozoomers that rotozoom a bumpmapped image, plasma or water. Can be easily done if you make a tiling picture. Also, with (fake) translucency you can do quite nice things.

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