Shadow decals?
Shadow decals?
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?
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?
Here is my code (attention: it is Java code, because I use Jirr):
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.
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);
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.
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.
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.
Because of this thread: http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=16466puh wrote:Why do you think psd files with alpha are supported? I think currently only tga and png with alpha are supported by irrlicht.
And because alpha works, but only with alpha > 127. Of course I tried other formats like PNG or TGA already.
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.puh wrote:And try adding tex->regenerateMipMapLevels() right after loading it.
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...
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.
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.
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.
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.
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!
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!
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
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
Problem solved.
While this did not work on my machine with Irrlicht 0.14, I have now smooth edges in Irrlicht 1.2
Code: Select all
shadowNode.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_ALPHA_CHANNEL);
shadowNode.getMaterial(0).setMaterialTypeParam(0.01f);