Shadows versus translucent objects

I have translucent objects (fire particles) and there is shadow cast by different object. If I put the camera to look at the shadow through the fire, shadow is rendered in front of particles. This is caused by the fact that I have disabled depth write for the particles. If I enable the depth write, then, in addition to my particles looking completely wrong, shadow is completely invisible behind them.

What I want to achieve is to just have transparent/translucent objects drawn AFTER the shadow is rendered, so the shadow will be filtered through them (so you can see shadow a bit through the translucent fire).

As I understand, at the moment order of render is something like

  • opaque
  • transparent
  • shadow
  • nifty gui

    This for example allows semi-transparent leaves to cast shadows with alpha shadow treshold etc. What I think I would need is something
  • opaque
  • transparent shadow casters
  • shadow
  • transparent non-shadow
  • nifty gui

    Any chance to achieve that without rewriting half of the jme3 render queue ?

Have you tried to set the Shadommode for the Particles ? Maybee that helps

ShadowMode is off.

It is not a problem that particles are casting shadow or that shadow is received by them. Shadow is still received by the floor behind them, it is just drawn on top of particles due to them not writing to depth buffer.

I need to find the way to get transparent objects drawn after the shadow map is composed onto scene

That’s strange because, if the shadow mode is off they should not be rendered in the shadow pass…

I’ll look into this.

I can confirm that issue:


I know what my issue is and still cannot make any sense of your screenshot :wink:

When I get home, I’ll try to write small program showing the issue - something like number of semi-transparent colored quads of ‘glass’, with shadow-casting poles in front of them. Then we could observe various ways to shadow behaviour - shadow being cast on the glass, glass blocking the shadow and shadow being cast ‘through’ the glass, but without glass coloring it (which is my problem).

Well it’s a blu particlee effect directly in front of the camera, but the Shaows are still 100% black and renderd over it - (The particle effect orgin is where the blue cylinder hits the ground)

@Remy: it doesn’t matter that the particles have shadow mode = off … Because particles render without z-write and the shadows are rendered after particles, the shadows are rendered on top of the particles

Ok, so here comes my screenshot. Fire should be mostly obscuring the shadow (like it obscures the floor behind) - but instead shadow is drawn on top of it.

Maybe alternate approach - allowing to create kind of post-processing filter which would in fact render a special bucket of translucent objects ? It would need to be added in correct place in post-processor list (after shadow, before bloom probably).

I’m not sure how we could make shadow post-processor to run in between the normal bucket rendering - and if it would not cause troubles with some other post-processors…

ok…@Kirill I think we need a plan for this :wink:

I guess the general idea would be, should transparent objects get shadows cast on them or not? If the answer is no, then the shadow effect should only be applied to the Opaque bucket

I think it is slightly more complicated. It is about order in which object buckets versus post-processor filters are applied. Critical part of the equation is not the place where shadows are rendered into shadowmaps, but the final stage when shadowmap is blitted on top of everything.

I can see two possibilities basically:

  • either create new special object bucket (Transparent-after-filters), which would allow to place certain kinds of transparent objects after the shadow processor; not sure how it will play with gui bucket , plus maybe it will skip all filters (and maybe we want bloom on particles?)
  • add ability to mix filters in the middle of render queue - so shadow filter would be fully blitted after opaque bucket but before transparent bucket (but then transparent objects cannot receive shadows)

    Some variation of second idea is possible, by creating two transparent bucket and putting shadow filter in between them. It would be then up to application in which bucket to put it.

The thing is semi transparent objects (like tree foliage) are in the transparent bucket, but has to receive shadows…

Maybe split the transparent bucket in transluscent and semi-transparent…

abies said:
Some variation of second idea is possible, by creating two transparent bucket and putting shadow filter in between them. It would be then up to application in which bucket to put it.

Exactly, then the difficulty will be to make something that is simple to use from the user point of view

How about two transparent buckets internally, and place the objects in the one they belong (with the shadow recive flag), then render all normal the shadow the no shadow particles and after that the rest of post processing.?

Ok I made some tests

I implemented a translucent Bucket that is rendered after the processors and the result is quite good with particles (only on my local copy for now)

Transparent bucket

Translucent bucket

@Momoko_Fan what do you think?

I’m not completely satisfied with this solution because it doesn’t work with filter (those who need depth has the exact same issue)

Isn’t there a way to make the particles write depth and quickly sort them?

It would have to sort all the triangles globallly (there might be particle emitters for which areas of effect partially overlap each other, even if single particles do not) and then render them, possibly switching texture context on each triangle and drawing it triangle by triangle instead of entire buffer at once. Would probably kill the performance.

Ok, so after this one is solved, somebody will probably ask for colored shadows for stained glass windows for rendering of church :wink:

Another way might be to actually have particles with depth … First you render them as usual without depth write, then you render their depth into the buffer without color write. This will also fix that issue with the water filter and particles

abies said:
Ok, so after this one is solved, somebody will probably ask for colored shadows for stained glass windows for rendering of church ;)

Soooo, how about those colored shadows for stained glass windows for renders of churches? :p

I had actually asked about this long ago when jME3 development was just starting, but I was also a lot more naive as to what goes into a lot of this stuff. Back before realizing how faking simple effects was a lot easier than trying to actually DO THE EFFECT while burning about 90% of a computer's power doing so. :p

1 Like

Update to last svn you have now a translucent bucket. Just put your particle emitter in it, and it should work with shadows.

If you want to use it with filters see this post for explanations