Can't make transparent objects receive pssm shadows properly

<cite>@nehon said:</cite> No it doesn't, but what the op want is shadows through semi transparent surface. @alrik, am i wrong? Here if he sets a discard threshold the surface will be completely transparent

I’m just going from the picture of a frame that has a totally transparent area that is casting shadows and from the code that sets the alpha discard threshold.

I thought the shadow pass just renders depth and doesn’t render the colour at each point? So it wouldn’t know the alpha in order to discard…

thanks, but why should it be not possible? I have found this website. did they have the same problem like mine?

http://gamedev.stackexchange.com/questions/5038/shadow-mapping-and-transparent-quads

EDIT: and yes, I mean shadows through semi transparent surface

<cite>@zarch said:</cite> I thought the shadow pass just renders depth and doesn't render the colour at each point? So it wouldn't know the alpha in order to discard...

Well, somewhere I’ve seen a picture of a leafy tree with leafy shadows. I may have made a lot of assumptions about how it was done but the leaves were definitely textures.

<cite>@pspeed said:</cite> I'm just going from the picture of a frame that has a totally transparent area that is casting shadows and from the code that sets the alpha discard threshold.
yeah for those it would work , I was referring to the top yellowish quad.
<cite>@zarch said:</cite> I thought the shadow pass just renders depth and doesn't render the colour at each point? So it wouldn't know the alpha in order to discard...
Actually it's aware of the diffuse color, so if the alpha threshold is set it does a texture fetch to retrieve the alpha value and if it's below the threshold the pixel is discarded. This way depth is not rendered for this pixel and thus won't show in the shadow map projection.
<cite>@alrik said:</cite> thanks, but why should it be not possible? I have found this website. did they have the same problem like mine? http://gamedev.stackexchange.com/questions/5038/shadow-mapping-and-transparent-quads
This already works in the engine. As @pspeed mention you have to set an alphaDiscardThreshold to your material and the areas that are completely transparent (to be exact that has a transparency below this threshold) will not be rendered in the shadow map. BUT they won't be rendered even in the scene. So this may work for the side of your cubes because it seems they are fully transparent, but this won't work for the yellow transparent quad on top of them.

ah i must admit, that there is no yellowish quad on the top… I modified the BlendMode of the Shadow Shader vom Modulate to ModulateX2 (because I want “sunlight” instead of shadows to get the original brightness of my vertexes) so some transparent surface are brighter than others. the glass and the leaves block have the same texture on each face. I only want to see the shadows from the leaves or the glass block frame.

When I try to set the alpha threshold, all shadows in the world are disappearing

EDIT:
two new screens with blendmode modulate (original)

the block material use the real Texture2DArray opengl feature…

Oh ok, i got misleaded by the first screenshot.
Could you show me the code where you set the alphathreshold?

On a side note, regarding the screenshots. Do you use some vertex coloring for the ambient shadows at the bottom of the cubes? it looks really nice.

oh thanks :smiley: … yeah I create my own vertex buffers (all types of block in one material due to “real” Texture Arrays). The Ambient Occlusions are calculated and applied through vertex colors. I modified the “MatDefs/Light/Lighting.j3md” file to use Texture2DArray instead of Texture2D. It all works perfectly … the transparent surfaces also :slight_smile:

Material defs:
[java]
mat = new Material(assetManager, “MatDefs/Light/LightingArray.j3md”);

mat.setTexture(“DiffuseMap”, tex);
mat.setTexture(“NormalMap”, tex_nm);
mat.setFloat(“AlphaDiscardThreshold”, 0.5f);
mat.setBoolean(“UseAlpha”, true);
[/java]

you can see the other stuff I have already posted some posts before.
now the shader files in detail:

AbstractShadowRenderer.java:
[java]
public abstract class AbstractShadowRenderer implements SceneProcessor, Savable
{

private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize)
{
// JME
this.postshadowMat = new Material(assetManager, “Common/MatDefs/Shadow/PostShadow.j3md”);
shadowFB = new FrameBuffer[nbShadowMaps];
shadowMaps = new Texture2D[nbShadowMaps];

/* MY IMPLEMENTATION */
preshadowMat.setFloat(“AlphaDiscardThreshold”, 0.5f);
postshadowMat.setFloat(“AlphaDiscardThreshold”, 0.5f);
preshadowMat.setBoolean(“UseAlpha”, true);
postshadowMat.setBoolean(“UseAlpha”, true);

// JME
setShadowCompareMode(shadowCompareMode);
setEdgeFilteringMode(edgeFilteringMode);
setShadowIntensity(shadowIntensity);
}

[/java]

the shader files (PostShadow15.frag, PostShadow.vert, PreShadow.frag and PreShadow.vert) are unmodified… I only added some lines to jme j3md files.

modified snippets:
MaterialParameters
[java]
// Apha threshold for fragment discarding
Float AlphaDiscardThreshold (AlphaTestFallOff)
// Output alpha from the diffuse map
Boolean UseAlpha
[/java]

Technique Defines
[java]
DISCARD_ALPHA : UseAlpha
[/java]

RenderState
[java]
Blend ModulateX2
[/java]

but now there are no shadows… so I think the aplha discard in the frag files won’t work correctly :confused:
[java]
if(alpha < m_AlphaDiscardThreshold){
discard;
}
[/java]

hope this helps.

You don’t need to change the j3md or the AbstractShadowRenderer files, just set the discardThreshold on your material.
Make sure your LightingArray.j3md has the preShadow, postShadow and postShadow15 techniques (like in lighting.j3md). Then your frag shader (the one for the LightingArray material) shoud discard the pixel if the alpha value is below the threshold.

ok thanks I will try it. but another problem: if I modify the new lighting.j3md (nightly) to lightingArray.j3md (I modify also the frag and vert shader => Texture2d to Texture2DArray), all textures are transparent and contain only numbers o.O (the current lightingArray.j3md I use is an older version (~ dec. 2012)

screen of the new lightingArray.j3md (nightly):

<cite>@alrik said:</cite> ok thanks I will try it. but another problem: if I modify the new lighting.j3md (nightly) to lightingArray.j3md (I modify also the frag and vert shader => Texture2d to Texture2DArray), all textures are transparent and contain only numbers o.O (the current lightingArray.j3md I use is an older version (~ dec. 2012)

screen of the new lightingArray.j3md (nightly):

I’m just guessing but it looks like your texture array is messed up and pulling in the font texture. Maybe the array is not initialized properly or something? Or access is off?

hm I don’t know. I did exact the same changes like I did in the old lighting shader files. I will send you a PM with a link to the shader files.

try to add this at the beginning of the shader
[java]
#extension GL_EXT_texture_array : enable
#extension GL_EXT_gpu_shader4 : enable
[/java]

I added this to the vert and frag shader, but nothing :confused:
but I know, that the old pssm shader also doesn’t work with my texture arrays

old post: http://hub.jmonkeyengine.org/forum/topic/texture-array-with-pssm/

hehe well, my answer would be similar i’m afraid.
Is everything working with the standard lighting and directionalShadowRenderer on your computer?

yes, the standard jme3 test case works fine.
I think, the sampler2DArray in the frac shader causes this problems :confused:

hi are there any news?

Does your texture array material properly implement the PreShadow and PostShadow techniques? Its probably trying to read a texture array using a regular texture2D function, which obviously won’t work.

There not much I can do, since it works with stock materials.

My texture array material only use the PreShadow technique at the moment. The array textures works, but the shadow (post shader enabled) ignores transparent textures. If I use the current material from jme and set the regular texture2D to texture3D, the whole world only consists of numbers/letters and there are no shadows (post shader disabled).