How to make Particles face to shadow camera?

I’m trying to make alpha clipped opaque billboards to cast and receive shadows. As you can see, I already got some results. I’ve made custom material def, shaders, and preShadow shader, so it gets particles alpha, and shadows slowly disappears, just like billboard does. That’s pretty cool, but i have following troubles and questions:

  1. How to make billboard face shadow camera, when shadows are rendering? Now from some points of view smoke shadow turns into bunch of lines.

    How does billboards facing the camera? Does it made with java code or vertex shader?

  2. For some reason shadow painted absolutely black on my material.

    When I’m forcing it to use PostShadowPSSM.frag instead of PostShadowPSSM15.frag it paints shadow as it should, with ShadowIntensity = 0.7, but with that it ignores alpha transparency.

  3. Is it possible to write texture into z buffer?

    Thanks in advance, for any answers.
  1. they are facing the camera from what I can see in the screenshot. And particles do that automatically (so do billboards). Maybe I am missing what effect you want.

  2. you will only get solid shadows, jme does not support soft shadows

  3. I’m not sure what you mean here, do you have an example of what you want to achieve?
  1. When shadows are enabled, the whole scene is rendered twice from two different cameras: orthographic shadow camera (z-buffer only) and normal game camera. Here is another pic of how it looks, when “sunlight” comes from the side. Particle shadows becomes thin lines. So I want them to face shadow camera, when shadow maps are rendered, and turn back to normal game camera, before rendering frame buffer. That way shadow shape will not be affected by game camera position.

  2. Yeah, I know, I even turned off alpha blending on particles. I’m talking about shadow Intensity. Compare shadow darkness, on landscape and particles. (I must be missed something in my shaders)

  3. I’m talking about using alpha channel as depth for each particle. So when they intersecting other geometry, they bumping out (like soft particles, but without blending). Well, never mind. I guess, it’s impossible to make in one render pass.

Well if you could try to use the pointmode for particles, they are automatically faced to any camera. Or you could use a vertex shader to turn your elements.

Changing the facing on the scene graph between different camera/viewport renderings is probably illegal behaviour, since you would break the geometry update stuff.

Is this the default ppsm shadow stuff, or do you use a own custom version btw?

You could fake it by doubling up the billboards. Look at the difference between sun and camera position and if it’s more than X then create a billboard for each.

Other than that I guess you’d have to identify where in the render loop the two renderings are done and insert code to change the billboard in between the two.

  1. you’d have to make them face the camera yourself. The particles act as billboards and are oriented to face the camera during the update loop. You render the shadow maps just after…so you’d have to iterate over the particleEmitter in the shadow cast queue and rotate the particles to face the shadow cam. Then after the shadow map render, rotate them back to face the view camera…

    That’s far from optimized but that would work.

    Another approach would be to make them face the cam in the shader. It should be possible with some math tricks to get a rotation matrix and to multiply the inPosition by this matrix instead of the WorldViewProjectionMatrix. It would be faster and would have no effect on the scene graph.

    2)Soft shadows are not what you seem to believe they are.Soft shadows offers the ability to smooth the shadows edges with some filtering/blurring. We do support them with several algorithm (PCF4/8, Dither, Nearest, Bilinear). Your problem seems to be that the intensity is not properly applied on particles, and that looks like a problem on my end.

    3)Shadow maps are depth maps. No sure I understand what you mean neither.

The built-in jME3 particle system already orients particles toward the camera (I assume you’re using your own). You can look at ParticleTriMesh class to see how that happens.

Wow! Thank you all, for replies. I will try with transformation matrices and stuff.

@EmpirePhoenix said:
Is this the default ppsm shadow stuff, or do you use a own custom version btw?

It's default shadow. I only changed PreShadow shaders a bit.
@Momoko_Fan said:
The built-in jME3 particle system already orients particles toward the camera (I assume you're using your own).

No, again, that's standard jme particles. Only shader is mine.