Board index FlightGear Development Effects and shaders

Skydome dithering

An exciting "new" option in FlightGear, that includes reflections, lightmaps, the particle system etc.. A lot is yet to be discovered/implemented!

Skydome dithering

Postby Icecode GL » Sat Apr 20, 2019 7:39 pm

While working on shadow mapping I've been investigating dithering and its applications. It was mainly used back in the day to display high bit depth images in low bit depth displays, although it can still be used today for that same thing. The skydome suffers from banding because the framebuffer only has a bit depth of 8 per color, while floats in the shader have a much higher resolution, so some loss of precision is happening. This can be prevented by randomly rounding up and down to the next available color in the display. The random factor used can be as simple as a one-liner noise function or some fancy blue noise texture. I just used the rand2D() from Thorsten's noise functions as it outputs a good enough result.

This could be done as a post-processing effect so it affects every object in the scene, but banding is mostly perceived only on the skydome, so this is a good enough fix for now.

Before:
Image

After:
Image

And the code to add just before gl_FragColor and after filter_combined() in skydome-ALS.frag:
Code: Select all
float dither_noise = rand2D(gl_FragCoord.xy);
color += mix(-0.5/255.0, 0.5/255.0, dither_noise);
Icecode GL
 
Posts: 506
Joined: Thu Aug 12, 2010 12:17 pm
Location: Spain
Callsign: icecode
Version: GIT
OS: Arch Linux

Re: Skydome dithering

Postby legoboyvdlp » Sat Apr 20, 2019 7:54 pm

It took a minute or two to see the difference but when I saw it while very subtle it really helps.
User avatar
legoboyvdlp
 
Posts: 6706
Joined: Sat Jul 26, 2014 1:28 am
Callsign: YV-LEGO
Version: 2018.3.1
OS: Windows 10 HP

Re: Skydome dithering

Postby Isaak » Sat Apr 20, 2019 8:14 pm

I 've seen banding appear in the skydome quite often (especially at dusk or dawn), and this looks like a good solution for it. Nice work!
Isaak
 
Posts: 405
Joined: Sat Jun 04, 2011 2:52 pm
Location: Leuven, Belgium
Callsign: OO-ISA
Version: 2019.1.1
OS: Windows 10

Re: Skydome dithering

Postby Icecode GL » Sun Apr 21, 2019 11:06 am

It took a minute or two to see the difference but when I saw it while very subtle it really helps.


It depends a lot on the brightness of your monitor or darkness in your room. I usually keep my monitor very bright so it's very noticeable in my case.


I've also thought of adding that code to filter_combined() instead so it affects every object, but that's Thorsten's call if he wants to merge the changes.
Icecode GL
 
Posts: 506
Joined: Thu Aug 12, 2010 12:17 pm
Location: Spain
Callsign: icecode
Version: GIT
OS: Arch Linux

Re: Skydome dithering

Postby Thorsten » Sun Apr 21, 2019 11:11 am

I approve of course - seems so simple to do, and yet it never occurred to me... I'm not sure - if you have commit rights you can put it in yourself, otherwise I'll try to do it (soonish).

I see the banding for the skydome, I'm less sure about other elements - do you have a comparison?
Thorsten
 
Posts: 10638
Joined: Mon Nov 02, 2009 8:33 am

Re: Skydome dithering

Postby Icecode GL » Sun Apr 21, 2019 11:51 am

I don't have commit rights but if you prefer I can do a merge request.

Everything has banding since shaders do their calculations with more precision than what the framebuffer allows. It's there but it's much harder to notice since there aren't many objects with plain gradients like the skydome. Although we can modify the skydome only if you prefer.
Icecode GL
 
Posts: 506
Joined: Thu Aug 12, 2010 12:17 pm
Location: Spain
Callsign: icecode
Version: GIT
OS: Arch Linux

Re: Skydome dithering

Postby Thorsten » Sun Apr 21, 2019 3:58 pm

I guess the cleanest implementation is to put it into the post-processing filter, so let's do that, and a merge request would be fastest for me since I can just okay that via the SF web interface, otherwise I need to update my repo copy on the right computers etc...
Thorsten
 
Posts: 10638
Joined: Mon Nov 02, 2009 8:33 am

Re: Skydome dithering

Postby wlbragg » Sun Apr 21, 2019 5:30 pm

Everything has banding since shaders do their calculations with more precision than what the framebuffer allows.

I see what looks like banding in transparency (glass). Maybe that is something different? It would be nice if this helps to clear that up.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4682
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640


Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 0 guests