Page 1 of 1

SoftShade - Palette-Friendly Dithering v0.9

Posted: Sun Feb 06, 2022 1:24 am
by DenisBelmondo
welcome...... to the world of true fake 8-bit randering......

A mod that adds ordered dithering to your screen-device.

Image

Download

First and foremost, 80% of the implementation was blatantly lifted from Marisa Kirisame's impeccable MariFX shader suite, which contains a post processing shader that gracefully, with dithering, quantizes the fragment colors to those of a particular palette out of a finite set of palettes. In other words: if you were playing a mod that has a custom palette, those cool new shades of cerulean will not at all be present in the pre-computed Doom Palette LUT and will end up being snapped to or stippled between Doom's blue or grey. My modified implementation aims to fix that issue and fully respects the PLAYPAL lump.

[spoiler=More screenshots]Image
Image
Image
Image[/spoiler]

what the shit is this black magic

Seeing that you cannot pass PLAYPAL as a texture uniform, there's no actual way to access the palette as-is in a shader. After kicking around a few solutions, I found one that came to me like a flash of lightning. So, when ZDoom wants to translate a truecolor image, it must first convert it to an indexed image. It doesn't matter if it's a completely meaningless translation like 0:0=0:0, ZDoom will convert it. I exploited this by taking a netural color LUT, fed it into TEXTURES as a patch, and told it to have the aforementioned 0:0=0:0 translation. ZDoom perfectly creates what is essentially a LUT out of whatever array of colors PLAYPAL contains. I then fed that "composited" texture into the shader as a uniform, and from there it's cake.

This is an 0.9 release, meaning that it only goes uphill from here (: Also, It would be nice in future releases to have some kind of Floyd-Steinberg or Ylilouma style dithering. Who knows! Anyhow, hope you enjoy.

Re: SoftShade - Palette-Aware Dithering v0.9

Posted: Sun Feb 06, 2022 1:31 am
by Rachael
Interesting way to downmix the LUT - I hadn't actually thought of that. That being said - I have actually been planning a shader just like this for a couple weeks now.

Re: SoftShade - Palette-Aware Dithering v0.9

Posted: Sun Feb 06, 2022 2:09 am
by DenisBelmondo
Oh wow, if it made it in as an engine feature that would be fabulous. The existing palette shader is cool, but dithering definitely elevates it and gives it a way more slick #retro type look as well.

Re: SoftShade - Palette-Aware Dithering v0.9

Posted: Sun Feb 06, 2022 2:39 am
by Rachael
No - no engine feature for something like this. I just had a different take on how I would have done something like this.

Re: SoftShade - Palette-Friendly Dithering v0.9

Posted: Sun Feb 06, 2022 2:46 am
by DenisBelmondo
Ahhh my mistake. In any case, I'm sure I can speak on behalf of all softwareheads by saying we will willingly embrace anything that will bring us closer to that type of aesthetic :o

Re: SoftShade - Palette-Friendly Dithering v0.9

Posted: Sun Feb 06, 2022 3:05 am
by Rachael
Well - this is what I had originally planned. The only difference here is - I had originally planned on providing downmixed LUTs for every game - so instead I went with your idea (which was a LOT better) to force the downmix with an empty translation method. I was also possibly planning on doing a 3rd and 4th correction (basically a 2x2 dither) - but - this is more or less the proof of concept plus the work I had done up to the point before I saw you post this.

This uses a simple error diffusion algorithm in a checkerboard pattern. You will have to view this in a lower resolution in order to see the actual dithering.

I did this in a way that, this is also compatible with Raze.

Feel free to do whatever you want from this - if this gives you ideas to improve your's, you're welcome to use it.

(Will put it in a separate thread - it is *not* my intention to thread hijack this)

Re: SoftShade - Palette-Friendly Dithering v0.9

Posted: Sun Feb 06, 2022 10:09 am
by Nash
I may use this in a future project. :) DenisBelmondo, what's the license on this?

Re: SoftShade - Palette-Friendly Dithering v0.9

Posted: Sun Feb 06, 2022 10:59 am
by Marisa the Magician
Ah, that's a very clever thing to do.

Re: SoftShade - Palette-Friendly Dithering v0.9

Posted: Mon Feb 07, 2022 2:01 pm
by DenisBelmondo
Thanks all! I am really glad that you found it interesting or even a possible use for it.

Rachael wrote:snip


No worries Rachael, I appreciate your insight. I booted it up and it looks fantastic especially in low resolutions like you specified.

Nash wrote:I may use this in a future project. :) DenisBelmondo, what's the license on this?


Thanks for taking interest Nash! Since I borrowed from Marisa's work so liberally, I want to say the licensing is transitive. I suppose what I actually borrowed is an implementation of positioned dithering, which I think itself is public domain? In that case, I would say my license is "Public Domain but I get a real kick out of seeing my name in the credits" (:

Re: SoftShade - Palette-Friendly Dithering v0.9

Posted: Tue Feb 08, 2022 4:10 am
by Gez
DenisBelmondo wrote:what the shit is this black magic

Seeing that you cannot pass PLAYPAL as a texture uniform, there's no actual way to access the palette as-is in a shader. After kicking around a few solutions, I found one that came to me like a flash of lightning. So, when ZDoom wants to translate a truecolor image, it must first convert it to an indexed image. It doesn't matter if it's a completely meaningless translation like 0:0=0:0, ZDoom will convert it. I exploited this by taking a netural color LUT, fed it into TEXTURES as a patch, and told it to have the aforementioned 0:0=0:0 translation. ZDoom perfectly creates what is essentially a LUT out of whatever array of colors PLAYPAL contains. I then fed that "composited" texture into the shader as a uniform, and from there it's cake.


Just out of curiosity, if the aim is to have a texture with every single palette color in it, why not just use a paletted picture with every color in it? Like this one?

Re: SoftShade - Palette-Friendly Dithering v0.9

Posted: Tue Feb 08, 2022 4:11 am
by Rachael
Because then you would actually have to do colormatching. Doing a downmixed LUT means that the colormatching is already done for you beforehand.

Most modern GPU's can handle the colormatching okay but if you can avoid putting the extra work on your GPU, it's better to.

GZDoom's palette tonemap already uses this exact same technique internally - I don't know if the LUT itself is exactly the same, but it is definitely the same size as DenisBalmodo's, and it works the same way.

Providing a 256-color table like that means that you will have to actually scan the entire table for every pixel and find a closest match - and you will have to do that for every pixel on the screen. Like I said, modern GPU's can handle it - but it's definitely not desirable to do this. Especially since you'll have to pow(color, 2.2) for every match *and* every pixel with it, as well, in order to ensure the matches are in the linear colour space - that will cost a little more processing power on top of that.