English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 10 February 2018, 18:06   #1
Master484
Registered User
Master484's Avatar
 
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 330
Blitz Raycaster Demo




This is a small Blitz raycaster demo that I made to test if Blitz could handle raycasting.

The ADF is in the attachment of this post, and Blitz source code is included in the disk, you can freely use it in your own projects.

System requirements : A1200

Controls: Joystick moves and following keys change stuff:

1 - Draw lines (simple walls without textures)
2 - Draw textures
3 - Draw textures to upper screen part only and mirror the bottom half. (this is the default mode when program starts)
H - Increase screen size
J - Decrease screen size

---

On a basic A1200 setup without any fast RAM and emulator Cycle Exact ON, I got the following results on the biggest 320*200 resolution:

(These figures are updated when new program versions are made. Right now newest version is V524)

Line mode : stable 17 FPS
Texture mode : between 5-10 FPS
Mirrored texture mode : 7-12 FPS

And on the smallest resolution of 160*200 speed is:

Line mode: stable 25 FPS
Texture mode: 8-17 FPS
Mirrored texture mode: 12-17 FPS

---

Wall drawing is fast, because they're drawn in segments of 4 or 5 pixel wide columns using the "BoxF" and "Scroll" commands. Only about 60 drawing operations are needed to create each frame.

Theoretically we would need cast 320 rays and draw 320 columns to create an accurate 3D view, but I decided to use only 60 rays. So 80 % of the rays are simply skipped. This works because 60 rays is enough to create a believable field of vision of 60 degrees.

The only downside of this trick is that horizontal drawing accuracy is reduced in the edges of the walls; this is why the walls have that "big blocks" look when you view them from certain angles.

The raycaster is custom made by me, and it mostly operates on integers, and mostly uses only adds and subtracts to count stuff. Also look-up tables are used a lot, and the code has been optimized for speed. In fact this is the first program where I have managed to improve speed by several frames by just making the code faster.

Also the textures are not "real", which means that there is no scaling of image data or anything like that...it just copies image areas from a pre-made, pre-randomized and pre-shaded bitmap. But still, it's enough to create the illusion that we have a full screen game with 1*1 pixel textures running at a playable speed.

But if this was an actual game, then all walls would need to be made from random pixel mess like that, because this system doesn't support actual textures. Any real texture scaling would require lots of pixel manipulation, and Blitz doesnt have any good commands for that sort of stuff (except Plot, but it's extremely slow) .

And also, this is actually a 8+8 dual playfield, on AGA. Again, this was done for speed, although I think it could handle 16+16 as well. The 3D view is drawn to the back playfield and the front playfield is reserved for possible enemies and stuff like that.

---

Also this is not an actual game project, it's just a Blitz raycaster engine demonstration. But as mentioned the code is open source, so if anyone wishes to use it in a game, they're free to do so.

Also note that before I compiled the executable, I used "loop unrolling", which means that all main loop Gosubs were replaced with directly copy pasted code. But the source code included in the disk of course still has the Gosubs, for the sake of readability. But if you want the final speed boost (about 1 frame faster), then just remove all Gosubs in the main raycaster loop, and replace them with copy pasted routines.

Also note that the effects of this loop unrolling will only be noticeable on a standard A1200 without any Fast RAM; on faster Amigas you won't notice much difference. And also if this program was converted to A500, then the speed boost from this trick would actually be necessary to achieve a playable frame rate.

In the future I might actually make a A500 version, as well as improved versions of the engine...although an actual game is unlikely.
Attached Thumbnails
Click image for larger version

Name:	BlitzRaycasterPic.png
Views:	234
Size:	14.3 KB
ID:	56736  
Attached Files
File Type: zip BlitzRaycasterV431.zip (52.5 KB, 28 views)
File Type: zip BlitzRaycasterV524.zip (53.9 KB, 25 views)

Last edited by Master484; 16 February 2018 at 15:43. Reason: added new program version
Master484 is offline  
Old 11 February 2018, 02:30   #2
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,679
Consider trying out the Mildred library for pixel manipulations and C2P.

For loop unrolling, perhaps you can use macros?
idrougge is offline  
Old 11 February 2018, 13:42   #3
Master484
Registered User
Master484's Avatar
 
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 330
Quote:
For loop unrolling, perhaps you can use macros?
Maybe, although I have never used macros before, and right now the loop unrolling process is still quite simple and can be achieved with a few copy pastes. But if the program gets more complex, then maybe I'll look into macros to make the unrolling easier.

And I'll check out the Mildred library.

---

The program can still be optimized for speed, and I just noticed that I have missed an obvious speed up trick for the reduced screen sizes; some ray logic processing still happens for the cut screen areas on the left side. Only the right side cut area skips the processing but not the left...it's nothing major, but everything counts.

And I think a few other optimizations are also possible, so I'll be posting updated versions of this engine as time goes on.
Master484 is offline  
Old 16 February 2018, 15:47   #4
Master484
Registered User
Master484's Avatar
 
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 330
I made an updated version of the program, which has been added to the attachments of the first post.

The old version had one crash bug that would cause an "array subscript out of range" error when running the program with Blitz debugger turned on. But this should now be fixed.

Also speed has been improved a lot. This version is over 200 scan lines faster than the old one.

New speed values are:

Full 320*200 screen

Line mode: stable 17 FPS
Texture mode: 5-10 FPS
Mirrored texture mode: 7-12 FPS

Smaller 160*200 screen

Line mode: stable 25 FPS
Texture mode: 8-17 FPS
Mirrored texture mode: 12-17 FPS

I'll update these new speed values to the first post as well.
Master484 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
To all demo experts: Trying to identify a music demo from '89 or '90 hoderer support.Demos 4 05 January 2018 10:16
[blitz basic] How much amiga-blitz friendly is this? saimon69 Coders. Blitz Basic 104 29 November 2016 21:45
Maniac Mansion Demo Disk - Onslaught releases the demo of a classic for C64! Neil79 Retrogaming General Discussion 0 16 January 2015 11:40
The Blitz Defender support.Apps 15 14 January 2014 23:55
Blitz CD? Graham Humphrey Coders. General 5 08 February 2005 14:49

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:08.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.06112 seconds with 14 queries