LoadTexture's alpha channel

Blitz3D Forums/Blitz3D Beginners Area/LoadTexture's alpha channel

fox95871(Posted 2009) [#1]
Hello, I noticed the book says:

"PNG [supports] an alpha channel which provides per pixel transparency information."

And the docs say:

"If an image contains an alpha map, this will be used to make certain areas of the texture transparent. Otherwise, the colour map will be used as an alpha map. With alpha maps, the dark areas always equal high-transparency, light areas equal low-transparency."

But I was under the impression that the only options available were binary alpha (only black gets turned transparent), and color map used as an alpha map (any color that's even slightly dark gets turned practically transparent). What's this about "if an image contains an alpha map"? I like using pngs just because they're as small as jpgs and have bmp quality, but can they really "contain" an alpha map? If so, how can I get Photoshop to merge the two? Or do I need some other program? Thanks and hope someone can help! :)


Kryzon(Posted 2009) [#2]
I had a lot of problem with this too, so I empathize with your difficulty. I wish someone had posted quick info for me, like i'm about to:

In photoshop, go to the Channels tab, then click on Create New Channel. A new channel will appear on the list, called "Alpha 1" (at least it's what its called on my old version 5.0). In that channel, everything thats 100% white will be completely opaque, everything lesser than that will be gradually transparent. When you're going to save your PNG from photoshop, make sure you only have a single alpha channel (meaning, no "Alpha 2" or "Alpha 3"), as that's the only amount photoshop will export, be it .TGA or .PNG. After you make sure you only have 1 alpha channel, then you can export your PNG or TGA (both formats are accepted by blitz3D and can have alpha transparency channel). In the export dialogue (which I believe to be Save a Copy as...), make sure that Exclude Alpha Channel checkbox is unmarked (or else it will...exclude the alpha channel and undo all your hard work. Makes sense).

Then that's it. All you have to do is load in blitz3D with the flag 2, and it'll read transparency from the texture's alpha channel. That way you can control parts you want to show or not.


fox95871(Posted 2009) [#3]
Great! I'll check all that out tonight! Thanks :)


fox95871(Posted 2009) [#4]
I have photoshop 5 too, but it's LE. I can't do channels with it apparenty, there's no tab or anything. You don't still have your installer for 5, do you? I've always liked 5 much more than the new fangled ones. They always change everything til it's like a totally different program.


Kryzon(Posted 2009) [#5]
That's exactly how I feel. Not only that, but most of the texturing tutorials I've read, years ago, used it. So I know what it's capable of.
But I'm afraid I don't have it anymore =/
Perhaps you could try and get version 6 or 7, I'm sure they don't change that much (now, the CS ones, now that's total different story!)


Ross C(Posted 2009) [#6]
You could create a grayscale map you want to use for your alpha channel, export it as a normal .bmp or .png. Then load your main texture and load your alphamap texture you made into blitz. Then from your alphamap texture, manually write the alpha information from the grayscale values to the alpha channel of the main texture.

Something like this might help in writing the alpha information:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1013


Ross C(Posted 2009) [#7]
That gives me an idea actually. I'm going to create a small app that lets you load in a texture and load in a grayscale image and use that as the textures alpha channel, then let you save that back to a texture format (.png)


Kryzon(Posted 2009) [#8]
Good call, but I'd stick with my easy to find Channels tab all day...


fox95871(Posted 2009) [#9]
Should be popular. Will be with me, I loathe the idea of trying to find a free version of photoshop 5 online. 6 or 7 I'm not too keen on either. It might be easier, but I like 5. Anyway, looking forward to seeing it. I'd try to do it myself, but when you said "manually write the alpha information from the grayscale values to the alpha channel of the main texture" things started to go black :D


Ross C(Posted 2009) [#10]
Come to think of it, i think leadworks had a free tool, that mentioned something about alpha channels...

Yeah, it does. Grab it here:

http://forum.leadwerks.com/viewtopic.php?f=7&t=2178&start=0&st=0&sk=t&sd=a

Load your texture with it, then do EDIT > ALPHA CHANNEL FROM IMAGE

Then choose a greyscale image, the same size as your texture, you want to use for your alpha channel. Then save it out as a .png again. Remember only certain image formats have an alpha channel.


fox95871(Posted 2009) [#11]
I'll take a look at that, thanks.

Kryzon, I just remembered I used to put my Photoshop 5 LE program folder on a disc and take it with me to the library. Back then you could just put it on the desktop and after an only mildy troubling error message, it would run just fine. So I was thinking maybe I could do the same with the non LE version. Do you think you could send me just that, the program folder?

Email me about this please.


fox95871(Posted 2009) [#12]
Hey Ross, that didn't really do what I was hoping. The image has to already have the alpha channel included. I need a program that will help me merge the two. Anyone have any ideas?


Matty(Posted 2009) [#13]
http://blitzbasic.com/codearcs/codearcs.php?code=1814

The above code archive entry allows loading and drawing of ALPHAed TGA files. You could modify it to allow saving of TGA files.


Ross C(Posted 2009) [#14]
I thought that was the point of leadworks tool... It should save out the alpha channel you imported from another image. Hell you could even import the alpha channel from the same image and save it back out again.

As far as i'm aware, you simply load the texture with the alpha flag and all is well. Try exporting as a .dds They seem to work particulary well.


fox95871(Posted 2009) [#15]
I thought that was the point of leadworks tool


Huh. Well if it is, it's not doing a very good job of it. I've tried everything you can do with that program, and the closest I've gotten to what I want is an error message that says, "Image does not contain an alpha channel." No kidding. I really don't understand how it could merge files anyway when it only loads one file at a time. Anyway thanks for trying to help. Never mind about my complaining.

Matty, thanks but wouldn't that only run fast on 2D Blitz programs like the last post on that thread said? And why tgas, when those are just large pngs with no real advantage over them?

I'm still mostly shooting for the Photoshop method here, so if anyone has Photoshop 5, the non LE version, please email me! Even just the program folder will do. I have some very good programs to trade.


Ross C(Posted 2009) [#16]
Well, the way i did it:

Make your alpha channel into a grey scale image. Load up the leadwerks tools. Load your image. Then:

EDIT > ALPHA CHANNEL FROM IMAGE

It will through up an error, and say it will apply an alpha channel based on the RGB, which is the greyscale you created.

Or, email me the image and the alpha channel and i'll combine them for you.


fox95871(Posted 2009) [#17]
Cool, I'll try that tonight! Were you able to get this somehow?:

http://leadwerks.com/wiki/index.php?title=Texture_Tool

I'd like an mht of it if anyone's a member. Or is it just not written yet?


Ross C(Posted 2009) [#18]
I believe that is the same application i linked too :o)


fox95871(Posted 2009) [#19]
The above link is for the help page, I'm not that spacy! It's blank, so I was just wondering if that's because I'm not a member.

Good news! All a get is error messages from start to finish, but then it makes the file perfectly :) I never would have thought to try that, just ignore error messages and use the produced file anyway.

So for anyone who wants to make their own alphamaps, here's how:

1. get this program: http://www.leadwerks.com/ccount/click.php?id=60
2. then in Photoshop, make one png for your image, and another for the alpha, meaning paint white over everything you want to be showing, and black over everything you want to be invisible, with a soft edge in between otherwise what's the point.
3. start Leadwerks texture tool and go to File>Open and open the actual image file (not the alpha!)
4. go to Edit>Alpha channel>From image, and select the alpha image.
5. ignore, and possibly taunt the message that comes up. Just don't even read it. Click okay.
6. now go to File>Save as and call it imagenameWITHALPHAMAP.png
7. definitely taunt, and possibly insult the integrity of the error message that comes up then. Don't worry, it worked! Click okay.
8. load the image into Blitz3D with flag 2, and you now have perfect texture antialiasing!

By the way, for mesh antialiasing get this: http://h1.ripway.com/fox95871/index.html

One more thing: I noticed Blitz3D crashes if you use ClearTextureFilters in a game that has a flag 2 object. Why is that? That kinda sucks because how else are you supposed to turn off flag 8 if you need to, which I do in order to have my character's faces look clear in the distance.

Here's my code:


and here's the image that goes with it:
http://www.geocities.com/dbalanciere/alphamap.htm


Ross C(Posted 2009) [#20]
That command shouldn't crash at all. I believe you have to put brackets at the end of the command? It's def a bug though, if that doesn't work. What line does the debugger say it crashes on?


H. T. U.(Posted 2009) [#21]
It doesn't use brackets.


Ross C(Posted 2009) [#22]
Can you upload your 2 textures so i may test this?


jfk EO-11110(Posted 2009) [#23]
Back to Photoshop: I always had problems saving a PNG with Alpha Channel, because I tried to work with an additional channel for alpha.

But there is an other way it works: When you have an image with say 3 layers and then you delete the background layer, then the unpainted areas will become transparent: the checkerboard pattern will shine trough, indicating transparency. If you save this, it's going to work in Blitz. It's not exactly the same as the 4th channel, but you can use the selection tools to erase something on RGB based on an the greyscales of an other image. Or maybe the blendmodes can be used.

As other people suggested - use the dds format. Whenever possible try to use masks instead of alpha, because of the z-order issue. Masked dds are really nice, but it'S a bit tricky to get a matte color that looks good (actually: you need a clone layer of the image (under the original layer), opacy 2%, then blur it one time, this way directx will use the correct colors on the outline of the mask, otherwise not.) There's a dds export plugin, btw.


fox95871(Posted 2009) [#24]
Thanks. That's a lot to go over tonight. Coffee!

Ross, I'm pretty sure it's no parenthesis because I use it all the time to turn off flag 8. This is the first time I've actually had to turn off ClearTextureFilters. Also, if you turn that line on, and switch the lines further down, you can see it works. But then for all I know it's one of those that works with or without parenthesis. So you want the texture image and the alphamap image? If so I can do that tomorrow, but the two merged into one file is already at the bottom of my post. I put it there so people could test it.

Thanks for the replies! :)


fox95871(Posted 2009) [#25]
Here are the files:

http://www.mediafire.com/imageview.php?quickkey=jm0edmovzmk
http://www.mediafire.com/imageview.php?quickkey=yndvlnjvndk
http://www.mediafire.com/imageview.php?quickkey=vmwzfmgltzn

Thanks Jfk, but I don't think I'll be using that way. For one, I still don't have Photoshop 5 non LE, but also that looks way more complicated than what I'm doing now! Glad it works for you though :)

Okay well, I'll be looking forward to the results of your testing Ross, and anyone else who wants to try and figure this out. In case I didn't explain it well enough, which I don't think I did, if you run my most recent code with the file provided in that post, there is apparently no way to get the texture to be both alphamapped and sharp at a distance (flag 2 on, flag 8 off). It's either or, because ClearTextureFilters, which is the only way I know of to turn of flag 8, seems to hate flag 2 being on and crashes Blitz3D in it's anger.


Ross C(Posted 2009) [#26]
I will have a bash at that. I'm in work and my home internet isn't working, so i'll try on here to get it sorted. You may have no choice but to use .dds textures though for this.


fox95871(Posted 2009) [#27]
As other people suggested - use the dds format.

Why? I tested that format and gave it a solid: why does this format even exist! Over pngs? Are you kidding?

Anyway, I've given up on this particular bug. It's no big deal I decided to be stuck with flag 8 for everything, and it's a small price to pay for having perfect alphamaps, which I now have thanks to all your help. Thanks so much everyone!


Warner(Posted 2009) [#28]
Maybe the program won't crash if you use:
Global cubetexture=LoadTexture("AREA0001foregroundWITHALPHAMAP.png",1+2)
instead ?


fox95871(Posted 2009) [#29]
Thanks, I'll try it.


fox95871(Posted 2009) [#30]
Yup, you got it. Not sure why it works though. Flag 1 is color, and 2 is alphamap. So if ClearTextureFilters was saying "No flags at all" and LoadTexture was saying "Alphamaps only", and now it's saying "Alphamaps and color" why would that be making it work? Why would not having color on have been making it crash before? :/

Anyway, thanks for figuring it out for me overall if not the whys :)


Warner(Posted 2009) [#31]
I have no idea. Maybe the alpha data is extracted from the color layer, and there is no internal check to see if there is any color information available ? Maybe ClearTextureFilters was added in a later stadium of Blitz3D than loading the alpha layer, and the routine that loads the alphamap was never made compatible with textures that don't have color information? I can only guess.
Anyway, I think you could add something like:
TextureFilter "", 1
after using ClearTextureFilters.


jfk EO-11110(Posted 2009) [#32]
This is a rather new "bug" and it doesn't happen on all Machines, which is why it's a mean one. To prevent such surprises you should also set Flag 1 whenever you use Flag 2. This was discussed several times and it should now be in some sort of FAQ.

Instead of tex=Loadtexture ("thing.png",2 or 8) you should start using something like this:

global my_alpha= 2+1
global my_mipmapped = 8
....
tex=Loadtexture ("thing.png",my_alpha or my_mipmapped)


Ross C(Posted 2009) [#33]
Don't dis-respect the .dds format ;o). It's biggest advantage is compression within the video cards memory itself, greatly reducing the room textures take up and allowing you to use more.


fox95871(Posted 2009) [#34]
I'm just not big on "lossy". Ever try loading a level 10 jpg into Blitz that has any semblance of clean lines? It gets rejpegged down to about a 5 and those lines turn into square ghost artifacts. And it's not just Blitz, Geocities uploads, and even my sacred Windows all run jpgs that every so often say "Okay, I'm just going to turn myself into a 7 or a 5 now and hope nobody notices."

I tested the png format a while back, and the results I got were: same size as a jpg, exact same quality as a bmp (even in extreme high contrast) in other words, truly lossless. How they achieved that I have no clue, but that's why I always use png now. But to each their own! :)


Warner(Posted 2009) [#35]
I'm a big fan of 'lossy' compression. I usually store my programs in a lossy format as well. That way, when I reload my programs, they sort of represent the thing that they were supposed to do.


fox95871(Posted 2009) [#36]
Why? Like watching old vhs movies? Or wearing glasses that aren't your prescription? I like denying the existence of sarcasm.


jfk EO-11110(Posted 2009) [#37]
I agree dds for lightmaps may result in colorish artefacts at the edges of things, but for masked textures dds is the one and only solution. And a really nice one.


Ross C(Posted 2009) [#38]
Fair enough, but the difference in memory using the compressed texture format makes is reason enough. As said, any textures that require lossless decompression, like lightmaps and skyboxes and heightmaps, fair enough, but textures like detail maps, which probably represent the bulk of textures, it's mad not to use them, if you want to game to run on more hardware.

It could mean the difference between running it on a 32 MB graphics card, or having to up the memory requirements to a 128 MB graphics card.