[WIP] VJET: Beam-chasing polygon rasterizer
Wuerfel_21
Posts: 5,051
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?
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?
Comments
Meanwhile: fastspin creates abstract art
I did find some other random bugs, but nothing substantial
thanks.
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
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...
Fastspin didn't handle 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: The instruction reads "tjz t1,:off". I think perhaps it should be "tjz t1, #:off"?
Really amazing work, @Wuerfel_21. Kudos!
My hat's off to you!
-Phil
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...
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.
Will try to get the convex polygons going next
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.
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.
Coming soon to a Propeller near you.
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.
• 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.
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.
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:
EDIT: It's as good as it's gonna get now