Page 1 of 1

Shadow decals?

Posted: Sat Sep 24, 2005 3:17 pm
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?

Posted: Sat Sep 24, 2005 3:25 pm
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?

Posted: Sat Sep 24, 2005 8:57 pm
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.

Posted: Sat Sep 24, 2005 9:33 pm
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.

Posted: Sun Sep 25, 2005 7:15 am
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...

Posted: Sun Sep 25, 2005 9:53 am
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.

Posted: Sun Sep 25, 2005 10:05 am
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!

Posted: Fri Oct 21, 2005 1:14 am
by Reiyn
Niko, do you have any idea on how to fix the alpha blending? =/ The materialparam isn't a proper fix =(

Posted: Fri Oct 21, 2005 9:56 am
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 . . .

Posted: Sat Oct 22, 2005 7:13 am
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.

Posted: Sat Oct 22, 2005 8:06 am
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.

Posted: Tue Nov 08, 2005 3:56 am
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

Posted: Tue Nov 08, 2005 11:31 am
by puh_guest
No, its just a square with transparent shadow texture on it.

Posted: Fri Mar 02, 2007 2:50 pm
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 :-)

Posted: Fri Mar 02, 2007 3:47 pm
by Klasker
You waited 1.5 years to have that solved?? :?