• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
grasshop

Texture Interpolation Problem With Transparent Pixels

10 posts in this topic

Hi,

Can somebody please tell me how I can stop texture interpolation from interpolating with fully transparent pixels? I am just using this code for interpolation:

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

At the moment my sprites that use transparency all have unnaturally coloured edges to them when I use interpolation, which isn't pretty :)

Thanks.
0

Share this post


Link to post
Share on other sites
You can't selectively interpolate some texels and not others.
However, this doesn't have to be a problem. If you make all of your transparent pixels black, and then use the "pre-multiplied alpha" blend mode ([i]i.e. [/i][font=courier new,courier,monospace][i]src=1, dst=1-srcAlpha[/i][/font]), there won't be any artefacts around the edges.
0

Share this post


Link to post
Share on other sites
Thanks for the info. Is there though any shaders I could use to deal with this? Edited by grasshop
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1347168933' post='4978186']
You can't selectively interpolate some texels and not others.
However, this doesn't have to be a problem. If you make all of your transparent pixels black, and then use the "pre-multiplied alpha" blend mode ([i]i.e. [/i][font=courier new,courier,monospace][i]src=1, dst=1-srcAlpha[/i][/font]), there won't be any artefacts around the edges.
[/quote]

Interesting, I have the same problem. Please help me understand how it works (I am using pre multiple alpha already).
[attachment=11170:TransparentArtifacts_2012-09-09.jpeg]
It is the sampling from the texture that will get a bad color, isn't it? So a position between a white non transparent pixel and a black transparent pixel would become gray 50% transparent? If so, using pre multiplied alpha won't help as long as the colors are wrong?

There is another possibility: Using mipmaps, but you have to create the mipmaps yourself. That way, you can use an averaging algorithm that ignores transparent pixels. Edited by larspensjo
0

Share this post


Link to post
Share on other sites
[quote name='larspensjo' timestamp='1347177365' post='4978204']
It is the sampling from the texture that will get a bad color, isn't it? So a position between a white non transparent pixel and a black transparent pixel would become gray 50% transparent? If so, using pre multiplied alpha won't help as long as the colors are wrong?
[/quote]Yes, so if we've got two pixels A=(1,1,1,1) and B=(0,0,0,0), then sampling exactly between them gives S=A*0.5+B*0.5, or S=(0.5, 0.5, 0.5, 0.5).
For example, let's say the background is light green: G=(0.5, 1, 0.5).
With regular alpha blending ([font=courier new,courier,monospace][i]src=srcAlpha, dst=1-srcAlpha[/i][/font]), we get:
S*0.5 + G*0.5
=(0.25, 0.25, 0.25) + (0.25, 0.5, 0.25)
=(0.5, 0.75, 0.5) <- darker than the original background, hence the black outline around the sprite.

With premultiplied alpha blending ([font=courier new,courier,monospace][i]src=1, dst=1-srcAlpha[/i][/font]), we get:
S + G*0.5
=(0.5, 0.5, 0.5) + (0.25, 0.5, 0.25)
=(0.75, 1, 0.75) <- brighter than the original background, no black outline any more.
[quote name='larspensjo' timestamp='1347177365' post='4978204'](I am using pre multiple alpha already)[/quote]What does the code for setting your blend mode look like? Edited by Hodgman
1

Share this post


Link to post
Share on other sites
[quote name='grasshop' timestamp='1347186431' post='4978241']Can I just ask, does DirectX suffer from this same issue?[/quote]
Yes. There isn't really an issue ("issue" as in "fault") here - GL/DX do what you tell them to.
Bilinear filtering tells the GPU to blend together the nearest 4 pixels. If the RGB values of your 'transparent' pixels are wrong, then this blending won't work.[quote]Is there any shaders I could use to deal with this?[/quote]Well, you could disable the GPU's bilinear filtering and instead re-invent it yourself in the pixel shader. You'd have to take 4 nearest-filtered samples ([i]from the 4 texels closest to the UV coord[/i]), calculate the regular bilinear weights as usual, but then set the weights of any transparent pixels to 0 and renormalize the remaining weights.
This would be a lot more complex and a lot slower than just ensuring that your transparent pixels are black.
0

Share this post


Link to post
Share on other sites
The problem is I don't actually have any control over anything myself as I am working on a user game development environment and the user could use any textures themselves and call upon any blend functions as well to that matter. I ask about DirectX because this problem doesn't occur in another game development environment which I am actually trying to emulate and it uses DirectX instead of OpenGL. I'm wondering how on earth the guy that wrote that managed to resolve this issue nicely.

I apologise for not giving the full circumstances before I was trying not to complicate things. Edited by grasshop
0

Share this post


Link to post
Share on other sites
grasshop, please excuse me for hijacking your thread, hopefully it is still within your area of interest.

[quote name='Hodgman' timestamp='1347178161' post='4978207']
[quote name='larspensjo' timestamp='1347177365' post='4978204'](I am using pre multiple alpha already)[/quote]What does the code for setting your blend mode look like?
[/quote]

After some debugging, I think I see where my problem is. The magnifying and minifying filters produce bitmaps with pixels that are effectively pre multiplied alpha (as long as transparent areas are black). But my original bitmap is not. That is, I have something that is supposed to look like a window. So it is mostly fully transparent, with some white lines in it. The lines have some anti-aliased pixels created by the bitmap editor (gimp). These are also full white, but with alpha ranging from 0 to 1.
[attachment=11172:WindowBase_2012-09-09.jpeg]
The shader multiplied all pixels with the alpha, to get pre multiplied alpha. That works fine for the bitmap itself, but not for interpolated areas from magnifying and minifying, which will now have the alpha multiplied twice. If I disable magnifying and minifying, it looks "fine". I wonder if I can use Gimp to make the colors pre multiplied by the alpha?
0

Share this post


Link to post
Share on other sites
[quote name='grasshop' timestamp='1347190617' post='4978269']
The problem is I don't actually have any control over anything myself as I am working on a user game development environment and the user could use any textures themselves and call upon any blend functions as well to that matter.[/quote]
Do you have control over the image loading functions? If so, I think you can modify those of format RGBA to apply premultiplied alpha at loading. That's the design idea I am looking into just now.

You say you have no control over how they are blended. If that is the case, there simply exists no solution that will always work.
1

Share this post


Link to post
Share on other sites
Ok, thanks for the help. I think at this point anyway it will be better to just have the user sort their own images out, that seems to be what some other game making environment just do. I guess it's not that big or common a problem.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0