White line & filterpad- solved?
by World-Loom · in Torque Game Builder · 11/30/2008 (2:18 pm) · 20 replies
Hi there!
We have just solved one of bigger issue around. For unknown reason (maybe there is one - please point it) Torque during allocating bitmap copies it's content to memory initialized with 0xFF (read 'white' pixels).
Changing this to '0x00' (black/invisible) ends with bitmap without white line - even if it's non POT and has filterPad set to "false".
The code fragment sits in dlg/gBitmap.cc, line 187, method GBitmap::allocateBitmap.
Fix:
Change
To
If you know any reason for not doing as described above - please notify us.
We have just solved one of bigger issue around. For unknown reason (maybe there is one - please point it) Torque during allocating bitmap copies it's content to memory initialized with 0xFF (read 'white' pixels).
Changing this to '0x00' (black/invisible) ends with bitmap without white line - even if it's non POT and has filterPad set to "false".
The code fragment sits in dlg/gBitmap.cc, line 187, method GBitmap::allocateBitmap.
Fix:
Change
dMemset(pBits, 0xFF, byteSize);
To
dMemset(pBits, 0x00, byteSize);
If you know any reason for not doing as described above - please notify us.
About the author
#3
11/18/2009 (1:17 am)
Awesome catch - just started seeing this to after converting lots of graphics to KEY imagemaps and this fixed the white line problem right up. Thanks!
#4
If it wasn't a POT then filter-pad places a single copy of adjacent texels around all frames in which case even linear sampling won't touch it.
That's the whole point of filter-padding and it does work. If you have a non POT and you were NOT using filter-padding then this would make a difference but it wouldn't be good in all cases because you would still get edges that faded from one color (at a certain transparency) to black (at completely transparent) so you'd still get a faint blended black line. Filter-padding stops this because the linear sampling only sees two texels of the same color/transparency.
Non of this affects T2D though as we don't use the same systems as TGB anyway but I still don't understand.
In summary, the only way I can see this making any difference in TGB is when NOT using filter-padding on a non-POT texture.
Me = Confused.
11/21/2009 (11:29 am)
To be honest, I don't understand why this affects TGB at all. If it's a POT texture, it wouldn't make any difference as the texture would be completely replaced with the bitmap.If it wasn't a POT then filter-pad places a single copy of adjacent texels around all frames in which case even linear sampling won't touch it.
That's the whole point of filter-padding and it does work. If you have a non POT and you were NOT using filter-padding then this would make a difference but it wouldn't be good in all cases because you would still get edges that faded from one color (at a certain transparency) to black (at completely transparent) so you'd still get a faint blended black line. Filter-padding stops this because the linear sampling only sees two texels of the same color/transparency.
Non of this affects T2D though as we don't use the same systems as TGB anyway but I still don't understand.
In summary, the only way I can see this making any difference in TGB is when NOT using filter-padding on a non-POT texture.
Me = Confused.
#5
I can tell you that a lot of times this happens when there is sub-pixel placement. I don't know if that actually matters, but that is when I usually saw it.
11/21/2009 (2:57 pm)
All I can say is that I tried padding on my non-POT textures, and would still get a one-pixel white line (often down the right and/or bottom). Once I put this in, about 99% of those went away.I can tell you that a lot of times this happens when there is sub-pixel placement. I don't know if that actually matters, but that is when I usually saw it.
#6
If i change it to a wide screen resolution like 853x480 it shows me again those white pixels in some of the images.
What can it be?
11/27/2009 (3:15 pm)
Thanks it solves my problem also when running in 640x480.If i change it to a wide screen resolution like 853x480 it shows me again those white pixels in some of the images.
What can it be?
#7
640x480

853x480

It's weird and annoying.
Thanks
PS: Changing filter mode from Smooth to None will solve it but if i have to resize any image they will look crappy.
11/30/2009 (11:20 am)
For example, if i have the game in 640x480 sometimes the images look ok (if they are on the left part of the window) but if using 853x480 they will all look bad (with the white pixels)640x480

853x480

It's weird and annoying.
Thanks
PS: Changing filter mode from Smooth to None will solve it but if i have to resize any image they will look crappy.
#8
So what is the texture-size and what doesn't the image-map definition look like?
It works in "none" mode because that tells the graphics card to NOT sample the neighbour texels. This is NOT a TGB thing, it's a pure hardware artifact. Filter-pad was added as a convenience to save you from having to do it in your art-work.
When you use "smooth" mode your GPU uses Bilinear Interpolation on your texture which results in neighbour texels being sampled. Filter-pad makes a copy of the texels surrounding the frame so that the GPU always samples correct texels.
This has been working for a VERY long time and therefore I have no idea what's going on here apart from (for some reason) filter-padding not being active.
11/30/2009 (11:40 am)
I suspect that this fix doesn't fix anything, it just changes it. These sampling lines will change according to how the texture is used and its position etc.So what is the texture-size and what doesn't the image-map definition look like?
It works in "none" mode because that tells the graphics card to NOT sample the neighbour texels. This is NOT a TGB thing, it's a pure hardware artifact. Filter-pad was added as a convenience to save you from having to do it in your art-work.
When you use "smooth" mode your GPU uses Bilinear Interpolation on your texture which results in neighbour texels being sampled. Filter-pad makes a copy of the texels surrounding the frame so that the GPU always samples correct texels.
This has been working for a VERY long time and therefore I have no idea what's going on here apart from (for some reason) filter-padding not being active.
#9
The texture size is 256x68px.
11/30/2009 (1:03 pm)
The image map definition looks like thisnew t2dImageMapDatablock(bt03ImageMap) {
imageName = "~/data/images/bt03.png";
imageMode = "CELL";
frameCount = "-1";
filterMode = "SMOOTH";
filterPad = "1";
preferPerf = "1";
cellRowOrder = "1";
cellOffsetX = "0";
cellOffsetY = "0";
cellStrideX = "0";
cellStrideY = "0";
cellCountX = "2";
cellCountY = "1";
cellWidth = "128";
cellHeight = "68";
preload = "1";
createColorMap = "0";
allowUnload = "0";
};The texture size is 256x68px.
#10
Does this happen in the stock code?
11/30/2009 (3:00 pm)
Have you made changes to the t2dImageMapDatablock code because "createColorMap" isn't part of the stock code.Does this happen in the stock code?
#11
If i leave that attribute out and use the stock code i gives me the same result.
12/01/2009 (7:26 pm)
Yes, sorry. It's something i implemented in order to detect transparent pixels. If i leave that attribute out and use the stock code i gives me the same result.
#12
12/02/2009 (3:44 am)
I really haven't got much time to look at this but I'll see what I can do. Can you put up a link to the image itself?
#13
Some help is always welcome.
Thanks
12/02/2009 (8:46 am)
http://img687.imageshack.us/img687/3874/bt03.pngSome help is always welcome.
Thanks
#14
The problem is that if you inspect your image using a paint package you'll see that the transparent region surrounding your capsule (the one on the left without the yellow glow) you'll see that it's set to be white/full-transparent. The exterior of your capsule is black surrounding the green center.
What this means is that in bilinear sampling mode, intermediary samples will fade from the surrounding opaque-black to fully-transparent-white. This means that there's a good chance (depending on the scale) that you'll see a point between black/white e.g. grey as it linearly blends from opaque to fully-transparent. This is essentially what the linear blending does.
I took your image, magic-wanded the region surrounding your capsule and filled it with transparent-black and the problem went away.
Always filling it with black isn't the solution. For instance, if your capsule was surrounded with (say) orange then you'd get a blend from orange to black which might only be seen as darker orange.
Bilinear interpolation and transparency can get quite tricky. The best thing to do is to avoid sudden colour changes and not rely on the transparency to hide it. Allow at least a single texel extent before you allow any color changes. Anything beyond that won't be affected.
The filter-padding is for when artwork reaches the edges of the frame (which yours doesn't). In this case it simply surrounds the frame with a copy of the neighbour texels to achieve essentially the rule I just stated.
12/02/2009 (10:50 am)
Okay so I added this image to stock TGB and immediately I saw the artifact. The thing is, the artifact is well away from the edges of your frame so this has NOTHING to do with filter-padding.The problem is that if you inspect your image using a paint package you'll see that the transparent region surrounding your capsule (the one on the left without the yellow glow) you'll see that it's set to be white/full-transparent. The exterior of your capsule is black surrounding the green center.
What this means is that in bilinear sampling mode, intermediary samples will fade from the surrounding opaque-black to fully-transparent-white. This means that there's a good chance (depending on the scale) that you'll see a point between black/white e.g. grey as it linearly blends from opaque to fully-transparent. This is essentially what the linear blending does.
I took your image, magic-wanded the region surrounding your capsule and filled it with transparent-black and the problem went away.
Always filling it with black isn't the solution. For instance, if your capsule was surrounded with (say) orange then you'd get a blend from orange to black which might only be seen as darker orange.
Bilinear interpolation and transparency can get quite tricky. The best thing to do is to avoid sudden colour changes and not rely on the transparency to hide it. Allow at least a single texel extent before you allow any color changes. Anything beyond that won't be affected.
The filter-padding is for when artwork reaches the edges of the frame (which yours doesn't). In this case it simply surrounds the frame with a copy of the neighbour texels to achieve essentially the rule I just stated.
#15
Thanks a lot. i will now have that in mind. Just though it was strange to have the artifact depending on the image position.
12/02/2009 (12:47 pm)
Ok, that's a good explanation :) Thanks a lot. i will now have that in mind. Just though it was strange to have the artifact depending on the image position.
#16
Thanks
12/03/2009 (7:54 am)
I'm trying to fill surrounding area with transparent-black but i don't know how to do it. I'm using photoshop, can you give me a hint on how to do it?Thanks
#17
For something more specific, you'd have to ask someone who's familiar with it.
12/03/2009 (7:57 am)
I don't use it myself (not being an artist) but there's got to be a "magic wand" tool to select the transparent region. Then all you have to do is select "fill" using the transparent-black colour.For something more specific, you'd have to ask someone who's familiar with it.
#18
In photoshop just select the transparent area with the magic wand and then in edit menu, select fill and then in Contents Use select "Black" and put Blending at "normal" with 1% opacity, deselect "Preserve Transparency". Then just save the image and it done and working.
Thanks Melv for the technical explanation :)
12/03/2009 (8:47 am)
I'm not an artist either, anyway i found out.In photoshop just select the transparent area with the magic wand and then in edit menu, select fill and then in Contents Use select "Black" and put Blending at "normal" with 1% opacity, deselect "Preserve Transparency". Then just save the image and it done and working.
Thanks Melv for the technical explanation :)
#19
As for solution - we found a problem, found working solution, implemented it and few days later released game (it was year ago). Since that time we have made many changes inside TGB helping us to work with it. Also we've created few external tools. We are now trying to release sequel of the game so we can't find much time at the moment. Hopefully we would be able to release some results of our work to community later as local resources.
For now - please check GIMP script that may help solve you two problems in one move. It basically serves as PNG splitter - changes one PNG file to JPG and alpha.JPG files. If your imagemap definitions do not use files extensions this should work out-of-the-box.
Although splitting file into RGB and Alpha channel looks as easy operation after short investigation few problems appear. The biggest one is that you have already found in your file - 0% alpha channel (invisible) pixel still has information about RGB colors (by the way it's technical issues not artistic one ;-) And of course compressing algorithm still takes care about those unnecessary color information - thus increasing file size.
Our scripts takes care about that problem while splitting file and makes it with two different attempts. First one - copies alpha channel over the image and then split it - it may cause problems with images containing very delicate mid-alpha pixels (border around your buttons may apply same for solid to alpha gradients). Second attempt - just sets pixel to black where it has alpha channel 0% and leave them unchanged for alpha > 0%. Thus you may still have some trash color pixels where you have any alpha at all and black where alpha is zero.
Please check script available from http://www.world-loom.com/other/fiu2-png-optimize.scm
Short usage instruction:
* download and install latest stable GIMP (currently 2.6)
* download script
* save in GIMP scripts folder (either in progrm files gimp folder - search deep into it's structure or in your personal scripts file)
* run GIMP and open any image
* run from menu Filters->Carz->PNGSplit
* select folder with files you want to split into .jpg and .alpha.jpg
* check if you want to preserve small alpha or not
* go!
Notes:
* due to other changes we've made files named like *_k.png would stay untouched as we name KEY mode files like this
* some PNGs not having alpha channel would not create alpha.jpg at all; it would only convert PNG file into jpeg
* splitting files not always would give you smaller files - make this wisely and use brain (this rule helps also during other activities ;-) )
* check which version of the script would work better for your images
* script WOULD NOT delete your PNGs but WOULD overwrite JPG files - so it's wise to make such operations in separate folder for selected files
Disclaimer: this software was made for internal purposes of World-LooM and we are not responsible for any disasters it may cause to your images, software or hardware. It may eat your children so use it for your own responsibility - we do not guarantee anything.
12/03/2009 (9:40 am)
Looks like we have started long topic here touching different aspects of preparing assets for work with TGB (and probably other usages). As for solution - we found a problem, found working solution, implemented it and few days later released game (it was year ago). Since that time we have made many changes inside TGB helping us to work with it. Also we've created few external tools. We are now trying to release sequel of the game so we can't find much time at the moment. Hopefully we would be able to release some results of our work to community later as local resources.
For now - please check GIMP script that may help solve you two problems in one move. It basically serves as PNG splitter - changes one PNG file to JPG and alpha.JPG files. If your imagemap definitions do not use files extensions this should work out-of-the-box.
Although splitting file into RGB and Alpha channel looks as easy operation after short investigation few problems appear. The biggest one is that you have already found in your file - 0% alpha channel (invisible) pixel still has information about RGB colors (by the way it's technical issues not artistic one ;-) And of course compressing algorithm still takes care about those unnecessary color information - thus increasing file size.
Our scripts takes care about that problem while splitting file and makes it with two different attempts. First one - copies alpha channel over the image and then split it - it may cause problems with images containing very delicate mid-alpha pixels (border around your buttons may apply same for solid to alpha gradients). Second attempt - just sets pixel to black where it has alpha channel 0% and leave them unchanged for alpha > 0%. Thus you may still have some trash color pixels where you have any alpha at all and black where alpha is zero.
Please check script available from http://www.world-loom.com/other/fiu2-png-optimize.scm
Short usage instruction:
* download and install latest stable GIMP (currently 2.6)
* download script
* save in GIMP scripts folder (either in progrm files gimp folder - search deep into it's structure or in your personal scripts file)
* run GIMP and open any image
* run from menu Filters->Carz->PNGSplit
* select folder with files you want to split into .jpg and .alpha.jpg
* check if you want to preserve small alpha or not
* go!
Notes:
* due to other changes we've made files named like *_k.png would stay untouched as we name KEY mode files like this
* some PNGs not having alpha channel would not create alpha.jpg at all; it would only convert PNG file into jpeg
* splitting files not always would give you smaller files - make this wisely and use brain (this rule helps also during other activities ;-) )
* check which version of the script would work better for your images
* script WOULD NOT delete your PNGs but WOULD overwrite JPG files - so it's wise to make such operations in separate folder for selected files
Disclaimer: this software was made for internal purposes of World-LooM and we are not responsible for any disasters it may cause to your images, software or hardware. It may eat your children so use it for your own responsibility - we do not guarantee anything.
#20
www.torquepowered.com/community/forums/viewthread/26407
12/04/2009 (8:32 am)
Use the SuperPNG plugin for Photoshop to have proper control over the color of transparent pixels in PNG images. Photoshop's built-in png plugin is terrible - it erases the color information from transparent pixels on file load.www.torquepowered.com/community/forums/viewthread/26407
Associate William Lee Sims
Machine Code Games