[SOLVED] Shadows don't appear with imported model

Hi all !

Hope I’m not opening a topic already discussed a thousand times, I’ve been searching though quite a long time and am still struggling…

I’ve been trying to make shadows work with an imported cube, and for this purpose I’ve been testing stuffs with the LightShadow test, which in his basic version appears juste fine.

So I’ve kept two of these objects in the scene and tried to put my imported cube in the middle. And while the two others keep casting and receiving shadows just fine, my cube is still orphan of his own shadow.

I’ve tried with using the mesh.xml or scene to j3o, same result.

If anyone got any idea, i’d be really glad, cause i’ve been trying a thousand different things, including moving OS.

Here is the code :

package jme3test.light.testPerso;

import com.jme3.app.SimpleApplication;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.shadow.DirectionalLightShadowFilter;
import com.jme3.shadow.DirectionalLightShadowRenderer;
import com.jme3.shadow.EdgeFilteringMode;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode;
import com.jme3.util.SkyFactory;
import com.jme3.util.SkyFactory.EnvMapType;
import com.jme3.util.TangentBinormalGenerator;

public class TestDirectionalLightShadow extends SimpleApplication{

    public static final int SHADOWMAP_SIZE = 1024;
    private DirectionalLightShadowRenderer dlsr;
    private DirectionalLightShadowFilter dlsf;
    private Spatial[] obj;
    private Material[] mat;
   
    private Geometry ground;
    private Material matGroundL;
    private AmbientLight al;

    public static void main(String[] args) {
        TestDirectionalLightShadow app = new TestDirectionalLightShadow();
        app.start();
    }
    
    //Charge la scene
    public void loadScene() {
        
        obj = new Spatial[2];
        mat = new Material[2];
        
        //obj0 set up
        mat[0] = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
        obj[0] = new Geometry("sphere", new Sphere(30, 30, 2));
        obj[0].setShadowMode(ShadowMode.CastAndReceive);
        TangentBinormalGenerator.generate(obj[0]);

        
        //obj1 type set up
        mat[1] = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
        mat[1].setBoolean("UseMaterialColors", true);
        mat[1].setColor("Ambient", ColorRGBA.White);
        mat[1].setColor("Diffuse", ColorRGBA.White.clone());
        obj[1] = new Geometry("cube", new Box(1.0f, 1.0f, 1.0f));
        obj[1].setShadowMode(ShadowMode.CastAndReceive);
        TangentBinormalGenerator.generate(obj[1]);

        
        
        //Basic objects
        
        //Met une sphere de type obj0 dans le monde
        Spatial t = obj[0].clone(false);
        t.setLocalScale(10f);
        t.setMaterial(mat[1]);
        rootNode.attachChild(t);
        t.setLocalTranslation(0, 25, 0);
                
        Spatial t1 = obj[1].clone(false);
        t1.setLocalScale(10f);
        t1.setMaterial(mat[1]);
        rootNode.attachChild(t1);
        t1.setLocalTranslation(40, 70, 30);
        

        

        //ground
        Box b = new Box(1000, 2, 1000);
        b.scaleTextureCoordinates(new Vector2f(10, 10));
        ground = new Geometry("soil", b);
        ground.setLocalTranslation(0, 10, 550);
        matGroundL = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
        grass.setWrap(WrapMode.Repeat);
        matGroundL.setTexture("DiffuseMap", grass);
        ground.setMaterial(matGroundL);
        ground.setShadowMode(ShadowMode.CastAndReceive);
        rootNode.attachChild(ground);

        //cube perso
        //Spatial cube1 = assetManager.loadModel("Models/cube1/cube1.mesh.j3o");
        Spatial cube1 = assetManager.loadModel("Models/gege2/gege.mesh.j3o");
        
        cube1.setShadowMode(ShadowMode.CastAndReceive);
        cube1.scale(15);
        cube1.move(30, 50, -60);
        
        rootNode.attachChild(cube1);
        
        
        //set up directionalLight
        l = new DirectionalLight();
        l.setDirection(new Vector3f(-1, -1, -0.8f));
        rootNode.addLight(l);

        //set up sky
        Spatial sky = SkyFactory.createSky(assetManager,
                "Scenes/Beach/FullskiesSunset0068.dds", EnvMapType.CubeMap);
        sky.setLocalScale(350);

        rootNode.attachChild(sky);
    }
            DirectionalLight l;


    @Override
    public void simpleInitApp() {

        
        //parametre la camera
        cam.setLocation(new Vector3f(3.3720117f, 42.838284f, -83.43792f));
        cam.setRotation(new Quaternion(0.13833192f, -0.08969371f, 0.012581267f, 0.9862358f));
        flyCam.setMoveSpeed(100);

        loadScene();//charge la scene

        //PARAMETRAGE DU POST PROCESSING
        //shadow renderer
        dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 1);
        dlsr.setLight(l);
        //dlsr.setLambda(0.55f);
        //dlsr.setShadowIntensity(0.8f);
        dlsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
        dlsr.displayDebug();
        viewPort.addProcessor(dlsr);

        //shadow filter
        dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE, 1);
        dlsf.setLight(l);
        //dlsf.setLambda(0.55f);
        //dlsf.setShadowIntensity(0.8f);
        dlsf.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
        dlsf.setEnabled(true);

        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
        fpp.addFilter(dlsf);
        viewPort.addProcessor(fpp);

    }
    
    @Override
    public void simpleUpdate(float tpf) {
    }

   
}

Thank you !!

my cube is still orphan of his own shadow.

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
    com.jme3.asset.AssetNotFoundException: Models/gege2/gege.mesh.j3o

Could you please show screenshot what you mean?

or provide example without gege mesh :slight_smile: (i dont think it belong to JME test-assets?)

edit:

btw as i see you use both:

  • DirectionalLightShadowFilter
  • DirectionalLightShadowRenderer

i use only one, because wiki says:

JME3 implements two ways to simulate geometries casting shadows on other geometries:

You only need one shadow simulation per light source: if you use shadow rendering, you won’t need a shadow filter and vice versa. Which way is more efficient depends partly on the complexity of your scene. All six shadow simulation classes have similar interfaces, so once you know how to use one, you can easily figure out the rest.

https://wiki.jmonkeyengine.org/jme3/advanced/light_and_shadow.html

Sure! Here’s how it look, I didn’t realize a image hoster had been implemented here.

I see if I can share the gege mesh. It’s basically the basic blender cube with his basic material, just renamed gege.

yes i see issue.

Could you try use just DirectionalLightShadowFilter

without DirectionalLightShadowRenderer?

also if you could, try without cloning “Spatial t = obj[0].clone(false);”, just to check.

why not then just use JME Box?

btw. here is my RAW configuration:

    dlsf = new DirectionalLightShadowFilter(assetManager, 4096, 2);
    dlsf.setLight(sun);
    dlsf.setEnabledStabilization(true);
    dlsf.setShadowIntensity(0.4f);
    dlsf.setEdgesThickness(10);
    dlsf.setShadowCompareMode(CompareMode.Hardware);
    dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);
    fpp.addFilter(dlsf);

for 1 meter = 1 unit scale

1 Like

Hmm I tried it and got the same issue. Tried as well with the shadowRender only and still stuck. As well without cloning…

Because I’m actually making a test to fix the same issue in a real project with personal models. And if it’s not working with a stupid cube I guess making a test to find the core problem is indeed worth it…

edit : tried your raws params for the shadowFilter and … It just told that it overcame my GPU capacities !

usually its some stupid issue.

myself i dont have shadow issue, but if you will prepare TestCase for me,
then i will run and confirm if issue is also for me in 3.2 version (i cant check 3.3 easly)

im not sure what version of JME you also have.

edit : tried your raws params for the shadowFilter and … It just told that it overcame my GPU capacities !

yeah just lower this “4096, 2);” ;p its too much anyway.

but most important is you to provide Test i can just run, and tell your JME version to be sure it match :slight_smile: Then we will see if this is some hardware issue to solve in JME or if this is some stupid issue that i will find in code by compare own solution.

Also please look at console logs for warnings if there are some.

Ok I’ll try to provide one as well as console logs, thank you already till here for your interest !

Should I simply make a zip file with the project and share it here then?

I’m running jme 3,2 btw

no zip files please, security reasons.

just paste code i can paste in JME Tests project, or make github project.

btw. i might soon go offline :slight_smile:

No worries it’s not urgent. We can see that later. It looks anyway indeed like a stupid issue with a parameter missing somewhere.

I’ll try to make a git project tomorrow then, might go as well. Thanks! good night!

edit : quicker as expected : https://github.com/Theodeme/shadowlighttest

1 Like

I can confirm that I’ve had this same issue with both the Renderer and Filter with certain models (and the camera angle sometimes causes shadow artifact flickering with the renderer), but this has been a long lasting issue for me, and I am still struggling to solve it as well. (I should note I’m using jme 3.2.4)
It seems like the Shadow Filter causes less of these artifacts than the Renderer, but the artifacts are still there with both.

I am also noticing that any models that are animated in the .vert shader (like grass or trees swaying in the wind) will always cause artifacts like the one in your screenshot, but I am wondering as well if I may be missing some parameter to fix this, or if there may be a bug in the shadow code.

I hope you can find a solution to this problem :slightly_smiling_face:

1 Like

If they don’t have a preshadow technique then they won’t render shadows.

But for example, SimArboreal trees render shadows just fine and they animate the vertex shader for swaying in the wind.

1 Like

@yaRnMcDonuts this might be answer also for your certain models issue.

@theodeme
well, i made a test based on what you had.

Looks like your model make issue :sweat_smile:
(idk why, but its good step forward)

    //Spatial cube1 = assetManager.loadModel("Models/gege.mesh.j3o");
    Spatial cube1 = assetManager.loadModel("Models/simpleBox.j3o");

when i replaced your model with own model(exported using GLTF), it started working.

As i noticed you export model using OGRE mesh that as i remember is outdated(and official its members were not updating it?)

i dont want now to check why old OGRE exporter have issues like this.
(maybe its your model normals issue or something too)

i checked vertex amount and your box had 24 same as my, so im unsure what might cause it. (initially i thought that you have double faces and it block shadow)

but what i want to say is something you might not know:

  • GLTF is new export standard that will be supported long time and care to work in JME too.

by default it export as PBR material, but you can modify material via SDK or via code if you dont want PBR.

(left is simpleBox.j3o, right is gege.mesh.j3o)

im using Blender 2.81a

exported own model using GLTF:

exported just a simple default cube like here:

1 Like

addition to above:
still, need to make sure if its ogre mesh exporter issue trully.

if it is then might create github issue (but i anyway suggest use other exporters)

Indeed it seems like the most probable hypothesis, as OgreExporter is in any case giving a lot of hard time (doesn’t even work on OSX, neither blender 2.8x), and not only with shadows. Might be good indeed to mention it.

I didn’t even know that there was other exports standard supported in JME, seems like I’m outdated as well. Quite a good new though. Is it mentionned in the documentation ?

I’ll try this GTLF and keep you in touch. thanks a lot!

yes, here you go:

https://wiki.jmonkeyengine.org/jme3/external/blender/blender_gltf.html

:slight_smile:

about Ogre in Blender 2.8, yes i heard they dont update their Blender plugin to work with 2.8, so it just somehow confirm its outdated. Last working version was for 2.79

First page of wiki has,
https://wiki.jmonkeyengine.org/#install

Under that is feature link, and under that is,
https://wiki.jmonkeyengine.org/jme3/features.html#supported-formats

You can also find it on page two of wiki, intermediate topic, Supported formats,
https://wiki.jmonkeyengine.org/jme3.html#documentation-for-intermediate-users

We have a success here.

capture4

So the problem seems definitely to come from the model and the exporter. Solved it downloading blender 2.81a and Jmonkey 3.24, and using the glTF standard for the export. Thanks a lot for your time and your help.

Very nice, thank you. I was used to the offline doc and not the online one, which is apparently more clear and complete.

1 Like

Very nice, thank you. I was used to the offline doc and not the online one, which is apparently more clear and complete.

Thanks for reminding this. by offline you mean SDK one? i thought it use same Wiki pages.

but recently Mitm changed wiki, so maybe it was just little outdated.

Yes.

Can be, I didn’t have the time to check the 3.24 doc but the previous one had some broken links and some outdated informations. I don’t think the use the same wiki pages in any case.

Not that I know of. I think they were copies of wiki pages when sdk started. Don’t know if there is a way to link to the official wiki from sdk so it uses latest.

1 Like