Shadow issue

Hi,
I’m having an issue with shadows. I have a ground which receives shadows, a point-light and a PointLightShadowRenderer, nothing else. So, my question is: Why is there a Shadow on the ground?

If i insert an object which casts a shadow everthing works fine.

The same behaviour is if I use a SpotLightShadowRenderer. The DirectionalLightShadowRenderer is ok.

test-code:
[java]
import com.jme3.app.SimpleApplication;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Quad;
import com.jme3.shadow.EdgeFilteringMode;
import com.jme3.shadow.PointLightShadowRenderer;

public class Main extends SimpleApplication {

public static void main(String[] args) {
    Main app = new Main();
    app.start();
}
PointLightShadowRenderer plsr;

@Override
public void simpleInitApp() {
    rootNode.setShadowMode(ShadowMode.Off);

    // --------------------------------------------
    // Camera
    flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(0, 8, 20));
    cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);

    // --------------------------------------------
    // ground
    Quad ground_quad = new Quad(15, 15);
    Geometry ground_geom = new Geometry("ground_geom", ground_quad);
    Material ground_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    ground_mat.setColor("Color", ColorRGBA.Yellow);
    ground_geom.setMaterial(ground_mat);
    Node ground_node = new Node();
    ground_node.attachChild(ground_geom);
    Quaternion ground_quat = new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X);
    ground_node.setLocalRotation(ground_quat);
    ground_node.setLocalTranslation(-7.5f, 0f, 7.5f);
    rootNode.attachChild(ground_node);

    ground_node.setShadowMode(RenderQueue.ShadowMode.Receive);

    // --------------------------------------------
    // cube
    Box box = new Box(1, 0.1f, 1);
    Geometry box_geom = new Geometry("box_geom", box);
    Material box_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    box_mat.setColor("Color", ColorRGBA.Blue);
    box_geom.setMaterial(box_mat);
    box_geom.setLocalTranslation(-2f, 2f, 0);
    // ############################
    // Uncomment here
    //rootNode.attachChild(box_geom);
    // ############################

    box_geom.setShadowMode(ShadowMode.Cast);

    // --------------------------------------------
    // Point-Light
    PointLight pLight = new PointLight();
    pLight.setPosition(new Vector3f(0, 3f, 0f));
    pLight.setRadius(5);
    rootNode.addLight(pLight);

    // --------------------------------------------
    // ShadowRenderer
    int SHADOWMAP_SIZE = 512;
    plsr = new PointLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
    plsr.setLight(pLight);
    plsr.setEdgeFilteringMode(EdgeFilteringMode.Bilinear);
    plsr.setShadowIntensity(0.5f);
    viewPort.addProcessor(plsr);
}

@Override
public void simpleUpdate(float tpf) {      
}

}
[/java]

looks like a bug. Thanks for the test case, I’m gonna look into it

1 Like

Related to this? http://hub.jmonkeyengine.org/forum/topic/pssmshadow-on-terrain-and-setting-shadowmode/

When there is only shadow receivers and no casters the shadow map is “undefined” :slight_smile:

heh looks like I forgot about that…
We’re in the case there is nothing to cast shadows…
Maybe I could skip the post shadow too in this particular case…

So I guess there is a similiar problem if I have a shadow receiver (red box) and a shadow caster (blue box)?

behind the red box shouldn’t be a shadow.

same code as above except:
[java]
// --------------------------------------------
// box1
Box box = new Box(0.1f, 1, 1);
Geometry box_geom = new Geometry(“box_geom”, box);
Material box_mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
box_mat.setColor(“Color”, ColorRGBA.Blue);
box_geom.setMaterial(box_mat);
box_geom.setLocalTranslation(-3f, 3f, 0);

rootNode.attachChild(box_geom);

box_geom.setShadowMode(ShadowMode.Cast);

// --------------------------------------------
// box2

Box box2 = new Box(0.1f, 2, 2);
Geometry box_geom2 = new Geometry(“box_geom2”, box2);
Material box_mat2 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
box_mat2.setColor(“Color”, ColorRGBA.Red);
box_geom2.setMaterial(box_mat2);
box_geom2.setLocalTranslation(-4f, 3f, 0);

rootNode.attachChild(box_geom2);

box_geom2.setShadowMode(ShadowMode.Receive);
[/java]

I would argue that is expected behavior given how you setup the second geo to only receive. The first geo is the only one being added to the shadow map and since those pixels on the back are farther away they get shadowed. You could probably generate another shadow map of the geometry only set to receive and then filter out values using that but that seems like a lot of wasted time. Most of the time I think people will have the second geo set to cast as well and it would be shadowed anyways.

1 Like

the red box should cast shadows

<cite>@nehon said:</cite> the red box should cast shadows

He set the shadow mode to receive only in his example.

yes that’s what I meant, he shouldn’t :stuck_out_tongue:

But I don’t want that the red box cast shadows :smiley:
So everytime I use shadowMode.receive I must be aware of that strange shadows are on the back of the object and shadows go through it?

At the moment my workaround is for example instead of using a box, to use a self-made box with 6 quads but thats always a fumbling :amused:

Well it works as inteded, the red box is non existent for shadowing, as you told it to be.

If I would set it to ShadowMode.Off … then it is non existent for shadowing. I would think the red cube is an opaque object that only receives shadows and doesn’t cast or let other shadows through because it’s opaque.
Or is there maybe another way to only receive shadows without letting them through like an one side black hole? :-?

@OPM87 said: I would think the red cube is an opaque object that only receives shadows and doesn't cast or let other shadows through because it's opaque.

…except you told the shadow code that it is not opaque.

There are nothing like negative shadows, stuff can cast shadows or not, but it cannot remove shadows casted by other objects.

@OPM87 There is no way around this, I’m afraid.

That’s too bad, nevertheless thank you very much for making such a great engine :slight_smile: