Palette Shader - A Rachael-Belmondo Production

Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
Post Reply
User avatar
DenisBelmondo
Posts: 381
Joined: Fri Jun 06, 2008 6:26 pm
Location: Two-Key Return
Contact:

Palette Shader - A Rachael-Belmondo Production

Post 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
Last edited by DenisBelmondo on Thu Aug 15, 2024 2:31 pm, edited 8 times in total.
User avatar
Rachael
Posts: 13923
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: SoftShade - Palette-Aware Dithering v0.9

Post 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.
User avatar
DenisBelmondo
Posts: 381
Joined: Fri Jun 06, 2008 6:26 pm
Location: Two-Key Return
Contact:

Re: SoftShade - Palette-Aware Dithering v0.9

Post 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.
User avatar
Rachael
Posts: 13923
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: SoftShade - Palette-Aware Dithering v0.9

Post 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.
User avatar
DenisBelmondo
Posts: 381
Joined: Fri Jun 06, 2008 6:26 pm
Location: Two-Key Return
Contact:

Re: SoftShade - Palette-Friendly Dithering v0.9

Post 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
User avatar
Rachael
Posts: 13923
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: SoftShade - Palette-Friendly Dithering v0.9

Post 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)
User avatar
Nash
 
 
Posts: 17487
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: SoftShade - Palette-Friendly Dithering v0.9

Post by Nash »

I may use this in a future project. :) DenisBelmondo, what's the license on this?
User avatar
Marisa the Magician
Banned User
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia
Contact:

Re: SoftShade - Palette-Friendly Dithering v0.9

Post by Marisa the Magician »

Ah, that's a very clever thing to do.
User avatar
DenisBelmondo
Posts: 381
Joined: Fri Jun 06, 2008 6:26 pm
Location: Two-Key Return
Contact:

Re: SoftShade - Palette-Friendly Dithering v0.9

Post 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" (:
Gez
 
 
Posts: 17938
Joined: Fri Jul 06, 2007 3:22 pm

Re: SoftShade - Palette-Friendly Dithering v0.9

Post 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?
Attachments
palcolor.7z
This .7z is actually larger than the .lmp it contains, but the extension .lmp is not allowed.
(463 Bytes) Downloaded 202 times
User avatar
Rachael
Posts: 13923
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: SoftShade - Palette-Friendly Dithering v0.9

Post 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.
User avatar
DenisBelmondo
Posts: 381
Joined: Fri Jun 06, 2008 6:26 pm
Location: Two-Key Return
Contact:

Re: SoftShade - Palette-Friendly Dithering v0.9

Post 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!!!!!
User avatar
Rachael
Posts: 13923
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Palette Shader - A Rachael-Belmondo Production

Post by Rachael »

Awesome work! :)
User avatar
DenisBelmondo
Posts: 381
Joined: Fri Jun 06, 2008 6:26 pm
Location: Two-Key Return
Contact:

Re: Palette Shader - A Rachael-Belmondo Production

Post 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.
Post Reply

Return to “Shaders”