Lightmap and AlphaChannel for a material.

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

Lightmap and AlphaChannel for a material.

Post by qez111 »

I am exploring lightmap possibilities for my scene. Currently the lightmapping works fine, but in my scene there are certain 2D textures such as trees. Such textures need to be transparent. But how do I set a material as transparent but still be able to use lightmap?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

You need to create your own material or use shader.
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

Post by qez111 »

is there any sample code available for writing such a material or a shader?
thanks.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

I did not see such code here on forum and I did not do such myself. I would say you need to learn shader programing and look for some tutorials or examples elsewhere on net, than adopt it for Irrlicht.
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

Post by qez111 »

thanks, but unfortunately i dont have much time to first learn and then use a solution as I have only couple of weeks left.
but i am wondering if there is anybody here who has been facing this problem and may have found a solution....

Edit: Is there any other method by which I can display a material transparently without setting the material flag?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Edit: Is there any other method by which I can display a material transparently without setting the material flag?
No, material type flag tells engine how to draw geometry.
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

Post by qez111 »

ok, i am trying to adapt the shader tutorial#10 to try and somehow get the materials with alpha channel. so far i have only managed to set them as semi-transparent (see-through), but i am struggling to set it transparent as alpha channel. anybody here with experience in shaders?
mtest
Posts: 10
Joined: Mon Feb 18, 2008 8:41 pm

Post by mtest »

http://www.clockworkcoders.com/oglsl/tutorial7.htm

This may be something of the nature you are looking for.

Not to suggest that internal shading is the only POSSIBLE way to do it, but I can't say.
qez111
Posts: 54
Joined: Mon Apr 28, 2008 9:44 pm

Post by qez111 »

Thanks for the link, i'll try that.. but its only for openGL i believe.

btw, I found that some particular materials are using EMT_ONETEXTURE_BLEND even after it is lightmapped. can i set such a material to transparent by its alpha channel?
mtest
Posts: 10
Joined: Mon Feb 18, 2008 8:41 pm

Post by mtest »

Sorry it took so long. My dad's just gotten home from the hospital, and I was getting really, really sick of trying to figure this out, but I had the same problem.

Still, you are correct. I solved the problem for me with this glorious line of code:

Code: Select all

newMaterialType1 = gpu->addHighLevelShaderMaterial(vertShader, "main", video::EVST_VS_1_1,pixelShader,"main",EPST_PS_1_1,callback,video::EMT_TRANSPARENT_ALPHA_CHANNEL); 
Notice the EMT_TRANSPARENT_ALPHA_CHANNEL cast, just as if you were using this as a parameter is SetMaterialType.
You are correct that link is GLSL, the openGL highlevel shader.

BlendFunc = source * sourceFactor + dest * destFactor ( E_BLEND_FUNC ) Using only Textures[0]. generic Blender

is the description for EMT_ONETEXTURE_BLEND.

I'm not exactly sure what you mean by referencing this material. In my openGL implementation I achieved this by

gl_FragColor.argb = texval1.argb*0.5 + texval2.argb*0.5

whereas .5 is simply the weight making it a true adverage (texval1.argb +
texval1.argb)/2.0 is the same thing. As you can see, I actually passed the textures, but, speaking from theory as I may be I do not believe you have to do this for a single texture, although I know none of the DirectX shader langauge.

If you have any more questions, such as how to pass a texture, please ask.

I Hope I'm getting the hang of this. I don't fully grasp everything in the materials world mysyelf, I'm sure.

I'm not directly sure how you might set the Alpha directly after using the blend material from IrrLicht, no, but as you can see, mapping the output similairly in the shader should not be terribly difficult (I think). Still, I'm not even sure to implement the blend thing in Irr itself, so I'm not very enlightened. Mabye you could simply cast it from the AddHighLevelShader call?

I hope I'[/code]
Post Reply