Log In  

Cart #mahkoe_sbuf-4 | 2022-01-06 | Code ▽ | Embed ▽ | Forks ▽ | License: CC4-BY-NC-SA

A long time ago I read a page that explained the "s-buffer" technique for hidden surface determination. I can't find it anymore, sadly.

The general idea is to keep an array of "segments" per each horizontal line in the display (making 128 arrays total). A segment is just a left x-coordinate, a right x-coordinate, left+right z-depths, and colour. Each array of segments is kept in order.

The polygon filling code is my own method, but it was largely adapted from the method outlined in the graphics programming black book: https://www.jagregory.com/abrash-black-book/#chapter-38-the-polygon-primeval

A few extra notes:

  • You can get 30 FPS with about 75 visible polygons
  • The fox model (downloaded here: https://opengameart.org/content/5-low-poly-animals) only hits 15 FPS. In general there are about 100 visible polygons at any given time
  • All polygons must be convex and planar, but the s-buffer technique completely deals with hidden surface determination (i.e. your models don't have to be convex, and you can have multiple objects in the scene)
  • There are still a few visual glitches for corner case polys that are a single line

EDIT: Thanks to @freds72, I was able to track down the original S-buffer article:

P#104285 2022-01-04 20:00 ( Edited 2022-01-06 02:36)

looks neat! it doesn't run tho:

> booting cartridge..
> can not #include

maybe save @clip and upload the string it puts in your clipboard instead; that should flatten the includes automatically

P#104286 2022-01-04 20:09
:: mahkoe

Thanks for the tip. I think I managed to upload it properly this time

P#104287 2022-01-04 20:12

Excellent! I tried something similar (using Abrash sorted edge)
some time ago only to realize it's totally impractical on pico :/

The cost of per span operation far outweight overdraw or regular sorting...

Note: I suspect the page you are looking for is: https://www.flipcode.com/harmless/issue01.htm

Note: using convex objects is the worst idea to demo the effect!

Abrash "z-buffer" for Quake, see: https://www.phatcode.net/res/224/files/html/ch66/66-03.html

Bug report: pressing left/right keys breaks the demo

P#104289 2022-01-04 20:37 ( Edited 2022-01-04 20:42)
:: mahkoe

@freds72 You have great insight! I ran a few stat(1) printouts earlier and found that about 80% of cycles are split roughly evenly between scanpoly (the function that find the left+right edges of polygons) and poly2sbuf (the function that inserts all the segments).

The first few objects are convex (they were there before I implemented the s-buffer) but the last two are nonconvex.

Anyway, it did end up being useful to try the s-buffer to have something to compare against. Until I tried it it was unknown whether it was better than the classic sort+draw, which is probably better for pico-8 anyway.

P#104291 2022-01-04 20:47

suggest to use James Edge bunny model, that would make a fair comparison with a "standard" rasterizer, see: https://www.lexaloffle.com/bbs/?tid=35282

P#104292 2022-01-04 20:54

bug report: looping through all models "misses" fox model!

@jimmi: that demo should interest you

P#104360 2022-01-05 20:33 ( Edited 2022-01-05 20:34)
:: mahkoe

@freds72 fixed, thanks for pointing that out!

P#104382 2022-01-06 02:36

what does the fox say gin gin gin gin bin gin gin gin

P#104607 2022-01-09 03:32

thanks for getting me started again on s-buffer :)
(started from scratch to avoid the collect then draw approach from original article + faster!)

P#105768 2022-01-27 21:47
:: mahkoe

@freds72 very cool! I'm looking forward to taking a look at the code, I think I'll be able to learn something

P#106015 2022-01-31 00:00

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2022-10-01 17:51:27 | 0.067s | Q:31