Basic Shadow Renderer - Issues / Questions

Hey everybody, I’m new to these forums. I’ve been using JME3 for a few months now, and I’m really enjoying it. However, I’ve hit a minor cosmetic issue with my game, and I was hoping somebody on these forums could help explain it to me.



For my game, I’ve created a modified material for the particle generator that allows for non-greyscale images to be used for particles; it makes use of a normal alpha channel in a given picture for transparency in the particles, rather than using the color black. I’ve had to do this because my game involves driving a car through things like trash cans and mailboxes, and I’m using the particle generator to simulate junk flying out of each object when the player hits it.



Anyway, this modified material works completely fine until it has to affect and be affected by the basic shadow renderer. It’s sort of hard to describe, but the rectangle enclosing each particle on the screen will “block out” any shadows that need to be rendered behind it, regardless of whether or not there are any non-transparent pixels there. I’ve attached a picture to better demonstrate what I’m taking about - this is during the game, midway through the effect of crashing into a trash can (and I’ve drawn a red rectangle around one of the particles that I think most clearly demonstrates the issue - it blocks out the shadows that would normally be rendered behind it).







Here is the code I’m using to set up the basic shadow renderer.



bsr = new BasicShadowRenderer(assetManager, 256);
bsr.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
viewPort.addProcessor(bsr);


After this, all game objects (including the particle generators) are set to receive shadows only.

Now, for the modified particle material I'm using, I will confess that I know next to nothing about material definitions for JME3, so I felt like I was groping in the dark while constructing this:


MaterialDef Point Sprite {

MaterialParameters {
Texture2D Texture
Float Quadratic
Boolean PointSprite

// Texture of the glowing parts of the material
Texture2D GlowMap
// The glow color of the object
Color GlowColor
}

Technique {

VertexShader GLSL100 : Common/MatDefs/Misc/Particle.vert
FragmentShader GLSL120 : Common/MatDefs/Misc/Particle.frag

WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
WorldMatrix
CameraPosition
}

RenderState {
Blend Alpha
DepthWrite Off
PointSprite On
// AlphaTestFalloff 0.01
}

Defines {
USE_TEXTURE : Texture
POINT_SPRITE : PointSprite
}
}

Technique {

VertexShader GLSL100 : Common/MatDefs/Misc/Particle.vert
FragmentShader GLSL100 : Common/MatDefs/Misc/Particle.frag

WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
WorldMatrix
CameraPosition
}

RenderState {
Blend Alpha
DepthWrite Off
}

Defines {
USE_TEXTURE : Texture
}
}

Technique FixedFunc {
RenderState {
Blend Alpha
// DepthWrite Off
// AlphaTestFalloff 0.01
}
}

Technique Glow {

VertexShader GLSL100: Common/MatDefs/Misc/SimpleTextured.vert
FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag

WorldParameters {
WorldViewProjectionMatrix
}

Defines {
HAS_GLOWMAP : GlowMap
HAS_GLOWCOLOR : GlowColor
}

RenderState {
PointSprite On
}
}
}


If anyone has any advice for me, or if there's any information I forgot to put in this post, please let me know! Thanks in advance!
1 Like

You can place your particles in the translucent bucket, that will prevent them to “hide” the shadows.



However…if you want the particles to cast shadows…that’s gonna be tough…

Thanks for the quick response!



No, I don’t need the particles to cast shadows, I just need to prevent them from blocking out shadows in the background.



I tried putting my particle emitters into the translucent bucket and the transparent bucket, but neither of these steps seemed to have an effect. This was the line of code I used to do that:


debris.setQueueBucket(Bucket.Transparent);


with debris being my ParticleEmitter. I also tried adding the following line of code, since this was demonstrated in one of the tutorials.

Material debris_mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);


But that didn't seem to have an effect either. Is there something I'm missing?

mhh…I would need some test case to debug this.

you could try :



[java]debris_mat.getAdditionalRenderState().setDepthWrite(false);[/java]



I had a similar issue with pssm shadows not showing through transparent materials, solved it with this.

1 Like

DepthWrite is set to false by default for particles, @brushguy, did you changed it?

No, I hadn’t changed DepthWrite initally, but I added thetoucher’s code to set DepthWrite to false, and that seemed to fix it! Thanks everybody for your help!

Cool! thanks @thetoucher :wink: