Page 1 of 1

Palette Shader - A Rachael-Belmondo Production

Posted: Sun Feb 06, 2022 1:24 am
by DenisBelmondo
Image
Mode: checkerboard dither, Square size: 4, Diffusion Bias: 0.5



welcome...... to the world of true fake 8-bit randering......

Hello all, this is my own fork of Rachael's palette shader mod, which leveraged a trick I discovered that makes the engine downmix a truecolor LUT to the colors contained in the current PLAYPAL for use as a sampler. An explanation of the trick can be found in the spoiler below. The benefit of using this trick over using the builtin palette tonemap shader is that the programmer now has nearly full control over how the downmixed image should look, including the ability to perform dithering between shades in the game palette or gracefully blending the colors.

Features:
Download/GitHub: https://github.com/DenisBelmondo/8bit



2024 update:
DenisBelmondo wrote: Wed May 01, 2024 11:55 pm Hello all! Sorry for the bump, but I've updated this mod with the following changes:
  • Updated to use PPShader instead of the now-deprecated Shader.
  • Shader is now actually disabled when turned off.
  • And most importantly, I've added LCH blending. Blending in a more perceptually uniform color space yields some really pretty results.
An explanation of the LCH blend modes:
  • LCH Color: performs blending on the Chroma and Hue channels.
  • LCH Chroma: performs blending only on the Chroma channel.
  • LCH Hue: performs blending only on the Hue channel.
Below are some demonstrations of the LCH hue blending mode. I turned the gamma up to 1.5 to better highlight its characteristics.
Spoiler: LCH blending screenshots
Much of the implementation was borrowed from nmz at shadertoy in their brilliant demonstration here: https://www.shadertoy.com/view/lsdGzN.

Spoiler: old post + explanation

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.

Re: SoftShade - Palette-Friendly Dithering v0.9

Posted: Fri Dec 23, 2022 3:55 pm
by DenisBelmondo
Hello all, sorry for the bump.

As some of you may have read, Rachael has her own implementation of this technique available in her own thread. Because it's superior, has a bigger LUT, and more flexible than mine, I decided to fork her version with my own features that include: saving CVars and a choice of when the shader should be enabled in the post processing chain which you can find here. Happy holidays!!!!!

Re: Palette Shader - A Rachael-Belmondo Production

Posted: Fri Dec 23, 2022 10:44 pm
by Rachael
Awesome work! :)

Re: Palette Shader - A Rachael-Belmondo Production

Posted: Wed May 01, 2024 11:55 pm
by DenisBelmondo
Hello all! Sorry for the bump, but I've updated this mod with the following changes:
  • Updated to use PPShader instead of the now-deprecated Shader.
  • Shader is now actually disabled when turned off.
  • And most importantly, I've added LCH blending. Blending in a more perceptually uniform color space yields some really pretty results.
An explanation of the LCH blend modes:
  • LCH Color: performs blending on the Chroma and Hue channels.
  • LCH Chroma: performs blending only on the Chroma channel.
  • LCH Hue: performs blending only on the Hue channel.
Below are some demonstrations of the LCH hue blending mode. I turned the gamma up to 1.5 to better highlight its characteristics.
Spoiler: LCH blending screenshots
Much of the implementation was borrowed from nmz at shadertoy in their brilliant demonstration here: https://www.shadertoy.com/view/lsdGzN.