Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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  
  Bleeding  (Read 5855 times)
0 Members and 1 Guest are viewing this topic.
Offline Cero
« Posted 2012-07-10 15:56:16 »

I have different games using different libs.
However almost all of them have the same problem: Zooming causes bleeding.



Here an isometric example


So I would appreciate it if you OpenGL experts would talk about: How, when and why it happens; and also of course how to avoid it.

Offline Roquen
« Reply #1 - Posted 2012-07-10 17:17:25 »

I not sure what visual defect you're referring to.  As a guess: RGB colors even if alpha is 0 DO count, due to sampling.
Offline davedes
« Reply #2 - Posted 2012-07-10 17:30:08 »

This occurs because the filtering is set to GL_LINEAR. Bilinear filtering will select the nearest four pixels and blend them using a weighted average. As Roquen said, the RGB is blended even if the adjacent pixels have an alpha of zero.

For example, this 32x32 grass tile is located at (1, 1) on the sheet.


We see bleeding when we scale up:


This is because when GL goes to sample the edge pixels of our grass tile, it blends the grass with adjacent pixels (magenta).

The solution is to use GL_NEAREST for our sprite sheet, which only picks the "nearest" colour and doesn't blend adjacent pixels.



If the images don't need to be tiled, we could instead simply pad our sprite sheets with some transparent white pixels.

What if you need GL_LINEAR, and your sprites need to be tiled? Even if you pad the sprites, you will end up with bleeding (whatever is behind our tiles will bleed through, as it appears in your first screen shot). One hack/solution to this is to pad our sprites with pixels taken from opposing edges. The top line of pixels taken from the bottom, the left line of pixels taken from the right, etc:


The result when scaled:


This problem may also manifest itself if you're loading non-power-of-two textures with Slick/SlickUtil. In that case, Slick pads the extra dimensions (to make it power of two) with transparent black pixels. Therefore bleeding on the bottom/right edges may occur using GL_LINEAR, even if the scale is unchanged.

tl;dr - don't use GL_LINEAR

Bleeding may also occur if you are using non-power-of-two texture regions (i.e. sprites), due to floating point inaccuracies. Ideally you should stick to power-of-two where possible.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd

« JGO Bitwise Duke »


Medals: 365
Projects: 2
Exp: 8 years



« Reply #3 - Posted 2012-07-11 00:02:33 »

If you're okay with limiting yourself to OpenGL 3+ cards you could just use a 2D texture array to hold the tiles. It's basically a 3D texture, but it won't interpolate between layers, meaning that you can create a 32x32xNUM_TILES texture array, and it magically works with filtering, mipmaps, etc since you can just enable GL_CLAMP_TO_EDGE.

Myomyomyo.
Offline Cero
« Reply #4 - Posted 2012-07-11 00:45:01 »

If you're okay with limiting yourself to OpenGL 3+ cards...

Of course not. >_>

Offline davedes
« Reply #5 - Posted 2012-07-11 00:52:50 »

Many older cards support texture arrays through extension (GL_EXT_texture_array). My OpenGL 2.1 card supports it.

Offline matheus23

JGO Kernel


Medals: 114
Projects: 3


You think about my Avatar right now!


« Reply #6 - Posted 2012-07-11 17:13:00 »

Cero is rage-appreciating here Cheesy [Note: this is an unrelevant post, which is not necessary. This is also not edited Tongue ]

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

Senior Devvie


Medals: 4
Projects: 3



« Reply #7 - Posted 2012-07-11 23:52:50 »

Hi we had some problems with sprites, where the borders where looking ugly so we made a tool that bleeds the colors of the opaque pixels into the transparent ones, the pixels that are not 100% transparent are not changed, but the transparent pixels get the color of the neighouring pixels. This fixes the interpolation error that usually happens in those pixels.

The tool does this:

 the left image is the original one rendered over a red background, the middle one is the result with alpha disabled, and the right one is the result image rendered over a red background with alpha enabled.

The projects is available here: https://github.com/gemserk/imageprocessing and there is a runnable jar in the downloads section.

If you have any question feel free to ask.

Offline Cero
« Reply #8 - Posted 2012-07-12 01:29:19 »

Cero is rage-appreciating here :D [Note: this is an unrelevant post, which is not necessary. This is also not edited :P ]

I saw someone appreciating posts in this thread that wasn't me - even though it was my question and I even say I would appreciate it. SO I figured, I gotta use that feature more often ;D


Quote

Looks like its rather for sprites than tiles

For tiles its more complicated...
Padding seems to work, however, I have of course build an entire game around these existing tilesets.
So we going to try to use texture arrays...

Offline theagentd

« JGO Bitwise Duke »


Medals: 365
Projects: 2
Exp: 8 years



« Reply #9 - Posted 2012-07-12 17:48:18 »

@ruben01
That looks great! Even if it isn't perfect it's 100x better than nothing!

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline JFixby
« Reply #10 - Posted 2013-02-23 19:33:24 »

Here is merge of the the gemserk's source code with the available source code of the TexturePacker: http://jfix.by/wp-content/uploads/2013/02/TexturePackerGemserk.zip

(+ explanatory blog-post http://jfix.by/2013/02/23/opengl-filters/)




my dev log: http://jfix.by/
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.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (75 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

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

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

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!