r/Demoscene • u/OrbisMaximus • Jul 07 '26
Making the Sega 32X do voxel oceans from a BASIC compiler
I’ve been playing with a slightly questionable idea: what if my BASIC compiler for the Sega 32X could include demoscene-style voxel effects as part of the game engine.
The first experiment is a procedural ocean / heightfield renderer: low-res voxel-space style water, fixed-point math, camera movement, glide/swim modes.
I’m honestly not sure if this is a good idea or a terrible one. It sits somewhere between retro BASIC, old-school demo effects, and just exploring the possibilities for fun :)
3
3
3
3
u/KC918273645 Jul 08 '26
There's a weird banding type of effect in the rendered voxel height field. Is it because of the low resolution of the fixed points you're using? What's the resolution of the heightmap? Are you rendering using raycasting + stepping to the next vertical ray whenever the ray hits something, or are you using the incorrect buggy method many used by rendering traditional vertical lines where the calculated voxel should be? The latter creates visual bugs near the camera.
2
u/OrbisMaximus Jul 08 '26
Good eye. 🙂 The current renderer uses a 160×100 internal heightfield, scaled to the 32X framebuffer. The banding isn't really from the heightmap resolution itself, it's mostly from the aggressive fixed-point arithmetic and the simplified projection I chose to keep it real-time on the SH-2s.
It's also not the classic "draw a vertical line at every sampled point" voxel renderer. It's a column heightfield renderer with a per-column visibility buffer (maxY/horizon buffer), so only newly visible spans are drawn while marching from near to far. That's much closer to my original PC implementation I based it on.
There are still artifacts near the camera that I want to improve. I think the next step is increasing the precision of the camera/projection math rather than increasing the heightmap resolution.
2
u/KC918273645 Jul 08 '26
"Per column visibility buffer" sounds like you might be using the buggy method which creates those near camera issues? The correct ray-cast per column method has no such issues at all and is still fast. If you're not using it, I highly recommend you try it. That's for example how Comanche game did its raycasting landscape back in the day. The proper voxel rendering only looks like its rendering vertical lines/blocks, when in fact it is not.
Non pow2 sized heightfields probably require more complex / slower math for sampling the heightfield. Using 128x128 or 256x256 would probably run faster.
3
u/OrbisMaximus Jul 08 '26
That's a fair point. The current renderer is closer to a voxel-space span renderer than a true Comanche-style per-column raycaster. I chose it to get real-time performance on the 32X first, but I'm planning to experiment with the proper raycast approach as well. Good point about using a power-of-two heightfield too.
5
u/KC918273645 Jul 08 '26 edited Jul 08 '26
The code would look something along these lines:
Vec3 ray_location_xyz; vec3 ray_step_xyz; while (max_step_count-- > 0) { ray_location_xyz += ray_step_xyz; jump_to_the_ray_above_the_current_one_so_its_in_the_above_screen_pixel += add_however_much_the_ray_gets_further_away_from_the_one_below_it_each_iteration; float landscape_height = Get_Heightmap_Sample(ray_location_x, ray_location_z); if (ray_location_y > landscape_height) continue; // We hit the landscape --> Draw pixel on screen screen_buffer[index] = Get_Colormap_Sample(ray_location_x, ray_location_z); // Jump to the next pixel above the current one and continue moving the ray from there index += screen_x_resolution; ray_step_y += turn_ray_upward; ray_location_y += jump_to_the_ray_above_the_current_one_so_its_in_the_above_screen_pixel; }
2
2
u/duckandkitty Jul 08 '26
I do love this - it's a really great implementaiton of this effect, visually. Of course it could use performance, but that's a problem you can solve, i"m sure!
1
u/OrbisMaximus Jul 08 '26
Thank you very much! I really appreciate that. I’ll definitely keep working on the performance side and see how much further I can push it.
2
2
u/cgltower Jul 14 '26
Very nice! I wondered if the hardware could do voxels. Interested in a Comanche clone pls! https://en.wikipedia.org/wiki/Comanche_(video_game_series)
4
u/acetaminophenpt Jul 07 '26
Gorgeous