Shop OBEX P1 Docs P2 Docs Learn Events
[WIP] VJET: Beam-chasing polygon rasterizer — Parallax Forums

[WIP] VJET: Beam-chasing polygon rasterizer

Wuerfel_21Wuerfel_21 Posts: 5,051
edited 2020-12-21 23:15 in Propeller 1
If a picture is worth a thousand words, then a video is worth a million...


This is a video driver that instead of tiles and sprites draws vector shapes in real-time as the screen is scanned. Therefore, no big frame buffer is needed, just a relatively small double-buffered display list.

I'm posting this here in a kindof unfinished state, because I want to avoid sitting on it for months like I usually do.

Instructions:
- Open either demo.spin (simple demo/test) or cobra.spin (the 3D Elite ship rendering thing)
- Change arguments to kb.start and gfx.start to suit your board (the latter takes a TV.spin style pingroup as first arg and NTSC/PAL60 flag as second (PAL60 not tested))
- Load to RAM
- Profit?

cobra.spin has some keyboard controls:
- Arrow keys/Home/End to rotate the model
- A to re-enable automatic rotation
- R to reset rotation
- C to toggle debug color mode
- B/N to switch models

Known issues (driver itself):
- Everything is kinda quickly hacked together and lacks polish and comments
- Output module is the same as JET Engine's. I might make a higher resolution and less bloated one later
- Shapes that are clipped by the top edge of the screen disappear - will have to precalculate during VBLANK

Known issues (Spin geometry processing):
- Only triangle rendering is implemented. In theory arbitrary convex polygons are already supported by the rendering cogs, but the geometry processing for those is going to bit more complicated than for triangles. (cobra.spin currently uses triangulation to draw convex polygons). I might also implement lines and text.
- Those nasty gaps between triangles

Known issues (example programs):
- cobra.spin doesn't work in fastspin for some reason - demo.spin does.
- slow Spin code (see above)
- In cobra.spin, the thargoid's model is imported, but doesn't work (The Elite ship models are taken from the included B7051600.TXT, more could be imported)
- The normals on the ship models are a bit whack (different lengths and sometimes plain wrong) - maybe recalculate from scratch?


«1

Comments

  • Wuerfel_21Wuerfel_21 Posts: 5,051
    edited 2020-07-14 20:00



    Meanwhile: fastspin creates abstract art



    fastspin%20be%20like.png
    1280 x 1024 - 268K
  • Neat!
  • Wuerfel_21Wuerfel_21 Posts: 5,051
    edited 2020-07-14 21:06
    The problem with fastspin seems to be some kind of memory corruption (the ABORT handler fires due to insufficient display list space, which indicates that either putXXXX is being called too often or the gl object's VARs are being corrupted.) Can't reproduce anything in a controlled enviroment though. Not sure if @ersmith wants tickets about big blobs of badly commetned code failing...

    I did find some other random bugs, but nothing substantial
  • JonnyMac wrote: »
    Neat!

    thanks.
  • Hot damn this is cool... early days of P1-Starfox? :D
    It's really amazing what you've done with this and your 2D gaming engine...
    Had to load this onto the Demoboard...most likely way way above my head but I'd like to look at this one in a little more detail...had the beginnings of an idea awhile back for a utility with basic 3D
    for testing an IMU (e.g., LSM9DS1). Is VGA totally out of the question? Even if only composite it would still be cool to mess with.

    Cheers
  • If you're content with linedoubled 256x224, VGA should be almost plug-n-play when I get around to properly finishing the regular JET Engine VGA output module.

    However, the display list format is ready to handle screens taller than 256 pixels and I haven't really hit the scene complexity limit yet, so 640x480 VGA might be possible? An actual problem is that the 64 VGA colors are really terrible for shading.

    As for messing around a little hint: The rendering cogs only get to see a list of "shapes". Currently only shape type 1 is defined, which is kinda like a stack of trapezoids, defined by an initial left X, an initial right X and a number of segments defined by height, left slope and right slope. All the math to turn a triangle into such a structure can be found in the display list object. This is also why I say that it will be easy to add arbitrary convex polygons.

    Using the driver with the Spin interface is easy, you just need to handle the swapping of display lists and then you're off to the races. Just call the triangle function and watch a pointy boi magically appear on screen.

    RE: fastspin debuggery
    The problem has nothing to do with math failure. I've also attached a more minimal sample of the bug. Ths doesn't crash, but display a distorted cube instead. Yet serial debug code shows that the vertices are being correctly transformed...


    cobrabugproptool.pngcobrabugfastspin.png
    1076 x 808 - 143K
    1076 x 808 - 129K
  • I managed to figure it out:
    Fastspin didn't handle
    data_ptr += byte[data_ptr++]
    
    correctly. Version with less silly pointer advancement attached. Now works properly on fastspin, full 60 FPS even at O0.

  • Wuerfel_21 wrote: »
    I managed to figure it out:
    Fastspin didn't handle
    data_ptr += byte[data_ptr++]
    
    correctly. Version with less silly pointer advancement attached. Now works properly on fastspin, full 60 FPS even at O0.

    Thanks, @Wuerfel_21 for tracking this down! I'll fix that bug for the next release of fastspin.

    BTW, did you notice the fastspin warning about a tjz instruction:
    VJET_v00_composite.spin:455: warning: tjz to tasks:off without #; are you sure this is correct? If so, change the tjz operand to tasks:off-0 to suppress this warning
    
    The instruction reads "tjz t1,:off". I think perhaps it should be "tjz t1, #:off"?


  • mparkmpark Posts: 1,305
    What the?! How in the??

    Really amazing work, @Wuerfel_21. Kudos!
  • An astonishing impressive accomplishment! I've often wondered if something like this were possible with the P1, and now you've proven it.

    My hat's off to you!

    -Phil
  • ersmith wrote: »
    BTW, did you notice the fastspin warning about a tjz instruction:
    VJET_v00_composite.spin:455: warning: tjz to tasks:off without #; are you sure this is correct? If so, change the tjz operand to tasks:off-0 to suppress this warning
    
    The instruction reads "tjz t1,:off". I think perhaps it should be "tjz t1, #:off"?

    You're right, that is a bug in all variants of this code, I just always had a broadcast freq defined so I never noticed.


    I've tried to reduce the triangle gaps a bit, but there's still some there...
  • And of course I forgot to save the file
  • I literally can't get rid of these stupid gaps.

    I've been staring at the code (PUB triangle in VJET_v00_displaylist.spin for those playing along at home) for hours, trying every permutation of fiddling I can think of, to no avail.
  • After staring for a couple more hours, I've managed to get it to a kinda manageable state. Still has gaps on certain edges, but the code isn't a mess anymore. Something's weird with the second short slope of each triangle, but I really don't know what. If anyone here has any applicable knowledge of geometry, help is appreciated.

    Will try to get the convex polygons going next
  • Good news, it's past 1AM, but I managed to figure it out: I need to not pre-apply the first slope step onto initial edge X if it slopes inward (i.e left edge slopes to the right).
  • Wuerfel_21Wuerfel_21 Posts: 5,051
    edited 2020-07-16 18:13
    Polygon rendering is in. Can handle any convex polygon (and some (all?) Y-monotonic ones) and as many vertices as you have memory for. The polygon function also use a lot less display list memory than triangulating the same polygon.

    Getting here involved a big ol' journey into computational geometry and a good couple failed algorithm attempts...


    There's also line and point functions now, but neither is efficient in terms of memory usage.

    polyfleet.png
    1076 x 808 - 329K
  • Way cool. I’m dreaming about hacks to your code that works at VGA resolutions to do 80’s style vector displays.
  • This is amazing. Reminds me of the Amiga demo days.
  • MJBMJB Posts: 1,235
    edited 2020-07-16 21:53
    Wuerfel_21 wrote: »
    ...

    wow - impressive

    now just imagine how this will perform on the P2 ...
    with the new features CORDIC, faster, more RAM ...
  • MJB wrote: »
    Wuerfel_21 wrote: »
    ...

    wow - impressive

    now just imagine how this will perform on the P2 ...
    with the new features CORDIC, faster, more RAM ...

    Yeah, although on P2 there's enough memory for a framebuffer (which bypasses many of the problem this realtime approach has)

    The actual CORDIC (as opposed to QMUL/QDIV) isn't _that_ helpful for 3D - the P1 sine lookup ROM is plenty accurate and fast for calculating sines.
  • Wuerfel_21Wuerfel_21 Posts: 5,051
    edited 2020-07-18 01:14
    Spin Super Hexagon, anyone?
    Coming soon to a Propeller near you.
    hexagon_preview2.png
    1058 x 794 - 420K
  • Spin Hexagon is coming along:
    NOTE: The game has no audio yet, I just put the original Super Hexagon music over it so you don't have to listen to line-in noise. I think I can add audio though and I guess I'll have to ask if I'm allowed to distribute the original audio files with it.

    Also sorry for the terrible gameplay, my capture device has terrible latency.
  • Awesome...haha btw even with the latency, you're still way better than I am (haven't played this in quite awhile..rage quit a few times). I haven't had a chance to look into the sources yet so maybe it's self-explanatory, but I had a question that pertains to this and the previous demos: is the level of grey fill in the border indicative of "load?" There seemed to be a correlation with it and the number of triangles onscreen when I was using the cobra and demo objects.
  • avsa242 wrote: »
    I haven't had a chance to look into the sources yet so maybe it's self-explanatory, but I had a question that pertains to this and the previous demos: is the level of grey fill in the border indicative of "load?" There seemed to be a correlation with it and the number of triangles onscreen when I was using the cobra and demo objects.

    Yes, all my programs for this driver currently set border color to $2D (light blue) after VSync and set it to 04 (mid-dark grey) when they're done and start waiting for the next Vsync. So it indicates "CPU load" if you will.
  • New preview version:
    • Added text rendering - uses 8x8 fonts (1px spacing is added between characters) and supports double width, quad width, double height, quad height, etc.
    • Added box rendering (points are now internally delegated to be drawn as 1x1 boxes)
    • Included an example font and a ruby program that converts an image to Spin DAT code
    • The display list object now culls some off-screen shapes for you - you must set the screen size using the set_clip method
    • The display list object now has a done method one should call before presenting a finished display list - this will sanitize it if it overflowed, preventing crashes and screen corruption.
    • minor optimizations
    • removed some JET leftover junk

    Note: To compile this version with fastspin, you will NEED the latest bleeding edge git build (or wait for 4.2.5 to release).
    I actually have no idea why it doesn't work on 4.2.4 anymore, but I really don't care. Obviously PropTool will work, too.

    Image10.png
    1058 x 794 - 349K
  • You are on the run right now, cool

    Go Wuerfelin, GO.

    You are writing pretty nice stuff, and are helpful here in the forum, so I read all of your posts with great interest.

    good to have you here,

    Mike
  • msrobots wrote: »
    You are on the run right now, cool

    Go Wuerfelin, GO.

    You are writing pretty nice stuff, and are helpful here in the forum, so I read all of your posts with great interest.

    good to have you here,

    Mike

    Oh thanks, have somehow missed your kind post before.

    Anyways, here's a new Spin Hexagon screenshot: It's almost done, just missing very few things. But those few things are gonna need some memory and I'm already a couple bytes short.
    Image21.png
    1076 x 808 - 274K
  • Wuerfel_21Wuerfel_21 Posts: 5,051
    edited 2020-07-28 01:29
    After chasing down a really annoying bug (Note: ALWAYS make sure a display list is either valid or zero'd out before presenting it or the graphics code will steamroller your code away) I have returned to post.

    It actually looked pretty neat on the capture device:

    Anyways, I've attached a new VJET preview release:
    • optimized display list generation by juggling the data directly instead of using the putXXXX functions - sadly this makes everything a lot less readable
    • removed JET cruft (attribute buffer, scrolling etc) and some features (overlays, most notably (although I'm thinking of axing those from JET, too... IDK) from TV output module
    • changed resolution to 256x238 and decreased pixel clock - many TVs will now no longer show any borders (before you ask: 256x240 wouldn't work, I was too lazy to debug it and 238 lines fill my big Phillips TV just as well, so whatever). The capture stick does, however (yet it doesn't show the top couple lines for some reasons). Also note that the pixels are now even wider than before, so always make sure to incorporate aspect ratio correction. I've added it to the cobra demo as an example (this can also be adjusted for anamorphic widescreen if you have a TV that supports it)
    • Added new functions for centered and left-justified text
    • Added _xasm versions of some of the objects - these don't include any PASM code and instead accept a pointer to it. To get the PASM code as a file you can load/include/whatever, just compile the non-xasm version with the "-c" switch, available on fastpin, homespun and maybe also BSTC?
    • Added the ! to hexfont.spin

    Also have some more random Spin Hexagon pictures:
    hexagon_almost2.png
    hexagon_almost1.png
    1076 x 808 - 96K
    1076 x 808 - 306K
  • Wuerfel_21Wuerfel_21 Posts: 5,051
    edited 2020-12-24 14:29
    So here's a thing: Not sure if work-in-progress or canned, but here it is:


    A rendition of the classic Atari ST demo...
    This is in that weird area where it almost works, but there just isn't enough power and/or memory to make it work well.

    Ask if you want source or smth, I guess.


    Unrelatedly:
    I'm using a different recording setup than usual.
    a) I have a new capture card.
    b) I'm using OBS studio because classic can't handle the particular crust of its driver
    c) I'm using x264 because OBS studio is poopoo as usual and the NVENC is broken. Searching the issue just nets "switching to software fixed it for me", which is tremendously helpful for troubleshooting.

    I think the quality took a hit somewhere...

    EDIT: It's as good as it's gonna get now
  • mparkmpark Posts: 1,305
    Amazing!
Sign In or Register to comment.