Live data from Hacker News

Pushing Polygons on the Mega Drive

jix.one

11–20 of 47 posts

Re: Pushing Polygons on the Mega Drive

#12
post #8
post #2

Author here, happy to answer any questions you might have.

Choosing 50 FPS instead of 60 was because needing to dedicate more CPU to each frame, or because another reason? P.S. Impressive demo, kudos :-)

For the Mega Drive/Genesis the framerate depends on the region, matching the local video standard. The European Mega Drive uses PAL with 50Hz.

As the biggest part (but not all) of the demoscene is based in Europe, most demos target PAL hardware. The same is true for our demo group. NTSC ports can be very difficult if not impossible as PAL often does have a slight advantage in CPU cycles per frame. This is also the case on the Mega Drive.

Porting the polygon renderer shouldn't be a problem as it renders in an off-screen CPU RAM buffer. In the worst case it would have to skip more frames, having a lower effective framerate.

A lot of the other effects have very critical timing though. I've been told that porting some of them to NTSC is just impossible.

Re: Pushing Polygons on the Mega Drive

#14
post #8
post #2

Author here, happy to answer any questions you might have.

Choosing 50 FPS instead of 60 was because needing to dedicate more CPU to each frame, or because another reason? P.S. Impressive demo, kudos :-)

There is a little more CPU time, but the extended vertical blanking interval means there is a huge difference in video memory bandwidth, which is critical for a long DMA transfer from 68000-bus memory to VRAM through the Mega Drive's VDP.

60Hz V-blank DMA: 7524 50Hz V-blank DMA: 17622

That's at 320x224 resolution for both. I don't know how much this affects this one demo in particular, but for other things it can be a little annoying sometimes to be bandwidth-starved.

Re: Pushing Polygons on the Mega Drive

#16
post #2

Author here, happy to answer any questions you might have.

Were there any alternatives/dead ends you went through to arrive at this technique, or any extensions you wanted to do but didn't find the time? Really amazing work BTW, this might be my favorite demo ever!

Re: Pushing Polygons on the Mega Drive

#17
post #16
post #2

Author here, happy to answer any questions you might have.

Were there any alternatives/dead ends you went through to arrive at this technique, or any extensions you wanted to do but didn't find the time? Really amazing work BTW, this might be my favorite demo ever!

There weren't really any dead ends. Mostly because I started with a very simple naive way to draw polygons and improved it incrementally. I didn't implement all those steps, but convinced myself that they would work. I started with a generic plot-individual-pixels-into-tilemap routine. Going by tile-rows and columns with special casing solid tiles came next. That required "convexity" in x direction but at that point I was only thinking of triangles. Then I noticed that avoiding overdraw and working with a tesselation of the screen is probably faster. A that point I also extended it from triangles to polygons. While fleshing out the details of everything I noticed that I don't have to be exact for right-side edges if I draw the polygons in the right order.

There actually was an extension I did, that was scrapped because it just didn't look good. At some point there was support for dithering. That helps with the low color precision of the Mega Drive (3-bit/channel). It only supported 50% checkerboard dither though, which looked odd when animated. I toyed with some ideas on how to improve upon that and discussed them within our demo group, but in the end the decision was to not use dithering.

Re: Pushing Polygons on the Mega Drive

#18
post #5

You want to go one further... according to this interview[1], Yuji Naka actually wrote a 3D graphics engine for the Master System! :) It was very low resolution, of course, but... [1] http://segaretro.org/Interview:_Mark_Cerny_(2006-12-05)_by_S...

According to another interview that I can't find at the moment, he also wrote a Famicom emulator for the Mega Drive, which might have been the first Famicom/NES emulator ever written.

Re: Pushing Polygons on the Mega Drive

#19
post #9

The imprecise overruns because you'll draw over it is a clever optimization. It's interesting to compare and contrast these techniques from other excellent sources, like Michael Abrash's Graphics Programming Black Book, Special Edition [1]. Thought my technical knowledge topped out somewhere in the middle of the 'Quickly Drawing Tiles' section, the prose and algorithmic detail is lovely, the rationales and code is we…

Quickly drawing tiles is one of those sections that's really only going to make sense if you've ever done development work on a tile-mapped videogame console, as the mode is quite rare in other applications.

A "tile" is nothing more than an index into a collection of 8x8 graphics squares. If you've played any retro-styled games you've seen the effects of this. They were a great way to deal with memory constraints back in the day, as you reduce 64 pixels worth of on-screen data to a small handful of bytes, describing the index of the tile, and often other attributes like the palette to use, or whether to mirror the tile in a given direction.

Since the Mega Drive can only draw tile-mapped graphics, and has no direct bitmap modes, it makes sense for the rasterization engine in this demo to take full advantage of the hardware. When he talks about drawing an entire 8x8 tile with a one-word write, he means quickly setting the index in this way. Somewhere in memory, he's created 16 solid-color 8x8 tiles, one for each of the palette colors. Then, if any group of 8x8 pixels in a row would be the same color and they're aligned with one of the tiles, he can just point that tile at one of this solid-color indices, and move on. Part of the magic of his algorithm is quickly identifying (in advance) which tiles the megadrive can be quickly drawn with this technique, and which tiles (at polygon edges) need to be drawn more slowly in software.

Re: Pushing Polygons on the Mega Drive

#20
post #2

Author here, happy to answer any questions you might have.

I had a couple of games on Mega Drive that did basic 3D, or seemed to. One was F1, where a few objects seemed to be true 3D. See the overbridge at 59s and then the long tunnel at 1:01 here for instance: https://youtu.be/qofonsN3Nwc?t=57 The long tunnel is made of several short tunnels.

The other was Gunstar Heroes, where the first boss is made of 3D cubes. See here at 4:00: https://youtu.be/9v3B1hzMwnQ?t=240

I'm just interested if you know or can guess anything about how the "3D" might have been done in those.

Post reply on HN