Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LibGDX - Gradient looks weird?  (Read 940 times)
0 Members and 1 Guest are viewing this topic.
Offline ddfh

Junior Devvie


Medals: 1



« Posted 2013-04-25 15:55:03 »

Hi,

I added a 3D cube. On this 3D cube is a gradient texture. When I start my app,
the gradient looks like this here:

(second image)
http://stackoverflow.com/questions/13478116/android-gradient-weirdness

I added this code to my main activity. Code is not working!
1  
2  
3  
4  
5  
6  
7  
8  
9  
        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.useGL20 = false;

        cfg.r = 8;
        cfg.g = 8;
        cfg.b = 8;
        cfg.a = 8;

        initialize(new Game(), cfg);
Offline davedes
« Reply #1 - Posted 2013-04-25 17:54:05 »

Are you using RGBA8888 format for your textures?

Offline ddfh

Junior Devvie


Medals: 1



« Reply #2 - Posted 2013-04-26 06:09:52 »

Yes. I added the RGBA8888 to the texture. Not working.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 113
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2013-04-26 17:01:50 »

Are you using RGBA8888 format for your textures?

His problem is not, that the gradients aren't working, they only look bad (as judged from the second image of the link he gave).

I'd like to help you, ddfh, but there is no easy solution for this problem.

It technically is a gradient... but the color difference between two gradient regions (which are bigger than 1 px) makes it look aweful.
Consider this: You want a gradient from (an imaginary) color 255 to 250 over 20 pixels... in the end this will be the color values:
255 255 255 255 254 254 254 254 253 253 253 253 252 252 252 252 251 251 251 251 250 250 250 250

In the image in the end your eye will recognize those jumps from one color region to another, for example from 255 to 254, because each of those actually is a region (4 px wide).

How the gradient was made in the 1st image of your link is a little trick. We trick our brain / eye not to recognize any patterns. How are we doing that? We randomize. so you add or subtract 1 or 2 color values from each pixel and randomize each pixel a bit.
What you then have is this:
255 256 255 254 255 253 254 253 254 253 253 252 252 251 251 252 251 250 251 250
(^ randomized through some scala code:
1  
for (i <- 0 until 20) { print(s"${(math.random * 4 - 2).toInt + 255-(i/4).toInt} ") }

not necessary for you to understand that code (since it's scala anyways), only that randomization plays a role)

As you can see, now you can't see regions with same values anymore. In the end the values get smaller if you go from left to right, but you still can't see any (so called) "banding".

That's how you trick your eye to make a gradient look good.


Now... How would you apply that to your game / gradient in android?

I'd do it with glsl shaders and add a little random noise to every pixel (even when not being a gradient. It won't be visible anyways).
But shaders is another story.
Let alone random values inside a shader...

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline ddfh

Junior Devvie


Medals: 1



« Reply #4 - Posted 2013-04-27 06:45:56 »

Thanks!
Offline Roquen
« Reply #5 - Posted 2013-04-27 07:15:21 »

If we were talking 555 or 565 then sure, but 888? No.
Offline noblemaster

« JGO Spiffy Duke »


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #6 - Posted 2013-04-29 03:10:57 »

OpenGL on Android might use 575 when rendering! It doesn't matter if you set it to use 888. However, you can try to enable dithering (GL_DITHER?) and see if that helps?

Offline Roquen
« Reply #7 - Posted 2013-04-29 06:16:51 »

16-bit!!??!  Eee-gads...the horror!  Yeah, enable dithering.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (71 views)
2014-11-26 15:22:04

toopeicgaming1999 (60 views)
2014-11-26 15:20:36

toopeicgaming1999 (14 views)
2014-11-26 15:20:08

SHC (27 views)
2014-11-25 12:00:59

SHC (25 views)
2014-11-25 11:53:45

Norakomi (31 views)
2014-11-25 11:26:43

Gibbo3771 (25 views)
2014-11-24 19:59:16

trollwarrior1 (38 views)
2014-11-22 12:13:56

xFryIx (77 views)
2014-11-13 12:34:49

digdugdiggy (55 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!