Black edge on Alpha Masking?
Blitz3D Forums/Blitz3D Programming/Black edge on Alpha Masking?
| ||
I'm having problems with alpha masked textures at the moment. For some reason they're all getting horrible black edges, even when full-bright! Is there any way to make the edge of the texture the same colour as the actual texture? Here's an example (the brown tone is consistant through the image) |
| ||
What does your texture look like? If you have the shape in the diffuse channel with a black background you'll get a black edge due to the filtering and blurring. Try making your texture's background the same brown as the main part (in other words, the entire colour channel would just be brown, with the shape defined in the alpha channel only). Hope that makes sense. If not, please post a picture of your texture and also of its alpha channel. |
| ||
I have to mark the alpha mask areas as black, so yes - my texture isn't brown all over. Would it be at all possible to use an alpha channel for masked textures in blitz? The only way I've found of doing it is defining the colour as 0,0,0. Using an alpha channel would be preferable, and I could ensure that the edge is properly brown that way. |
| ||
You can choose your own mask colour for your sprite or texture: http://www.blitzbasic.com/codearcs/codearcs.php?code=1013 |
| ||
If you use the alpha channel I think you'll lose the Z-sorting on the poly, unless you sort it manually. Masked textures should work OK - try turning off the mipmapping for that texture - try using CLEARTEXTUREFILTERS before loading the texture, then either load with just the COLOR and MASKED flags (1+4) or use the TEXTUREFILTER command on the named texture after loading, again setting to COLOR and MASKED only (1+4). Remember to reset the default filters after loading this texture - use CLEARTEXTUREFILTERS following by TEXTUREFILTER "",1+8 |
| ||
I think this function may be what you are looking for: http://www.blitzbasic.com/codearcs/codearcs.php?code=1131 |
| ||
Ah, nice one skid :D |
| ||
Excellent, this should probably do the job. However, I'm stuggling to figure out how I can apply this to my existing scenes. Presuming that I have exported an image from gile[s] or b3dpipeline, I only have to use one load command and it loads in all the textures. How do I apply this function to textures that are loaded automatically in this way? |
| ||
I assume you would need to use GetSurface >> GetSurfaceBrush() >> GetBrushTexture() on all your surfaces. |
| ||
You must free the brush and texture that is generated with these commands :o) |
| ||
This really sucks. :( I tried working this into my pipeline somehow, but it's pretty impractical, especially as some of my masked textures don't have just one colour. It doesn't work nicely with my scenes either, I would have to do a lot of work on every scene to get this to work. I wish it were possible to load alpha PNGs with the mask flag - that would be ideal. That way it could apply 0 alpha to the alpha areas less than 128, and retain the correct colour in the other areas. As far as I see it, this is a totally broken implementation of alpha masks, and I now don't really have any convenient ways I can use alpha in my game. :( |
| ||
I wish it were possible to load alpha PNGs with the mask flag It is. Haven't you tried it? |
| ||
It is. Haven't you tried it? Yes, I tried it... which is strange. I basically made an alpha image and tried to define it at masked rather than alpha (in MAX via b3dpipeline), but it didn't seem to recognise the alpha channel at all and the texture was opaque. What's supposed to happen if you load a 32-bit PNG with the mask flag? This is interesting! |
| ||
I tried this again today, and I still can't get alpha-masking from PNG images with an alpha channel (other than using black, which results in the same problem as BMP). Here are my sample files. Can anyone see why this doesn't work? http://www.deadpanda.com/lj/startest.b3d Thanks for your help, I really want to get this working. |
| ||
Please, can someone confirm for me, Yes or no? Is it possible to make an alpha masked texture from a PNG file alpha, rather than relying on the 0,0,0 pixels? |
| ||
I can probably take a look at this tonight. In the meantime, try using TGA. PNG works for alpha transparency, but Photoshop is a little weird about it. TGA is simpler to deal with. Also, a couple years ago Anthony Flack devised an ingenious way to combine alpha channel with masked transparency. Here's the code: texture=LoadTexture("image.png",1+2+16+32) readalpha(texture) texture=LoadTexture("image.png",1+4+8+16+32) writealpha(texture) ;----------------------------------------------------------------------------- ; function for extracting the alpha Function ReadAlpha(tex) t=TextureBuffer(tex) LockBuffer t For y=0 To TextureHeight(tex)-1 For x=0 To TextureWidth(tex)-1 pix=ReadPixelFast(x,y,t) pix=(pix And $ff000000) Shr 24 alphainfo(x,y)=pix Next Next UnlockBuffer t End Function ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; function for putting the alpha back on Function WriteAlpha(tex) t=TextureBuffer(tex) LockBuffer t For y=0 To TextureHeight(tex)-1 For x=0 To TextureWidth(tex)-1 pix=ReadPixelFast(x,y,t) pix=(pix And $ffffff) Or (alphainfo(x,y) Shl 24) WritePixelFast (x,y,pix,t) Next Next UnlockBuffer t End Function ;----------------------------------------------------------------------------- |
| ||
I tried TGAs to do masks, but its exactly the same as PNG. It ignores the existing mask and just masks out any pixels that are 0,0,0 RGB. :( *sob* You're right about TGAs though, they do seem to handle alpha more reliably than PNGs. It's useful in this instance to have a proper alpha channel rather than working pre-multiplied. That said, they're four times the size of PNGs. :) I'll take a look at Mr Flack's code for making a proper masked texture, but I get the feeling that it's going to be nigh-on impossible to conveninently work into a level built with textures included within. Previously I could just load my B3D file and that was it. |