Quadrangles

Technical discussion for those interested in Supermodel development and Model 3 reverse engineering. Prospective contributors welcome.
Forum rules
Keep it classy!

  • No ROM requests or links.
  • Do not ask to be a play tester.
  • Do not ask about release dates.
  • No drama!

Quadrangles

Postby Ian » Fri Sep 14, 2018 5:20 pm

Supermodel originally appeared to have many small rendering anomalies.
Here in scud race there is what appears to be a missing poly on the car windscreen (windshield for you yanks).

Image

There actually existed a prototype version of scud race for the dreamcast, and there is some footage on youtube of it, running under demul.
Image

The exact same poly errors shows up here too, so I assumed that the car was just modeled badly originally. Without high quality footage of car from the original model3 hardware I had no way of knowing if this was a bug or not, so I just wrote it off.

Then Harry showed me this screenshot, and hardware comparison.
Image

And on the model3
Image

Oh god, what's going on with the texturing? Why is it so broken. To debug this thing first I took a look at the actual polys themselves.
(Scud race looked actually quite awesome like this lol)
Image

Poly 712 and 713 were the most visibly broken ones.

Here is the polys overlayed with the original rendering. The white lines show how they are being split into triangles.
Image

Okay maybe we've split our quads the wrong way? There are actually 2 ways you can split a quadrilateral, and you can get quite different results depending on which split you take.
Image

Okay so let's see the rendering with the splitting into triangles flipped.
Image

Parts of the model look better.. other parts look more broken somehow. My original thoughts were, the splitting could have been related to how the vertices were arriving at the input buffer, but that turned out not to the case. There actually exists algorithms to split quads to give better results. For example you can split a quad into triangles by the shortest distance between the vertices. I tried this, and results were better but still no cigar. I realised later on that, both ways of splitting the quad were wrong, and actually the hardware was natively rendering quads, ie with quadratic interpolation (between 4 points) This is somewhat problematic, because virtually all hardware in existence renders only triangles (interpolation between 3 points). Besides the DS? The only hardware that rendered quads were made 20+ years ago, sega saturn, nvidia NV1? Not much is known about how they render quads, and what kinds of limitations they actually had.

Quads are actually quite interesting .. by interpolating between 4 points per vertex lighting suddenly looks a lot better.
Image

The left is triangles per vertex, middle quads, right pixel shaders. The per vertex quad version looks almost identical to the pixel shader version ... which is a massive improvement over triangles.

You can also do this with quads
Image

To texture that properly with triangles, you'd have to really tessellate that down to the pixel level. There are papers online that recommend tessellation to solve this problem and that was the first solution I tried. But splitting a quad into 4 quads, and splitting again to render as triangles 1 quads becomes 8 triangles, and all you've done is halved the error. Do a 2nd or 3rd level of splitting really explodes the number of polys and basically chokes the renderer. Not a viable solution.

Nvidia has a paper where they recommend rendering quads with a geometry shader and gl_lines_adjacency. You can then pass all the 4 attributes to the pixel shader and do custom interpolation there.
Image

An algorithm for this exists and which works really well can be found in this paper. (Warning super technical)
http://www.inf.usi.ch/hormann/papers/Ho ... 04.AQR.pdf

My original quad code based upon this paper, basically worked (as a proof of concept) but had a lot of corner cases that would result in NaNs and other errors. And I also had a serious issue with AMD cards where interpolation qualifiers didn't work with geometry shaders. Looked like this

Image

This bug caused me to abandon the project entirely. If I couldn't get it to work on my AMD card, what's the point? Anyway, 1 year later AMD got back to me and that bug has been fixed. Just not on my AMD card because it's older and doesn't get driver updates anymore .. lol, oh well.

Anyway with this bug fixed, motivated me enough to finish this project. And these are the results.

Image
Just like the arcade now!

Although interpolation of vertex attribs now looked correct, these errors still existed.
Image

The reason is because fundamentally we are still rendering the quad as 2 triangles. And the depth values are being written as triangles. Anyway in GLSL you can write to gl_FragDepth and write your own custom values. Normally you don't need to bother with this because it's done automatically. You don't even need to write anything. Triangles are always planar, but quads, well they don't have to be planar. In fact you they can be twisted and contorted. You can render some extremely complex shapes with just a single quad polygon. Anyway interpolating the depth between 4 points gives us these results.

Image
No more depth testing errors, everything works as expected!

As far as I know this is the only general purpose quad renderer (in opengl) in existence. You can switch between the triangle and quad shaders with the command line -quad-renderer. Personally I wouldn't have bothered with the normal triangle renderer at all, but there are enough people out there with potatoes for pcs that will complain if I make it the default renderer lol.

This project has actually changed my mind about quads. I don't see them making a come back, but they aren't so evil after all.
Ian
 
Posts: 1547
Joined: Tue Feb 23, 2016 9:23 am

Re: Quadrangles

Postby Toshiko » Fri Sep 14, 2018 6:45 pm

This is a great write up, even for those of us who've been following along (there were details I wasn't yet aware of, and it's a great jog to the memory of how far you've come). Your patience and attention to detail is beyond commendable.

One thing I have to ask, though: was there actually a leaked prototype of Scud Race for Dreamcast? That screenshot appears to be of the Model 3 game from an older build of Demul (it had Model 3 support for a while, before the author decided it wasn't worth it to him to continue work on it given the state of Supermodel).
Toshiko
 
Posts: 119
Joined: Fri Mar 16, 2012 10:30 am

Re: Quadrangles

Postby Ian » Sat Sep 15, 2018 1:14 am

One thing I have to ask, though: was there actually a leaked prototype of Scud Race for Dreamcast?


Well, not that I have tried it but I believe so.
Thread on it here
https://assemblergames.com/threads/is-d ... sed.29868/
Ian
 
Posts: 1547
Joined: Tue Feb 23, 2016 9:23 am

Re: Quadrangles

Postby doteater » Sun Sep 16, 2018 7:43 pm

Ian wrote:As far as I know this is the only general purpose quad renderer (in opengl) in existence. You can switch between the triangle and quad shaders with the command line -quad-renderer. Personally I wouldn't have bothered with the normal triangle renderer at all, but there are enough people out there with potatoes for pcs that will complain if I make it the default renderer lol.


hello ian , nice work as always

just downloaded 741 and that quad command doesn't seem to get recognized (i tried using -quad renderer as well)
is it something meant for the next release(s) maybe ?

Image

also,is the performance loss from switching from triangles to quads supposed to be that big ?
my hardware isn't that great (very old i7 and a 750ti) but i didn't notice a significant difference when i tested your wip quadtest build a couple days ago
a few games do drop from 70/80 fps to 30 in particular moments or stages in the "regular" build but pheraps those are known issues ?
i might open a thread in the fitting room section later i guess

one final question while we're at it (i've been kinda out of the loop in the past 6-8 months)
should i disable the network emulation (aka does it help performance) or is it mandatory in certain games ?
and what's the command to disable it if there is one

and thank you again for fixing vf3 , that was the #1 on my personal wish list
User avatar
doteater
 
Posts: 21
Joined: Fri Nov 18, 2016 9:24 am

Re: Quadrangles

Postby Ian » Mon Sep 17, 2018 1:13 am

Command line is
-quad-rendering
my bad for probably type out the wrong one. You should disable the network code .. unless you actually have multiple instances of the program and you have other people to play with lol. Currently the network code can only work in single threaded mode, which is significantly slower
Ian
 
Posts: 1547
Joined: Tue Feb 23, 2016 9:23 am


Return to The Dark Room

Who is online

Users browsing this forum: No registered users and 3 guests