Log In  

Cart #53994 | 2018-07-07 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

I am still very new to PICO-8 and saw a few games rendered with polygons.
This lead me to the Trifill Thunderdome benchmark by Musurca.

One thing this benchmark didn't show was the number of tokens for each method which is an important detail considering the limitations of the platform.

Also, I wrote two triangle rasterizers in 163 and 335 tokens respectively which perform pretty decently. They might be an acceptable alternative to ElectricGryphon's super fast triangle rasterizer if you need an extra 2-400 tokens. If you don't, by all mean use his. It is the fastest one I found, and by a good margin!

Update 20180706: Added the possibility to switch rasterizer and turn the test triangle with the arrow keys. This allows to compare rasterizers at a normal pace. Updated EG's rasterizer to the latest he posted in the previous thread and added the one from Gryphon 3D Engine Library v2 only modified to use normal color() and fillp().

Update 20180708: Added a fill pattern and a toggle for the results and control wireframe.

Hope this helps,

P#53941 2018-07-04 16:42 ( Edited 2018-07-08 17:39)

Looks like some of the new rasterizers have severe artifacts on edges.
@p01 are these yours?

P#53947 2018-07-05 02:59 ( Edited 2018-07-05 06:59)
:: p01

That would be the one by @creamdog. It uses memset(screenAddress, col * 17, scanlineWidth) which can only set an even number of pixels. Hence the half resolution horizontally and the artifacts.

The triangle you see spinning after the benchmark uses my 335 tokens rasterizer.

P#53949 2018-07-05 04:23 ( Edited 2018-07-05 08:23)

Nice work! I haven't looked at the code yet, but that's a mighty optimization effort right there. (Twice!)

edit: I added some code to switch between renderers on the result screen, there seems to be something not quite right with at least one of the algorithms. (Pretty sure I set things up right, maybe not?)

z changes the renderer, x pauses the rotation, up changes the colour.
You might want to extend this to modify the vertices as well if you're hunting for artefacts.

add this part after the tests array definition, around line 620

add(functioninfo, { tests[1], solid_trifill_v3, "solid_trifill_v3" } )
add(functioninfo, { tests[2], function(...) local v={...} musurca_triangle({v[1],v[2]},{v[3],v[4]},{v[5],v[6]},v[7]) end, "musurca_triangle" } )
add(functioninfo, { tests[3], creamdog_tri, "creamdog_tri" } )
add(functioninfo, { tests[4], p01_triangle_335, "p01_triangle_335" } )
add(functioninfo, { tests[5], function(...) gfx_draw({...}) end, "gfx_draw" } )
add(functioninfo, { tests[6], steptri, "steptri" } )
add(functioninfo, { tests[7], p01_triangle_163, "p01_triangle_163" } )

replace everything from ::loop_showing_results:: onwards with this

local method,col,pausetime,paused=3,0,0,false

local u=t()/8
if btnp(5) then
 if (not paused) pausetime=u
 paused=not paused
if (paused) u=pausetime

if (btnp(2)) col=(col+1)%16
local r=80+32*cos(u*1.7)
if btnp(4)  then
local fn=functioninfo[method+1]

--zebra = 0
for i=0,#tests do print_result(i) end
goto loop_showing_results

P#53956 2018-07-05 11:44 ( Edited 2018-07-07 02:04)
:: p01


Excellent idea to try the different rasterizers after the benchmark.

I tried this last night and saw some have wild bugs. I updated EG's rasterizer to the last one he posted in the previous thread, and the one from the Gryphon 3D librarry v2 and now my "big" rasterizer comes ahead :U

P#53963 2018-07-06 08:17 ( Edited 2018-07-06 13:48)

Another nice addition would be an overlay of the demo triangle using plain lines (dunno, switch on/off using button).
Not all rasterizers are drawing the triangle at the same place!!

EDIT: just did the test, and @p01 are fast and accurate. Nice job!

-- "native" pico triangle/lines
if btn(4) then
 for i=0,2 do
    local p0,p1=2*i+1,(2*(i+1))%6+1
P#53968 2018-07-06 13:00 ( Edited 2018-07-06 17:13)
:: p01

Thanks. Great idea. I also added a fill pattern to make sure the different rasterizers can draw shaded triangles.

P#53995 2018-07-07 19:45 ( Edited 2018-07-07 23:45)

Hi, @p01
I'm developing a 3D modeling tool with a small specification for PICO-8.
I would like to post on the BBS using your awesome trifill code.

P#74559 2020-04-08 10:52 ( Edited 2020-04-08 10:54)
:: p01

That's the idea ;)
Go right ahead an use this code if it helps your project.

This modeler looks neat!

P#74561 2020-04-08 11:09

Thank you!
I've posted a production!


P#74564 2020-04-08 13:43

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-04-08 19:56 | 0.056s | 4194k | Q:44