Does JME have shaped drop shadows?

Recently, I’ve been playing an old game from 2006, called AirRivals.

I noticed that they have post-processing drop shadows, in the same shape as the plane:

These shadows seem to use up almost no processing time at all, and add quite a nice ambiance effect - For example, it can be important in plane games to get perspective on how close to the ground the player is.

In that specific game, the drawback is that I can see shadows through objects. For example:

As it is, I think these shadows add a cool effect, and I’m wondering, does jMonkeyEngine have any sort of equivalent, where we can create shadows the same shape as an object, that just “drop” down below it?

Also, these shadows are object specific. For example, the portal I am sitting on does not have any shadow cast by it at all.

No, JME does sot support such things. I think that it can be done with decals, there is some 3rd party code for that, you’ll need to adapt it for your needs.
Today’s graphics card have much better performance than ten years ago, you don’t need to make such cheats. For directional light shadows will not eat much fps, for many point lights there are techniques to optimize the rendering pipeline (deferred lighting, deferred shading).

[quote=“FrozenShade, post:2, topic:35623, full:true”]For directional light shadows will not eat much fps, for many point lights there are techniques to optimize the rendering pipeline (deferred lighting, deferred shading).
[/quote]
You’ll have to teach me your secrets then, since directional light shadows not only drop my FPS by over 70%, but also look really horrible (e.g. the shadow obviously “jumps” into existence in front of me).

1 Like

I used shadows for directional light only once and I don’t remember any problems. I “just did it” and it worked.

It doesn’t “just do it” for me. Even a basic shadow map with a size of 256 drops the FPS by a huge amount, and the shadows look horrible as well.

Of course, part of that is because I have a mobile GPU, but the entire point of the question is to make basic-looking shadows for bad GPUs in the first place.

I have a drop shadow implementation that I’ve posted here before. It’s only shaped based on the bounding boxes of the geometry but it does have the added benefit of intersecting with the scene more correct otherwise.

I included them as part of SimArboreal:

…You can find the class here:

I haven’t tested it with JME 3.1 alpha 5 yet but it worked on alpha 3, I think.

There may be many reasons for low FPS. The most obvious is that the scene is not optimized. With shadows enabled the engine needs to go through all shadow casting objects and render them to the shadowmap. If you have many objects on your scene and you don’t use culling properly, the engine must go through all of them.

The FPS is dropped by 60%. Even if the only object I am casting shadows with is the aeroplane I am flying. Yes, the shadows then look smooth, but it is not worth losing over half my FPS just for a “cool graphical look” or “depth assistance” in the game.

I suppose my point is that I am looking for very simple, low-quality shadows, that use very little CPU, and that JME currently doesn’t seem to have that functionality.

I was looking for the actual shape of the plane, as opposed to just a bounding box. I would like to be able to see my plane’s shadow looming in front of me as I land/crash, rather than just a box. Boxes work well for things like tanks or people, but not for things like planes, which require more shape.

Also we come back to the issue that the code is fairly complicated.I’m still fairly new to JME and as such implementing that into the game would take so much time that I would be much better off implementing something useful (e.g. proper missiles).
Edit: Oh, wait a minute, it’s a filter that I copy and paste into my code. Is there any tutorial on usage though? I have never used a custom filter.

It’s actually ovals that it displays roughly the size of the object (or objects).

How to use this code:
-cut and paste the class into your project, rename the package, whatever.
-add it to a filter post processor (should be a tutorial on filter post processor)
-set the objects you want to cast shadows to cast shadows like for any other JME shadows.

…that’s it. And then you will have some shadows (maybe not perfect) while you work on real things.

I’m getting this issue:

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.IllegalArgumentException: Material parameter is not defined: Texture
at com.jme3.material.Material.checkSetParam(Material.java:459)
at com.jme3.material.Material.setTextureParam(Material.java:538)
at com.jme3.material.Material.setTexture(Material.java:604)
at com.jme3.post.FilterPostProcessor.renderFilterChain(FilterPostProcessor.java:280)
at com.jme3.post.FilterPostProcessor.postFrame(FilterPostProcessor.java:308)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1035)
at com.jme3.renderer.RenderManager.render(RenderManager.java:1078)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:260)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:152)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:192)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:233)
at java.lang.Thread.run(Thread.java:745)

I’ve found all the assets needed at GitHub and added them to the project, but I can’t see anywhere that “texture” is defined. So, I’m stuck. :confused:

Hmmm… here is how the code sets it up, effectively:

        fpp = new FilterPostProcessor(assets);
        shadows2 = new DropShadowFilter();
        fpp.addFilter(shadows2);
        getApplication().getViewPort().addProcessor(fpp);

For drop shadows, you should only need the files from the matdefs directory:

(And really only the null and shadow ones)

What version of JME are you running?

Edit: but it’s weird because the null shader definitely has a Texture parameter:

I am initiating the filter just as you’ve suggested. Of course, there are other filters too that are on the same .FilterPostProcessor.

Did they work before? What happens if you remove them?

I don’t understand why drop shadows would cause this problem because it definitely has a Texture parameter.

If the filter is on it’s own (or near the end of a post processor), I get this:

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.NullPointerException
at com.jme3.material.Material.<init>(Material.java:122)
at com.simsilica.arboreal.DropShadowFilter.initFilter(DropShadowFilter.java:147)
at com.jme3.post.Filter.init(Filter.java:241)
at com.jme3.post.FilterPostProcessor.initFilter(FilterPostProcessor.java:173)
at com.jme3.post.FilterPostProcessor.reshape(FilterPostProcessor.java:467)
at com.jme3.post.FilterPostProcessor.initialize(FilterPostProcessor.java:157)
at com.jme3.renderer.RenderManager.notifyReshape(RenderManager.java:311)
at com.jme3.renderer.RenderManager.notifyReshape(RenderManager.java:336)
at com.jme3.app.Application.reshape(Application.java:526)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:189)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:233)
at java.lang.Thread.run(Thread.java:745)

Are you sure you have MatDefs/Null.j3md in your assets folder?

Material has changed a lot since that old version of JME so I can’t tell for sure what line 122 is now… but that’s my guess. Missing j3md.

Edit: actually if the line is the same as now then asset manager is null.
public Material(AssetManager contentMan, String defName) {
this((MaterialDef) contentMan.loadAsset(new AssetKey(defName)));
}

so somehow you are initializing this all in a strange way it seems.

Oops, looks like I copied the shadow j3md into the null j3md. Unfortunately, I can’;t just download the assets, as it keeps failing the download due to a “network error”. So I have to copy them in manually.

Anyway, new error:

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.NullPointerException
at com.simsilica.arboreal.DropShadowFilter.postFrame(DropShadowFilter.java:210)
at com.jme3.post.FilterPostProcessor.renderFilterChain(FilterPostProcessor.java:272)
at com.jme3.post.FilterPostProcessor.postFrame(FilterPostProcessor.java:308)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1035)
at com.jme3.renderer.RenderManager.render(RenderManager.java:1078)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:260)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:152)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:192)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:233)
at java.lang.Thread.run(Thread.java:745)

That said, the problem is probably an incorrect material or shader, so give me a minute or so to work it out.

Materials and shaders are all copied correctly.

Still getting the same error as posted above.

The line numbers have changed in the DropShadowFilter.java file that you downloaded so I can’t tell exactly which line the NPE is happening on.

The line is:

if( depthTex.getImage().getMultiSamples() > 1 ) {

Apologies for the extra lines, I added a couple of comments and stuff.