[Added] Stipple (aka Dither) Shader

Moderator: GZDoom Developers

Stipple (aka Dither) Shader

Postby Rachael » Mon Aug 06, 2018 9:04 am

This shader attempts to smooth the banding that is found even in OpenGL, something which proves 8 bits per channel is too low even for GZDoom.

This shader is always on and has no configuration options. Its effect is very subtle and barely noticeable (it's more noticeable when it's not loaded, actually), so I didn't really see the need to include an on/off switch.

Basically, it is designed strictly for 24-bit displays, which have trouble at the lower colour bands showing gradients smoothly.

Both of these screenshots are doctored in such a way to attempt to show off the effect of the shader. Under normal conditions you will not see it.

Before:


After:


Before you ask, YES you are allowed to use this in your mod! (Or even your commercial game, without royalty!) There is a license that's basically, there's no warranty, and give me credit.
Attachments
stipple-shader.pk3
(1.66 KiB) Downloaded 49 times
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: Stipple (aka Dither) Shader

Postby Caligari87 » Mon Aug 06, 2018 9:29 am

This looks pretty awesome Rachael! :D I think I'm gonna try integrating it to DarkDoomZ, since that's basically all about the lower color bands.

8-)
User avatar
Caligari87
I'm just here for the community
User Accounts Assistant
 
Joined: 26 Feb 2004
Location: Salt Lake City, Utah, USA
Discord: Caligari87#3089

Re: Stipple (aka Dither) Shader

Postby Rachael » Mon Aug 06, 2018 9:31 am

Thank you, and that sounds good. :)
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: Stipple (aka Dither) Shader

Postby DabbingSquidward » Mon Aug 06, 2018 10:07 am

24 Bit as in 32 Bit = 24 Bit color + 8 Bit Alpha channel?
User avatar
DabbingSquidward
 
Joined: 08 Nov 2017
Location: Germany

Re: Stipple (aka Dither) Shader

Postby Rachael » Mon Aug 06, 2018 10:17 am

Yes. No matter what your desktop colour resolution is set to, the final result is downsampled when your monitor receives it.

It's supposed to be 24-bit, but from what I understand some monitors are often actually 18-bit and either they, or the GPU, do internal dithering of sorts to make up the difference.
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: Stipple (aka Dither) Shader

Postby Graf Zahl » Mon Aug 06, 2018 11:52 am

Too bad that 30 bit hasn't become standard yet, that'd make such things pretty much unnecessary.
In a way it reminds me at how old graphics hardware tried to 'improve' the look of 16 bit output with dithering, of course with such a low bit depth to start it was a mostly hopeless undertaking.

This one doesn't have much of an effect in bright scenes but testing with some really dark map it nearly completely removes the banding. I'm all in favor of making this an official postprocessing effect.
Last edited by Graf Zahl on Mon Aug 06, 2018 12:00 pm, edited 1 time in total.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Stipple (aka Dither) Shader

Postby Rachael » Mon Aug 06, 2018 12:00 pm

I've found even when developing this shader, that 30-bit presents a bit of banding with GZDoom. This shader simulates 36-bit which is an extremely high colour resolution, that seems to be enough to eliminate the banding, mostly.

So even when 10bpc displays start to become common, I expect I'll have to update this shader again for the new colour resolution, dividing the first line by 2048 instead of 512. But that's still much better than what we have, today. ;)

Although, I start to wonder at what point the floating point precision errors will start kicking in.
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: Stipple (aka Dither) Shader

Postby Graf Zahl » Mon Aug 06, 2018 12:01 pm

Rachael wrote:I start to wonder at what point the floating point precision errors will start kicking in.


A lot later. I think 16 bpc should be fine unless some really complex stuff gets done.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Stipple (aka Dither) Shader

Postby Rachael » Mon Aug 06, 2018 12:05 pm

This one doesn't have much of an effect in bright scenes but testing with some really dark map it nearly completely removes the banding. I'm all in favor of making this an official postprocessing effect.

This is licensed so you are free to grab it and go, you can include it in any of your projects if you want to.

I am not really sure how to implement it into GZDoom, myself, but I am looking at it.
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: Stipple (aka Dither) Shader

Postby Graf Zahl » Mon Aug 06, 2018 2:14 pm

It shouldn't be too hard. The main question is, where in the chain is the most appropriate place.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Stipple (aka Dither) Shader

Postby Rachael » Mon Aug 06, 2018 2:28 pm

Ideally, the very last place where the colour channels are still floats, before they are transmitted to the window for presentation to the user. If it can be done after the resolution scaling, that would be even better.

Also, the definition at the top of the file (right under the BSD notice) can be changed as follows:
Code: Select allExpand view
in int colourdepth;

void main()
{
   if (colourdepth == 0)
   {
      FragColor = texture(InputTexture, TexCoord);
      return;
   }
   float halfcolour = 1./float(2<<colourdepth);


This allows you to put 8 or 10 in as colourdepth - something that will allow you to set the stipple to tune to a 8bpc display or a 10bpc display. The "halfcolour" variable is the most important switch to the entire shader program that tells it how to stipple the display.
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: Stipple (aka Dither) Shader

Postby Graf Zahl » Mon Aug 06, 2018 2:45 pm

Rachael wrote:If it can be done after the resolution scaling, that would be even better.


Agreed. But that's after the application of the 2D HUD elements and I don't think that at that point any postprocessing is done. Also, if it's supposed to be done I guess it requires another intermediate buffer to first scale the image and then dither the result and not the input.

Waiting for dpJudas's input here. In any case, I think this is worth evaluating the existing options and their costs.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Stipple (aka Dither) Shader

Postby Rachael » Mon Aug 06, 2018 2:48 pm

Well, I am not hard pressed about that. If we can't get it in after the scaling, then that's how it currently works in mod form anyhow. It doesn't look as good with the scaling but, it doesn't look terrible, either.
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle
Graphics Processor: nVidia with Vulkan support

Re: Stipple (aka Dither) Shader

Postby dpJudas » Mon Aug 06, 2018 3:05 pm

The Present shader would be the natural place if it should be done post resolution scale. It can use the gl_ScreenPos variable to make it full resolution (as opposed to using UV coords). It still has the input as half-floats and outputs to the frame buffer. The catch is this is after the 2D HUD, which could maybe make the dithering more visible to the eye.

Creating a separate render buffer at full resolution before the 2D HUD will be a bit too problematic I think. So IMO its either the Present shader or like in Rachael's current implementation.
dpJudas
 
 
 
Joined: 28 May 2016

Re: Stipple (aka Dither) Shader

Postby Graf Zahl » Mon Aug 06, 2018 3:25 pm

There's actually two issues with where it is located now:

1. The aforementioned resolution scaling.
2. The screen blend which is done as the first thing in the 2D pass.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Next

Return to Closed Feature Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest