How to get rid of banding effect on gradient background

Anything libgdx related goes here!

How to get rid of banding effect on gradient background

Postby Logisk » Tue Jan 08, 2019 5:24 am

I don't know if I can just post a stackoverflow link instead of detailing the issue in here but here it is. Any idea on how I could fix this?
Logisk
 
Posts: 8
Joined: Sun Aug 19, 2018 1:58 am

Re: How to get rid of banding effect on gradient background

Postby obigu » Tue Jan 08, 2019 12:13 pm

Try generating the gradient like suggested here https://www.badlogicgames.com/forum/vie ... =11&t=9361
obigu
 
Posts: 117
Joined: Fri Aug 02, 2013 4:47 pm

Re: How to get rid of banding effect on gradient background

Postby Magnesus » Tue Jan 08, 2019 7:27 pm

Haven't looked at the thread linked above but if that solution doesn't help try adding some dithering to your gradient so it isn't just bands of color one after another - most screens nowadays are not good at displaying clean gradients unfortunately.
Magnesus
 
Posts: 1654
Joined: Sun Sep 25, 2011 3:50 pm

Re: How to get rid of banding effect on gradient background

Postby Logisk » Tue Jan 08, 2019 10:48 pm

obigu wrote:Try generating the gradient like suggested here https://www.badlogicgames.com/forum/vie ... =11&t=9361

I will try that and update with the results.

Magnesus wrote:Haven't looked at the thread linked above but if that solution doesn't help try adding some dithering to your gradient so it isn't just bands of color one after another - most screens nowadays are not good at displaying clean gradients unfortunately.

I tried that, unfortunately, it didn't help.

On a side note, I noticed in the AndroidGraphics.java class, there is a bufferFormat initialized with
Code: Select all
private BufferFormat bufferFormat = new BufferFormat(5, 6, 5, 0, 16, 0, 0, false);

Could that be the issue? I'm not sure what exactly the BufferFormat do but I wonder if having (r,g,b,a) be (8,8,8,8) instead of the current (5,6,5,0) would change anything.
Logisk
 
Posts: 8
Joined: Sun Aug 19, 2018 1:58 am

Re: How to get rid of banding effect on gradient background

Postby Magnesus » Fri Jan 11, 2019 9:52 am

If dithering doesn't help then most likely you are not using 888. Not sure about bufferFormat but something in your drawing code must be using 565. Are you using framebuffer or a pixmap? Make sure they are 888.
Magnesus
 
Posts: 1654
Joined: Sun Sep 25, 2011 3:50 pm

Re: How to get rid of banding effect on gradient background

Postby Logisk » Sat Jan 12, 2019 5:14 pm

Magnesus wrote:If dithering doesn't help then most likely you are not using 888. Not sure about bufferFormat but something in your drawing code must be using 565. Are you using framebuffer or a pixmap? Make sure they are 888.


This is what I use to generate the background. I create an Image actor with the texture and scale it to fill the stage.
Code: Select all
Pixmap pix = new Pixmap(2, 2, Pixmap.Format.RGBA8888);
pix.setColor(colorSchemes[index].getTopColor());
pix.fillRectangle(0,0,2,1);
pix.setColor(colorSchemes[index].getBottomColor());
pix.fillRectangle(0,1,2,1);

Texture texture = new Texture(pix);
texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
pix.dispose();

Image background = new Image(new TextureRegionDrawable(new TextureRegion(texture)), Scaling.stretch);
Logisk
 
Posts: 8
Joined: Sun Aug 19, 2018 1:58 am

Re: How to get rid of banding effect on gradient background

Postby Magnesus » Sun Jan 13, 2019 8:53 am

Ah, so you are stretching extemely small texture to the size of the screen - the resulting quality will depend on the GPU scaling method in that case. Maybe generate a larger one, line by line and don't stretch it that much?

I would probably make a texture/pixmap with width set to 1 or 2 and height the height of the screen (or at least 256). Then draw pixels or lines calculating the color for each line onto that texture/pixmap.
Magnesus
 
Posts: 1654
Joined: Sun Sep 25, 2011 3:50 pm


Return to Libgdx

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest