[Patch] 3dfx rendering accuracy

Post new patches here!
Post Reply
User avatar
leilei
Posts: 553
Joined: Fri 25 Apr, 2014 4:47 pm

[Patch] 3dfx rendering accuracy

Post by leilei » Mon 14 May, 2018 12:20 pm

I'm still working a bit on this but decided to put it out early as I really need a break from this (4 trial and errory days so far). I'd prefer technical feedback on this. It's not ready for the tree in its current state (still have comments and the tabs/spacing isn't consistent as I code in a notepad offshoot)
dithes.png
dithes.png (20.51 KiB) Viewed 992 times
What's in the patch:
- 4x4 dithering for alpha blends (interpreter only)
- Allow forcing which filter to use in a combo box instead of a checkbox
- Options to enable/disable this new alpha blend dithering.

Also included but not quite finished or refined:
- Emulation of the CLUT bug on the V1 and V2 . Right now it doesn't produce the too bright=wrap to dark artifact yet, and causes some odd bugs with certain games (Some Direct3D games showing only white)
- 2x2 dithering for alpha blend (interpreter only). Right now it shouldn't be doing this as I recently realized dithersub only applies to the 4x4 dither (after peeking in the glide source code)
- Alpha blend bug hack fix (interpreter only). I tried to fix the darker color that shows up at the darkest side of the destination blend and might've ended up cutting off too much. This hack is now redundant when the blend dither table can do the same thing so ignore this one. It got included in the patch by accident.

EDIT: other stuff I learned:

fbzMode bit 19 controls the dithersub on all 3dfx cards. FX_GLIDE_NO_DITHER_SUB supposedly can disable it but I haven't seen this actually happen.

There is no dithersub for 2x2, but there is similar color reduction happening there anyway.

There is no big 2x2 table!
Attachments
voodoo_accuracy_6.patch
(30.79 KiB) Downloaded 26 times

User avatar
omarsis81
Posts: 618
Joined: Thu 17 Dec, 2015 6:20 pm

Re: [Patch] 3dfx rendering accuracy

Post by omarsis81 » Fri 01 Jun, 2018 6:18 pm

Wow, great job leilei!
I didn't notice that huge difference between real V2 and PCem 14 when playing

User avatar
leilei
Posts: 553
Joined: Fri 25 Apr, 2014 4:47 pm

Re: [Patch] 3dfx rendering accuracy

Post by leilei » Sat 02 Jun, 2018 10:35 pm

Play a quake game and DON'T use third party drivers, and you should see the diff...

User avatar
leilei
Posts: 553
Joined: Fri 25 Apr, 2014 4:47 pm

Re: [Patch] 3dfx rendering accuracy

Post by leilei » Wed 06 Jun, 2018 5:29 am

Here's a new patch:

- Heavily refactored: table cut in half, no extra alpha blend edit
- Now performs dither subtraction on destination before the blending function
- More consistent naming (it's called dithersub from here on out)
- An attempt to be consistent with the PCem code style (should have no tab spaces, braces on new lines, etc)
- should look the same as the pic in post #1 while looking better in other parts.
- fbzMode 19 is considered
- nothing for 2x2 yet as i'm still yet uncertain about that, envvars, etc. FX_GLIDE_NO_DITHER_SUB seems to be broken. There's supposedly some glide conformance tests out there that test the dithering bits interactively, haven't come across such yet.
- It's ONLY the dither subtraction. This patch does not contain CLUT bug, clamp hack, and the filter options
- still no changes to the recompiler :) but shouldn't be too hard to adapt it. I think most of the future changes related to this may happen in the table generation part (unless I have another terrible realization somewhere)


I'm not sure how the current dither_rb/dither_g tables were generated, my dithersub table can't seem to match it, and not even basing the generation off the old dither generation function from years ago can match it
Attachments
voodoo_accuracy_14.patch
(5.17 KiB) Downloaded 8 times

tedgreen
Posts: 6
Joined: Mon 11 Jun, 2018 11:57 pm

Re: [Patch] 3dfx rendering accuracy

Post by tedgreen » Tue 12 Jun, 2018 3:53 pm

leilei wrote:
Wed 06 Jun, 2018 5:29 am
I'm not sure how the current dither_rb/dither_g tables were generated, my dithersub table can't seem to match it, and not even basing the generation off the old dither generation function from years ago can match it
I would guess you are missing the conversion to RGB565 that is done after the dithering, this shifts the rb right by 3 and the g by 2.
I have attached a program showing this and seems to generate the same matrices as what is in PCem.
Please note that MAME has recent changed the 2x2 dithering matrix to allow the iteagle (gtfore06) driver to pass it's graphics validation tests, I think this is the only arcade driver that uses the 2x2 matrix in it's validation routines. This new matrix has NOT been verified in any real hardware.

Cheers,
Ted
Attachments
dither.cpp
(1.11 KiB) Downloaded 7 times

User avatar
leilei
Posts: 553
Joined: Fri 25 Apr, 2014 4:47 pm

Re: [Patch] 3dfx rendering accuracy

Post by leilei » Tue 12 Jun, 2018 7:50 pm

I assumed the 3dfx V2 driver already dioes validating as i've managed to make the card detection fail while trial-and-erroring very slightly different dither tables. I don't have doubt for PCem's current 2x2 table.
tedgreen wrote:
Tue 12 Jun, 2018 3:53 pm
I would guess you are missing the conversion to RGB565 that is done after the dithering, this shifts the rb right by 3 and the g by 2.
This already happens. What i'm trying to do is apply negative dither to the destination before it gets blended (which should also RGB565 and back to RGB888) with the source (that then applies a dither after it, in which the RGB565 conversion happens at the same time)

tedgreen
Posts: 6
Joined: Mon 11 Jun, 2018 11:57 pm

Re: [Patch] 3dfx rendering accuracy

Post by tedgreen » Tue 12 Jun, 2018 8:18 pm

So I think in your code you want the following:
// Dither subtract value
drb= ((int)(15 - dither_matrix_4x4[((y)<<2) + x])>>1);
dg= ((int)(15 - dither_matrix_4x4[((y)<<2) + x])>>2);
// Add subtract value
rb = i + drb;
Seems counter intuitive to add the subtract value but I think the math works out.
Note that the dither matrix columns are selected by x and the rows by y.
Last edited by tedgreen on Tue 12 Jun, 2018 9:30 pm, edited 1 time in total.

tedgreen
Posts: 6
Joined: Mon 11 Jun, 2018 11:57 pm

Re: [Patch] 3dfx rendering accuracy

Post by tedgreen » Tue 12 Jun, 2018 9:10 pm

Interesting, the formula I gave causes overflow for rb values of 255 (when RGB565 rb =31) but otherwise works out.

User avatar
leilei
Posts: 553
Joined: Fri 25 Apr, 2014 4:47 pm

Re: [Patch] 3dfx rendering accuracy

Post by leilei » Wed 13 Jun, 2018 5:46 am

Here's what that code looks like
dithersubhm.png
dithersubhm.png (4.45 KiB) Viewed 420 times
Seems to be adding more dither than the reverse...

tedgreen
Posts: 6
Joined: Mon 11 Jun, 2018 11:57 pm

Re: [Patch] 3dfx rendering accuracy

Post by tedgreen » Wed 13 Jun, 2018 2:48 pm

Yeah that definitely doesn't seem right.
I have attached a dither subtraction routine that I think better balances the dither removal.
I have changed your indexing to use col selection by x and row selection by y.
The result using this routine is:
The rb (5 bit) 0 value returns values from -3 to 4 before clamping.
The rb (5 bit) 31 value returns values from 252 to 259 before clamping.
I then clamp between 0 and 255.

This still seems a little off because rb (5 bit) 31 must have come from original values beween 248 and 255.
And rb (5bit) 0 must have come from original values 0 to 7.
Attachments
dither_patch.txt
(972 Bytes) Downloaded 6 times

User avatar
leilei
Posts: 553
Joined: Fri 25 Apr, 2014 4:47 pm

Re: [Patch] 3dfx rendering accuracy

Post by leilei » Wed 13 Jun, 2018 10:26 pm

Here's what that looks like...
new.png
new.png (4.13 KiB) Viewed 347 times
I undid your x and y swap and...
newnew.png
newnew.png (4.23 KiB) Viewed 347 times
Getting warmer!

tedgreen
Posts: 6
Joined: Mon 11 Jun, 2018 11:57 pm

Re: [Patch] 3dfx rendering accuracy

Post by tedgreen » Thu 14 Jun, 2018 12:12 am

Could you try changing the:
rb += 4;
g += 2;
To:
rb += 0;
g += 0;
and also:
rb += 8;
g += 4;

That should move around the centering of the dithering.

tedgreen
Posts: 6
Joined: Mon 11 Jun, 2018 11:57 pm

Re: [Patch] 3dfx rendering accuracy

Post by tedgreen » Thu 14 Jun, 2018 12:21 am

Looking near the bottom where the horizontal purple meets the grey and also the bottom left corner of the green and black it almost looks like there is a y flipping being done.
You could try reversing the order of the colums (I guess y is choosing columns) in the de-dithering matrix.

Post Reply