Shadow not working or invisible?

Hi everybody,



after i tried a while now, and searched a lot in the forum, i now open a new topic.

I’m sure, my problem may be easy to solve, but it seems not easy enough for me xD.



I read the tutorial for Light and Shadow and implemented both, the BasicShadowRenderer and PssmShadowRenderer like in the JMETests where they work well.

But after all i still am not able to get the shadow visible.

Here is a picture of my dilemma:



MIssing Shadow



As you can see i inserted a directional light too, and it has the same direction as the shadow should have.

The floor exist of 100 cubes like the one with the picture, but with a different texture.



I implemented the shadow like this:

[java]

@Override

public void simpleInitApp() {



flyCam.setMoveSpeed(25);

rootNode.setShadowMode(ShadowMode.Off);



createWorld();

addLight();

addShadow();

}



private void createWorld() {



for (int i = 0; i < world.length; i++) {

Spatial blockSpatial = assetManager.loadModel(“Models/block.j3o”);

Material mat = assetManager.loadMaterial(world.getType().getMaterial());

//Material mat = new Material(assetManager,“Common/MatDefs/Misc/Unshaded.j3md”);

TextureKey tk = new TextureKey(“Textures/Blocks/blockEarthOvergrown.png”, false);

//mat.setTexture(“ColorMap”, assetManager.loadTexture(tk));

mat.setReceivesShadows(true);

blockSpatial.setMaterial(mat);

blockSpatial.setLocalTranslation(world.getPosition().toRealCoordinates());

blockSpatial.setShadowMode(ShadowMode.CastAndReceive);

rootNode.attachChild(blockSpatial);

}

}



private void addShadow() {

pssmRenderer = new PssmShadowRenderer(assetManager, 1024, 3);

pssmRenderer.setDirection(sun.getDirection());

pssmRenderer.setLambda(0.55f);

pssmRenderer.setShadowIntensity(0.6f);

pssmRenderer.setCompareMode(CompareMode.Software);

pssmRenderer.setFilterMode(FilterMode.PCF4);

pssmRenderer.displayDebug();

viewPort.addProcessor(pssmRenderer);

bsRenderer = new BasicShadowRenderer(assetManager, 512);

bsRenderer.setDirection(sun.getDirection());

//viewPort.addProcessor(bsRenderer);

}



private void addLight() {

sun.setColor(ColorRGBA.White);

rootNode.addLight(sun);



AmbientLight al = new AmbientLight();

al.setColor(ColorRGBA.White.mult(1f));

rootNode.addLight(al);

}

[/java]



Hopefully someone of you can help me, if so many thanks in advance.



Mfg

Dragonblade05

Have you set shadowmode for the ground spatial to Receive?

Hi johncl, thanks for the answer.

I set it to ShadowMode.CastAndReceive.

Each cube also the ground-cubes are created with this method:



[java]

private void createWorld() {



for (int i = 0; i < world.length; i++) {

Spatial blockSpatial = assetManager.loadModel("Models/block.j3o");

Material mat = assetManager.loadMaterial(world.getType().getMaterial());

//Material mat = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");

TextureKey tk = new TextureKey("Textures/Blocks/blockEarthOvergrown.png", false);

//mat.setTexture("ColorMap", assetManager.loadTexture(tk));

mat.setReceivesShadows(true);

blockSpatial.setMaterial(mat);

blockSpatial.setLocalTranslation(world.getPosition().toRealCoordinates());

blockSpatial.setShadowMode(ShadowMode.CastAndReceive);

rootNode.attachChild(blockSpatial);

}

}

[/java]



That means the whole world exists of cubes like in minecraft. And so I set the ShadowMode for everything to CastAndRecieve, but i also tried to set the ground-cubes to Recieve only, with no effect.

Can you confirm the direction of your sun is pointing in the right direction (ie. not straight up or down). Also, what happens if you just put a regular cube in the scene that isn’t one of your models? The normals/tangents might be messed up on the model.



The debug screens are showing all black, meaning there is definitely a problem.

Ok, solved the problem with the missing shadow.

Seems like i had to generate the j3o from the .scene and not the .mesh.xml file, don’t know why this causes that sort of problem.



After all, some shadow is visible, but its not really correctly, maybe because i have set everything to CastAndRecieve?

Don’t know, but here is a image:



http://choppster.org/images/wrongShadow.png



I would be greatfull if someone could help me out again ^^.

It’s a sign!

hehe



Is there nothing above the ground casting that shadow? I’m guessing something is getting into your scene file to cause that, it is shadowing both the ground blocks and the axe wielding mouse block.

@Sploreg:

Yes, i tried it shortly before you wrote it, and yeah, it works, but also not really good.

There i really came across some really weird thing.

I used two boxes:



[java]

Box b = new Box(Vector3f.ZERO, 2, 2, 2);

Geometry geom = new Geometry(“Box”, b);

Material geomMat = new Material(assetManager,“Common/MatDefs/Light/Lighting.j3md”);

geom.setMaterial(geomMat);

geom.setLocalTranslation(5, 2, 5);

geom.setShadowMode(ShadowMode.CastAndReceive);

rootNode.attachChild(geom);

Box b2 = new Box(Vector3f.ZERO, 10, 1, 10);

Geometry geom2 = new Geometry(“Box”, b2);

Material geomMat2 = new Material(assetManager,“Common/MatDefs/Misc/Unshaded.j3md”);

geomMat2.setColor(“Color”, ColorRGBA.Blue);

geom2.setMaterial(geomMat2);

geom2.setLocalTranslation(0, 0, 0);

geom2.setShadowMode(ShadowMode.CastAndReceive);

rootNode.attachChild(geom2);

[/java]



I let the directional light and the shadow rotate around the plane to simulate a day/night-change and at some position the shadow or whatever looks like this:







P.S.: Sry for the double post, but when i click on edit i just get to a page with the title and nothing else…

Hopefully these are not signs, that would just be creepy. xD

Maybe these are the ghosts like in IRobot (for those who don’t know it: http://de.wikipedia.org/wiki/I,Robot%28Film%29) :wink:

@Sploreg said:
It's a sign!
hehe

Is there nothing above the ground casting that shadow? I'm guessing something is getting into your scene file to cause that, it is shadowing both the ground blocks and the axe wielding mouse block.


1 Like

The block.j3o constists of:

-(Node)Models/ogre/block-scene_node

-(Node)block

-(Node)block-entity

-(Node)block-ogremesh

-(Mesh)block-geom-1

-(Mesh)Mesh

as the SceneEditor says…



here you can download the block.j3o if you want: http://choppster.org/files/block.j3o

If you have a texture containing letters, that is mostly either a grafic driver bug, or a misused renderstate.



Since opengl is state based, this can happen, when thhe last used material is the one for the debugtext, and the next one has for whatever reason no new texturestate set.



Usually this kind of error should not happen at all, even when doing stuff seriously wrong.

Hm… yea, but I really don’t get it what I am making so wrong. Cause, i really read the TestShadow.java and TestPssmShadow.java carefully and looked that I implemented it exactly the same way, but they both don’t work as wished.

It don’t think its a problem with my graphicscard or the driver cause the TestShadow.java and TestPssmShadow.java both work fine.

So after all I think its a problem with the export of my blender model using OgreExporter and converting it into j3o.

Maybe there is a problem somewhere. Is there something that could cause something like this?

So, just if someone, is (or maybe will be) encountering the same problem.

I could solve the “cross”-problem with changing the third parameters in the PssmShadowRenderer-Constructor.

If it was less or equal 3 the cross appeared, but with:



[java]

pssmRenderer = new PssmShadowRenderer(assetManager, 1024, 4);

[/java]



it works.



As i can read out of the Light and Shadow Tutorial, this is meant to be the number of shadow maps.