Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075927 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 03:57:38 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Texture tiles question
Pages: [1]
Print
Author Topic: Texture tiles question  (Read 1189 times)
Charybdis
Level 1
*


View Profile WWW Email
« on: June 29, 2011, 04:58:45 PM »

I have a small technical question regarding packing tiles into textures.
Let's say we have a 128x128 texture, with four 64x64 tiles.
So the first tile has tex coords <0,0><0.5,0.5>
When rendering with nearest filtering there is no problem. But if I want to use linear filtering, the pixel value will take contributions from texels outside the limits and there will be edge colour bleeding.
What I did for T2DAOROC was to pull the texture coordinates in by half a texel. So the first tile tex coords will become <0.015625,0.015625><0.484375,0.484375>
Then I would render sprites with the aforementioned tiles onscreen with a size of 63x63.
(the sprites can scale, rotate and are not constraned to discrete pixel coordinates)
I would like to know if this is the best thing to do. Are there other ways to deal with this? It must be a fairly common problem.
Most sprites are designed to have a border of transparent pixels to eliminate the problem, but the background tiles need to be fully opaque.
And I haven't even mentioned mipmapping...
Does anyone know of any good resources that I can read about this topic?
Anyway, thanks for reading and I hope I have made the problem clear enough.

Logged

ThemsAllTook
Moderator
Level 10
******


Alex Diener


View Profile WWW
« Reply #1 on: June 30, 2011, 08:52:36 AM »

Most sprites are designed to have a border of transparent pixels to eliminate the problem, but the background tiles need to be fully opaque.

Instead of transparency, you could extend the pixels at the edges of each tile, so essentially you'd have one pixel's worth of GL_CLAMP_TO_EDGE baked into the texture. Of course, this means you can no longer fit four 64x64 tiles into a 128x128 texture...

I've never really found a satisfactory solution to this myself. Maybe you could do it with some fragment shader trickery?
Logged
Charybdis
Level 1
*


View Profile WWW Email
« Reply #2 on: June 30, 2011, 10:21:41 AM »

Yeah, I doubt there is a perfect solution. Unfortunately fragment shaders are not always available. I guess the best solution would be to repeat borders like you suggested and have 62x62 tiles instead. Come to think of it, that doesn't sound too bad at all.
Logged

dcarrigg
Level 0
***

Software Neurosurgeon


View Profile WWW Email
« Reply #3 on: June 30, 2011, 10:43:54 PM »

When we pack images into an atlas, we leave a small border between them to eliminate the issue.

Pretty simple and straight forward, and doesn't have any downsides that I can think of.

-Dave
Logged

Check it out! www.retroaffect.com
Charybdis
Level 1
*


View Profile WWW Email
« Reply #4 on: June 30, 2011, 11:16:34 PM »

When we pack images into an atlas, we leave a small border between them to eliminate the issue.

Pretty simple and straight forward, and doesn't have any downsides that I can think of.

-Dave

Thanks for the reply.
Certainly if the tile is something like a character sprite, then it will have alpha round the edge, hence no problem.
However, the main reason for my original post was because fully opaque tiles, with linear filtering, subject to scaling and rotation WILL get unwanted contributions along the border.
Therefore I think ThemsAllTook's suggestion of doubling edge pixels is a neccessity in this situation.
Logged

Netsu
Level 10
*****


proficient at just chillin'


View Profile WWW
« Reply #5 on: July 01, 2011, 12:11:04 AM »

Certainly if the tile is something like a character sprite, then it will have alpha round the edge, hence no problem.

Unfortunately, sprites with alpha around the edge have their own problem:
http://forums.tigsource.com/index.php?topic=20103.0
http://forums.tigsource.com/index.php?topic=19619.0
Logged

Charybdis
Level 1
*


View Profile WWW Email
« Reply #6 on: July 01, 2011, 02:07:15 AM »

Hi Netsu
Thats second thread is mine, relating to an earlier problem I had, similar to yours. I completely solved it using premulitplied alpha.
There was a healthy debate, and others disagreed, but all I can say is that it is the perfect solution for me.
If you haven't tried it yet, I heartily recommend it. I cant sing its praises enough. And it's just so simple.

By the way, Netsu in japanese means "fever". Is that what your name means? Just curious
Logged

Netsu
Level 10
*****


proficient at just chillin'


View Profile WWW
« Reply #7 on: July 01, 2011, 02:44:15 AM »

Holy shit, I fail at interwebs. Wanted to show you those threads now so you won't have to wonder what's wrong when you encounter those problems and haven't even noticed that the thread with the solution is actually yours Durr...?
I used precomputed alpha too and worked like a charm, your thread helped me a lot.

Yeah, Netsu is a japanese word but I had no idea that it is when I choose it to be my nickname. I was 8 years old, and just thought it sounds cool, it kinda stuck since then :D
Logged

Charybdis
Level 1
*


View Profile WWW Email
« Reply #8 on: July 01, 2011, 03:22:17 AM »

I heard about premultiplied alpha when I was working on PS3. But I never looked into it too deeply. Now that I am an indie developer, I am learning so many new things that I used to take for granted. It's so much fun. I love learning tiny new things that just work.
I make iPhone games but I do all my development on PC with my cross platform system. It's just the way I came to it. Apple's iOS stuff uses premultipled alpha, and now that I use it also, my PC screenshots look exactly as they do on iphone. Before, I had to take screenshots and videos from the Mac, but now I can take them from PC too. Its a lot easier for me.
Logged

dcarrigg
Level 0
***

Software Neurosurgeon


View Profile WWW Email
« Reply #9 on: July 01, 2011, 10:09:05 AM »

Certainly if the tile is something like a character sprite, then it will have alpha round the edge, hence no problem.
However, the main reason for my original post was because fully opaque tiles, with linear filtering, subject to scaling and rotation WILL get unwanted contributions along the border.
Therefore I think ThemsAllTook's suggestion of doubling edge pixels is a neccessity in this situation.

Tiles typically have some alpha around them in the actual art. The border I'm talking about is an additional border in the atlases themselves. This way, when you do your linear filtering it will be blending with transparent pixels instead of adjacent art in the atlas.

-Dave
Logged

Check it out! www.retroaffect.com
Charybdis
Level 1
*


View Profile WWW Email
« Reply #10 on: July 01, 2011, 03:42:12 PM »

Certainly if the tile is something like a character sprite, then it will have alpha round the edge, hence no problem.
However, the main reason for my original post was because fully opaque tiles, with linear filtering, subject to scaling and rotation WILL get unwanted contributions along the border.
Therefore I think ThemsAllTook's suggestion of doubling edge pixels is a neccessity in this situation.

Tiles typically have some alpha around them in the actual art. The border I'm talking about is an additional border in the atlases themselves. This way, when you do your linear filtering it will be blending with transparent pixels instead of adjacent art in the atlas.

-Dave

Yes, that solves the unwanted blending with adjacent tiles and for most situations it will be sufficient. But in the case of using the tiles in a 2D grid, for a tiled background, ugly cracks will appear betwen tiles where pixels get a transparent contribution.
Back to my original post, what are the downsides to pulling the texture coordinated in half a texel? Can anyone explain to me at the pixel level what this will do?
Logged

Nix
Level 10
*****



View Profile
« Reply #11 on: July 01, 2011, 08:49:30 PM »

Certainly if the tile is something like a character sprite, then it will have alpha round the edge, hence no problem.
However, the main reason for my original post was because fully opaque tiles, with linear filtering, subject to scaling and rotation WILL get unwanted contributions along the border.
Therefore I think ThemsAllTook's suggestion of doubling edge pixels is a neccessity in this situation.

Tiles typically have some alpha around them in the actual art. The border I'm talking about is an additional border in the atlases themselves. This way, when you do your linear filtering it will be blending with transparent pixels instead of adjacent art in the atlas.

-Dave

Yes, that solves the unwanted blending with adjacent tiles and for most situations it will be sufficient. But in the case of using the tiles in a 2D grid, for a tiled background, ugly cracks will appear betwen tiles where pixels get a transparent contribution.
Back to my original post, what are the downsides to pulling the texture coordinated in half a texel? Can anyone explain to me at the pixel level what this will do?


I can't cite where I read this because I've forgotten, but from my understanding, half-texel offsets are more or less the correct (and cleanest) way of accomplishing this.
Logged
Charybdis
Level 1
*


View Profile WWW Email
« Reply #12 on: July 02, 2011, 12:01:28 AM »

I can't cite where I read this because I've forgotten, but from my understanding, half-texel offsets are more or less the correct (and cleanest) way of accomplishing this.

Thanks, that gives me hope. Can anyone confirm this? I'd really love to see a paper on this topic.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic