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 » Sat Apr 20, 2019 8: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
 
Posts: 709
Joined: Thu Aug 12, 2010 1:17 pm
Location: Spain
Version: next
OS: Fedora

Re: Skydome dithering

Postby legoboyvdlp » Sat Apr 20, 2019 8: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: 7981
Joined: Sat Jul 26, 2014 2:28 am
Location: Northern Ireland
Callsign: G-LEGO
Version: next
OS: Windows 10 HP

Re: Skydome dithering

Postby Isaak » Sat Apr 20, 2019 9: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!
Want to support medical research with your pc? Start Folding at Home and join team FlightGear!
Isaak
 
Posts: 768
Joined: Sat Jun 04, 2011 3:52 pm
Location: Hamme, Belgium
Pronouns: he, him
Callsign: OO-ISA
Version: next
OS: Windows 10

Re: Skydome dithering

Postby icecode » Sun Apr 21, 2019 12:06 pm

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
 
Posts: 709
Joined: Thu Aug 12, 2010 1:17 pm
Location: Spain
Version: next
OS: Fedora

Re: Skydome dithering

Postby Thorsten » Sun Apr 21, 2019 12:11 pm

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: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Skydome dithering

Postby icecode » Sun Apr 21, 2019 12:51 pm

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
 
Posts: 709
Joined: Thu Aug 12, 2010 1:17 pm
Location: Spain
Version: next
OS: Fedora

Re: Skydome dithering

Postby Thorsten » Sun Apr 21, 2019 4: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: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Skydome dithering

Postby wlbragg » Sun Apr 21, 2019 6: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 and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070


Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 6 guests