Specular map + transparency
by Gunther Moors · in Technical Issues · 03/11/2008 (12:29 pm) · 8 replies
Now i know it might sound like a lot,
but is it possible to make some sections of a model have transparency in combination with a specular map, i've tried a lot of things already, but can't seem to find a way on how to combine the specular map with the transparency, since they are both derived from an alpha channel in a .PNG file or .TGA file. did anyone ever get something like this to work ? or is it a near impossible job ??
PS: i want to use this technique for a framed window, where the glass is transparent but shiney and the framework isn't shiney.
Greetings Gunther
but is it possible to make some sections of a model have transparency in combination with a specular map, i've tried a lot of things already, but can't seem to find a way on how to combine the specular map with the transparency, since they are both derived from an alpha channel in a .PNG file or .TGA file. did anyone ever get something like this to work ? or is it a near impossible job ??
PS: i want to use this technique for a framed window, where the glass is transparent but shiney and the framework isn't shiney.
Greetings Gunther
#2
but it doesn't seem to work, i've been using SuperPNG a while now, with success so that's not the problem, but it seems that the moment you add transparency to a material, the alpha channel gets used for it instead of for specularity. and i'm not really looking for a fully see through type of material, it should still be slightly visible and that is really dependent on alpha channels 2, (in this image the model in question with transparency
).
i was thinking maybe there is a way to use the mapto command in the material.cs to get the specularity mapped ontop of the existing transparency ??
Greetings Gunther
Ignition Games
03/13/2008 (9:50 am)
Hey dave thx for the advice,but it doesn't seem to work, i've been using SuperPNG a while now, with success so that's not the problem, but it seems that the moment you add transparency to a material, the alpha channel gets used for it instead of for specularity. and i'm not really looking for a fully see through type of material, it should still be slightly visible and that is really dependent on alpha channels 2, (in this image the model in question with transparency
).i was thinking maybe there is a way to use the mapto command in the material.cs to get the specularity mapped ontop of the existing transparency ??
Greetings Gunther
Ignition Games
#3
OUT.col += specularColor * specular * tex2D(lightMap, IN.lmCoord) * diffuseColor.a;
should be a relatively simple matter to refactor the material generator to spit out
OUT.col += specularColor * specular * tex2D(lightMap, IN.lmCoord) * bumpMap.a;
That'll (in theory) sperate out the light calculation factors into the normalmap (where imho it belongs anyway), leaving you a free channel for the transparency in your diffuse.
03/13/2008 (10:02 am)
What about refactoring the specularity to use the normalmaps alphachannel? Since this ones the pub area, won't throw out basecode, but the proceedural hlsl files generated by materials even in the demo do contain the line:OUT.col += specularColor * specular * tex2D(lightMap, IN.lmCoord) * diffuseColor.a;
should be a relatively simple matter to refactor the material generator to spit out
OUT.col += specularColor * specular * tex2D(lightMap, IN.lmCoord) * bumpMap.a;
That'll (in theory) sperate out the light calculation factors into the normalmap (where imho it belongs anyway), leaving you a free channel for the transparency in your diffuse.
#4
1.) Make sure the alpha channel is active. You'll know it's active because it will show up as a red overlay to your image. If it's not active, it often does not get saved out, and could cause your above mentioned issue.
2.) When saving, make sure that the 'Use Alpha Channel' option is checked in the exporter.
03/14/2008 (8:28 am)
Gunther: That should not be occuring... I've tested this in the current release of TGEA (1.0.3 I believe) and it worked just fine. Have you removed the original .PNG exporter plugin that ships with your image software? Sometimes that can cause a problem. Also, when you save out with SuperPNG, you have to make sure to do 2 things..1.) Make sure the alpha channel is active. You'll know it's active because it will show up as a red overlay to your image. If it's not active, it often does not get saved out, and could cause your above mentioned issue.
2.) When saving, make sure that the 'Use Alpha Channel' option is checked in the exporter.
#5
Thanks.
03/15/2008 (4:41 pm)
I tried looking through the code to see where I would make that change but I cant find anything. Would it be possible to email me the file and line where this would be specified?Thanks.
#6
This is very easy to fix if you write a custom shader, and - while I'm not too familiar with the engine code - it should also be rather easy to fix in Shadergen as well. The problem is that in shaders, you have 4 values on a pixel... RGBW. 'W' is the alpha channel. So all this works great when you don't have specular and translucency. But when you do, it's trying to use that fourth channel for both - and you've got a conflict on your hands.
So... the best way to handle this, is to make sure you have the option of using a seperate, greyscale specular map. I say option, because you only want to use it when you also are using transparency, or else you're just filling your alloted memory space with excess graphics.
-Dave C.
21-6 Productions
03/15/2008 (5:12 pm)
My apologies.... I didn't catch at first that you were working with a transparent material. Okay.... everything I said above works with non-transparent materials. With transparent, however, none of that works because, yes, the alpha channel is used for transparency.This is very easy to fix if you write a custom shader, and - while I'm not too familiar with the engine code - it should also be rather easy to fix in Shadergen as well. The problem is that in shaders, you have 4 values on a pixel... RGBW. 'W' is the alpha channel. So all this works great when you don't have specular and translucency. But when you do, it's trying to use that fourth channel for both - and you've got a conflict on your hands.
So... the best way to handle this, is to make sure you have the option of using a seperate, greyscale specular map. I say option, because you only want to use it when you also are using transparency, or else you're just filling your alloted memory space with excess graphics.
-Dave C.
21-6 Productions
#7
I've had mild success with moving the specularity and/or cubemaps to the second pass. This requires using a separate texture from your main plane body one:
Modify as needed. AlphaTest/Ref are optional performance tweaks. Glow and Cubemap may be optional (I don't recall).
03/16/2008 (6:07 am)
Yeah, transparencies and spec maps are imperfect--to say the least.I've had mild success with moving the specularity and/or cubemaps to the second pass. This requires using a separate texture from your main plane body one:
new Material (windshield_MAT)
{
// STAGE 0 (first rendering pass)
//----------------------------
mapTo = "windshield";
baseTex = "windshield";
translucent = true;
translucentZWrite = true;
alphaTest = true;
alphaRef = 40; // anything below this number is not visible and is not written to Z-buffer
// STAGE 1 (second rendering pass)
//----------------------------
glow[1] = true; // affects specularity only since it's on the same pass
emissive[1] = true; // affects specularity only on this pass
pixelSpecular = true;
specular[1] = "0.95 0.95 0.95 0.95";
specularPower[1] = 128.0;
Cubemap = Sky_Day_Blur02;
};Modify as needed. AlphaTest/Ref are optional performance tweaks. Glow and Cubemap may be optional (I don't recall).
#8
03/17/2008 (3:06 pm)
This has been an overall problem with TGEA that I would like to fix properly. I saw right away the problem with the "double use" of the Alpha channel for Transparency and Specularity Masking. My thought at the time was that all Materials really need a maskTex parameter that can be applied to any pass. Then, the Alpha Channel from the specified Mask Texture would be used to mask (proportionally) all effects on that pass. Then the Alpha Channel on all textures would be reserved solely for the purpose of Transparency, while independent mask textures could be used/applied for all other purposes: Specularity Masks, Glow Masks, whatever.
Associate Dave Calabrese
Cerulean Games
First off, if you are using Photoshop, you cannot do this by default. Adobe removed the ability to save an Alpha Channel with a .PNG awhile ago. So, you will need to download the SuperPNG plugin, located here: www.fnordware.com/superpng/.
Now, when you create your image, make it transparent like you normally would, so you can see the white and grey grid behind it. Now in the channels tab, create your alpha channel, and apply a greyscale map. On this map, the whiter parts will have a higher specular level than the blacker portions.
And make sure you keep your original art file (in the case of Photoshop, this is your .PSD file)! This is especially important, since Photoshop cannot read the saved .PNG file correctly (it just comes out as mostly transparent), and when you view it in Windows Explorer, the image will look practically blank - however it will work in the engine.
Give it a try and let me know if you have any problems!
-Dave C.
21-6 Productions.