Shadow decals?

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
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Shadow decals?

Post by Andi|xng »

Since stencil buffer shadows are very slow, I want to include a much more simple shadow technique to my game. It is a soccer game, so there is a plain surface the players are running on. I decided to place a decal under each player, with a shadow texture on it.

The shadow texture is not animated, that means, it has to be very blurry. First I searched for a "inverse method" to EMT_TRANSPARENT_ADD_COLOR, but there is none.
So I tried EMT_TRANSPARENT_ALPHA_CHANNEL with a texture with a circle gradient from transparent to black. The problem is, that only pixels with alpha 127 are drawn by Irrlicht (docs: "... which means that pixels with an alpha value >127 will be written, others not"). The solution seems to be MaterialTypeParam, but changing the value seems to help nothing. The problem is already described there: http://irrlicht.sourceforge.net/phpBB2/ ... php?t=8550

Then I tried it with a very small texture and linear interpolation, so the texture has to be scaled - and so blurred. But here also pixels with < 127 alpha were not drawn... The edge was again very "sharp".

Do you have another idea, how I could get a nice blurry shadow result?
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

Hmm, i don't see any problems with MaterialTypeParam.
What videocard are you using?
And could you post your code for changing materialTypeParam? Maybe you should also add yourTexture->regenerateMipMapLevels() after all?
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post by Andi|xng »

Here is my code (attention: it is Java code, because I use Jirr):

Code: Select all

videoDriver.setTextureCreationFlag(
  E_TEXTURE_CREATION_FLAG.ETCF_ALWAYS_32_BIT, true);
videoDriver.setTextureCreationFlag(
  E_TEXTURE_CREATION_FLAG.ETCF_CREATE_MIP_MAPS, false);
ITexture tex = videoDriver.getTexture("data/meshes/schatten2.psd");
nodePlayerShadow.setMaterialTexture(0, tex);
nodePlayerShadow.getMaterial(0).setMaterialType(
  E_MATERIAL_TYPE.EMT_TRANSPARENT_ALPHA_CHANNEL);
nodePlayerShadow.getMaterial(0).setMaterialTypeParam(254f);
I also tried it with MaterialTypeParam values of 0, 0.5f, 1f, 250f, ... It did not change anything.
Of course I already looked if setMaterialTypeParam() is implemented correctly in Jirr (isn't it a public member of the SMaterial struct in C++? This does not work for a Java binding, so there is the method) - I found no error.

It still looks like as if all alpha values < 127 are ignored - in OpenGL and in DirectX.
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

Why do you think psd files with alpha are supported? I think currently only tga and png with alpha are supported by irrlicht. And try adding tex->regenerateMipMapLevels() right after loading it.
I'm not sure that this one is correct: nodePlayerShadow.getMaterial(0).setMaterialTypeParam(254f);
try nodePlayerShadow.getMaterial(0).setMaterialTypeParam(254.0f);

And i repeat - in my apps the alpha is used a lot, and i have no problems at all. I can send you my app if you don't believe.
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post by Andi|xng »

puh wrote:Why do you think psd files with alpha are supported? I think currently only tga and png with alpha are supported by irrlicht.
Because of this thread: http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=16466
And because alpha works, but only with alpha > 127. Of course I tried other formats like PNG or TGA already.
puh wrote:And try adding tex->regenerateMipMapLevels() right after loading it.
As you can see, I have disabled mip maps for this texture, so this should not be the problem. I tried it anyway, but it did not help.

254f and 254.0f is exactly the same in Java (I thought in C++ it's the same too...). I also tried it with 0.9f, 0.1f, and so on, did not help.

Thanks for your ideas anyway. A small demo (when possible with sources) would help me very much, here is my e-mail: andi@xenoage.com . So I could try it with your alpha texture...
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

Hi, Andi|xng

please test this app:
http://www.irrforge.org/images/2/24/Quake3Map.zip [48 KB]

I modify slightly the\irrlicht-0.12.0\examples\02.Quake3Map
You can press "+", "-" to modify transparency for the plaster
"W", "S", "A", "D" - for moving plaster

Just use standard irrlicht.dll.

I use C++ though, and as i've noticed the proper alpha works with DX only, but version 10 was worked with OGL too, so i hope niko will add fix for next version.

Image

Would be nice if some forumers could test this and post their spec for PC, as i feel the problems with alpha could be in driver, not in Irrlicht.
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post by Andi|xng »

Thanks puh, you are great :)

Here my results: It works perfectly with DirectX 8 and 9, but in OpenGL I can only see the the center of the shadow (perhaps until alpha gets smaller than 127) with transparency == 0 (all other transparency values make the shadow completely invisible...).

Interesting, because my application show other results... I will compare the sources, perhaps it is a problem with Jirr, not with Irrlicht. When I know more, I will post it here. Thank you very much for your help so far!
Reiyn
Posts: 23
Joined: Sat Mar 05, 2005 7:51 pm
Location: Canada

Post by Reiyn »

Niko, do you have any idea on how to fix the alpha blending? =/ The materialparam isn't a proper fix =(
Reiyn
Creating "Chimera", an Online RPG
DAoC - Guinevere - Druid rr11
WoW - Gorgonnash - Druid 55
genesys
Posts: 75
Joined: Tue Nov 02, 2004 6:49 pm
Contact:

Post by genesys »

you just have to activate 32bit textures!
by default irrlicht formats the textures to A1R5G5B5 that's why the alpha channel gets only true or false . . .
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

genesys wrote:you just have to activate 32bit textures!
by default irrlicht formats the textures to A1R5G5B5 that's why the alpha channel gets only true or false . . .
Is this really the problem everybody has? So maybe I should default to 32 bit texture loading now.
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post by Andi|xng »

niko wrote:Is this really the problem everybody has? So maybe I should default to 32 bit texture loading now.
No, this is not the problem. Of course I tried it also with 32 bit textures...
At the moment I have no ideas, why it does not work, I will look at it again if I have the time.
GueZt

Post by GueZt »

Hi puh, does your SHADOW DECALLING really DRAW the DECALS
from the MESH of a BSP? or it is just a SQUARE mesh sitting
on the floor with TEXTURE TRANSPANRENT ?


I really wanted to do a decalling on my TERRAIN a X file mesh
but lack of knowledge of doin it.


Do you mind on given some tutorial of code perharps
how to attain that.


Thanks
puh_guest

Post by puh_guest »

No, its just a square with transparent shadow texture on it.
Andi|xng
Posts: 83
Joined: Thu Mar 24, 2005 10:49 pm
Location: Schrobenhausen, Germany
Contact:

Post by Andi|xng »

Problem solved.

Code: Select all

shadowNode.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_ALPHA_CHANNEL);
shadowNode.getMaterial(0).setMaterialTypeParam(0.01f);
While this did not work on my machine with Irrlicht 0.14, I have now smooth edges in Irrlicht 1.2 :-)
Klasker
Posts: 230
Joined: Thu May 20, 2004 8:53 am
Contact:

Post by Klasker »

You waited 1.5 years to have that solved?? :?
Post Reply