Hardware Accelerated Raycaster

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
marclurr
Party member
Posts: 101
Joined: Fri Apr 22, 2022 9:25 am

Hardware Accelerated Raycaster

Post by marclurr »

Just thought I'd add my entry to the already overflowing pile of raycasters.

The title might be a little misleading, but I have to get clicks somehow ;) While I think my approach is reasonably novel, I'm sure it's been done before. That said, I didn't find any examples (not that I looked super hard).

I'd been playing a lot of 90's style shooters (Ion Storm, Project Warlock, Lead Haul, Gungodz) and fancied making something similar of my own. I wrote a software raycaster that could render a 320x200 frame in about 8ms on my 2013 MacBook Pro. While this was probably reasonable performance for the kind of thing I was going to do it felt a bit disappointing and I got bored and left the idea for a few weeks.

After some random messing around with Love and realising the shaders are proper GLSL shaders I thought I'd revisit the racyaster with an idea had a few years ago for a hardware rendered version. Essentially all the data required for plotting pixels is gathered into a texture which is submitted to a shader for drawing. With a bit of fiddling around I was also able to use proper depth buffer for occluding the sprites. Floors and ceiling are rendered with a Mode 7ish style shader, there's plenty of those knocking around on here.

As plotting the pixels is normally the slowest part of a raycaster, and GPUs are obscenely good at that part the performance boost is quite crazy.

For a 320x200 frame the machines I tested on get the following:
PC (i9-9900K, 32GB, 1070ti): <1ms, ~300-600 microseconds (~1-6ms for a similar scene in the software version)
2013 MPB (i5-4882U, 8GB, Integrated GPU): 1-3ms

The really cool part is that it can render a frame at 3840x2400 on the PC in about 1-3ms, and the native resolution of the MBP, 2560x1600, in about 2-4ms. The old Mac can't really run at the higher resolution.

Nearly all of the frame time is now taken up by the raycasting, and it's still possible to tank the performance by trying to render really large open rooms with very long draw distances. The draw distance can be configured. For lower screen resolutions lower draw and shading distances actually look better as there's too much "pixel crushing" (not sure of the real term, but I'm referring to the noisy textures on far walls) on distant textures.

I've attached a demo with some simple UI (thanks to Slab) for changing the renderer's parameters. You can enter or exit "walk around mode" by pressing tab. I'm curious to hear how it performs for other people, particularly on quite slow machines.

github: https://github.com/marclurr/harc
harc.love
(261.21 KiB) Downloaded 205 times

And a video for anyone who can't be bothered downloading, but wants to see:



Edit: Added link to github
Last edited by marclurr on Thu Mar 30, 2023 6:05 am, edited 2 times in total.
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Hardware Accelerated Raycaster

Post by yetneverdone »

Awesome, I always want to start with raycasting but never gotten to it yet. Will it be open-source like in GitHub? Glad to see another love project powered by Slab :)
User avatar
marclurr
Party member
Posts: 101
Joined: Fri Apr 22, 2022 9:25 am

Re: Hardware Accelerated Raycaster

Post by marclurr »

yetneverdone wrote: Fri Nov 04, 2022 2:11 am Awesome, I always want to start with raycasting but never gotten to it yet.
I love raycasters. This is about my 4th one in the last 20 years (probably in 4 different language as well :\). I usually start them with the intention of making a game but end up feeling satisfied enough with just getting the rendering working well. I hope to buck that trend this time though!
yetneverdone wrote: Fri Nov 04, 2022 2:11 am Will it be open-source like in GitHub?
I am planning to open source it. I still have a few features I want to add and tweak some of what's there first though. I've started working on a built-in level editor, then I want to add transparent walls, as well as "thin walls with adjustable inset". I did have that feature but it was buggy due to the lazy way I implemented thin walls. I did originally want to support arbitrary wall heights as well but I'll probably leave that for another time, as I don't need it for the game I'm planning to make.
yetneverdone wrote: Fri Nov 04, 2022 2:11 am Glad to see another love project powered by Slab :)
Thanks for keeping it going! I very nearly rolled my own imgui ripoff but I've already gone off on too many tangents on this project so thought I'd try a community offering, and I'm very impressed by it. It's should make developing the level editor a breeze.
alejandroalzate
Citizen
Posts: 67
Joined: Sat May 08, 2021 9:45 pm

Re: Hardware Accelerated Raycaster

Post by alejandroalzate »

Forma god sake i have to ask the dumb question: But! it can rum doom?!
(Now seriously try to load a wad in there)

Code: Select all

target = boardIndex.getWhosPeekingThisLine()
target:setObey(true)
User avatar
marclurr
Party member
Posts: 101
Joined: Fri Apr 22, 2022 9:25 am

Re: Hardware Accelerated Raycaster

Post by marclurr »

alejandroalzate wrote: Sun Nov 06, 2022 6:43 pm Forma god sake i have to ask the dumb question: But! it can rum doom?!
(Now seriously try to load a wad in there)
Sadly this will only render orthogonal walls arranged on a grid.
alejandroalzate
Citizen
Posts: 67
Joined: Sat May 08, 2021 9:45 pm

Re: Hardware Accelerated Raycaster

Post by alejandroalzate »

marclurr wrote: Mon Nov 07, 2022 4:41 pm
alejandroalzate wrote: Sun Nov 06, 2022 6:43 pm Forma god sake i have to ask the dumb question: But! it can rum doom?!
(Now seriously try to load a wad in there)
Sadly this will only render orthogonal walls arranged on a grid.
:( well but now my butt can rest in peace i asked tho.

Code: Select all

target = boardIndex.getWhosPeekingThisLine()
target:setObey(true)
arfur9
Prole
Posts: 6
Joined: Wed Dec 21, 2022 2:01 pm

Re: Hardware Accelerated Raycaster

Post by arfur9 »

It's looking very impressive, nicely done
There reason I looked at love2d was for a raycaster but as usually I've gone with what I know and I'm doing a Myst style game and a simple editor , the editor is c# but I discovered Slab last night so all Lua might be cool
keep up the good work!!
arfur9
Prole
Posts: 6
Joined: Wed Dec 21, 2022 2:01 pm

Re: Hardware Accelerated Raycaster

Post by arfur9 »

I've tested on a Ryzen 5 4000 series with 8gb ram and a gtx1650 4gb and it's running smoothly no matter what setting I use
usually if there's anything remotely taxing the fan kicks in and it didn't
User avatar
dusoft
Party member
Posts: 492
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Hardware Accelerated Raycaster

Post by dusoft »

Same here: Ryzen 7 and it's very smooth, 1-3ms even when 1920x1080
User avatar
UnixRoot
Citizen
Posts: 80
Joined: Mon Nov 08, 2021 8:10 am

Re: Hardware Accelerated Raycaster

Post by UnixRoot »

At first, thumbs up for your shader based ray caster, I really like the idea. It's great for high resolution rendering.
marclurr wrote: Thu Nov 03, 2022 9:53 pm For a 320x200 frame the machines I tested on get the following:
PC (i9-9900K, 32GB, 1070ti): <1ms, ~300-600 microseconds (~1-6ms for a similar scene in the software version)
But for lower resolution software rendered ray casters, you don't really need the GPU. I'm easily rendering a 320x200 scene at around 0.25 ms, or a 640x400 scene at 0.40 ms on my way slower office PC (i5-4590, 32GB, GeForce GT 710). There has to be a bottleneck in your calculations or drawing routine.


Image
320x200
Image
640x400

Even at 1280x720, it's still fast enough with roughly 2.5 ms / 400 FPS
marclurr wrote: Thu Nov 03, 2022 9:53 pm As plotting the pixels is normally the slowest part of a raycaster, and GPUs are obscenely good at that part the performance boost is quite crazy.
That's not the slowest part. The slowest part in my case was the per pixel divisions needed for vertical floor rendering and the vertical columns you have to draw, instead of horizontal scan lines. Plotting the pixels on a frame buffer is really fast if you use FFI and pointers.

I'm rendering to a 90° rotated frame buffer, so I can render the vertical columns, including ceiling and floors, as horizontal scan lines in one go. Together with a precomputed LUT for the floor and ceiling rendering, it's pretty fast.
Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests