Can't see shadows

Hi, I've been dabbling with JME for a few months now but I'm stuck on shadow rendering.  The JME example works fine, but all of my attempts have yielded nothing.  See my example code below, everything in the scene is rendering fine but I just can't get the damn shadow-pass to work. 



BTW I'm using GameStates and I suspect I'm not understanding something… any ideas please?



package DT4;
import com.jme.image.Texture;
import com.jme.renderer.pass.Pass;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;

import com.jme.bounding.BoundingBox;
import com.jme.light.DirectionalLight;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.pass.BasicPassManager;
import com.jme.renderer.pass.RenderPass;
import com.jme.renderer.pass.ShadowedRenderPass;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.LightState;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueueManager;
import com.jmex.game.StandardGame;
import com.jmex.game.state.BasicGameState;
import com.jmex.game.state.GameStateManager;
import com.jmex.model.collada.ColladaImporter;


public class BasicState extends BasicGameState {
    private LightState lightState;
    StandardGame MainGame;
    private BasicPassManager pManager;
    private static ShadowedRenderPass sPass = new ShadowedRenderPass();
    private Node occluders;
    Box b;
    Box g;

    public BasicState(String arg0) {    
        super(arg0);
    }
   
    public void Init()
    {     
        System.out.println("BasicState Init()");
        DisplaySystem.getDisplaySystem().getRenderer().setBackgroundColor(ColorRGBA.gray);    
        
        DirectionalLight dr = new DirectionalLight();
        dr.setEnabled(true);
        dr.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
        dr.setAmbient(new ColorRGBA(.2f, .2f, .2f, .3f));
        dr.setDirection(new Vector3f(0.5f, -0.4f, 0).normalizeLocal());
        dr.setShadowCaster(true);
 
        PointLight pl = new PointLight();
        pl.setEnabled(true);
        pl.setDiffuse(new ColorRGBA(.7f, .7f, .7f, 1.0f));
        pl.setAmbient(new ColorRGBA(.25f, .25f, .25f, .25f));
        pl.setLocation(new Vector3f(0,500,0));
        pl.setShadowCaster(true);

        DirectionalLight dr2 = new DirectionalLight();
        dr2.setEnabled(true);
        dr2.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
        dr2.setAmbient(new ColorRGBA(.2f, .2f, .2f, .4f));
        dr2.setDirection(new Vector3f(-0.2f, -0.3f, .2f).normalizeLocal());
        dr2.setShadowCaster(true);
       
        lightState=DisplaySystem.getDisplaySystem().getRenderer().createLightState();
        lightState.setEnabled(true);
        lightState.setTwoSidedLighting(true);
        lightState.detachAll();
        lightState.attach(dr);
        lightState.attach(dr2);
        lightState.attach(pl);
        lightState.setGlobalAmbient(new ColorRGBA(0.6f, 0.6f, 0.6f, 1.0f));
       
        rootNode.setRenderState(lightState);
       
        // create ground plane
        g= new Box("ground", new Vector3f(), 1000,0.1f,1000);
        g.setModelBound(new BoundingBox());
        g.updateModelBound();
        g.setLocalTranslation(new Vector3f(0,-10,0));
        rootNode.attachChild(g);
 
        setupOccluders();
       
        pManager = new BasicPassManager();
        sPass.add(rootNode);
        sPass.addOccluder(occluders);
        sPass.setRenderShadows(true);
        sPass.setLightingMethod(ShadowedRenderPass.ADDITIVE);
        pManager.add(sPass);

        RenderPass rPass = new RenderPass();
        pManager.add(rPass);
    }
   
 
    private void setupOccluders() {
        TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(
        TextureManager.loadTexture(BasicState.class.getClassLoader().getResource(
            "DT4/texture1.png"),
            Texture.MM_LINEAR_LINEAR,
            Texture.FM_LINEAR));
 
        occluders = new Node("occs");
        occluders.setRenderState(ts);
        rootNode.attachChild(occluders);
       
        for (int i = 0; i < 10; i++) {
            Box b = new Box("box", new Vector3f(), 3, 30, 3);
            b.setModelBound(new BoundingBox());
            b.updateModelBound();
            float x = (float) Math.random() * 100 - 75;
            float z = (float) Math.random() * 100 - 75;
            b.setLocalTranslation(new Vector3f(x, -10, z));
            occluders.attachChild(b);
        }
       occluders.lock();
    } 
 
    public void update(float tpf) {    
       
        rootNode.updateGeometricState(tpf,true);
        rootNode.updateRenderState();
        pManager.updatePasses(tpf);     
    }
   
    public void render(float tpf) {

        pManager.renderPasses(DisplaySystem.getDisplaySystem().getRenderer());
    }

    public void SetMainGame(StandardGame game) {
        MainGame=game;       
    }
   
}


Ive noticed sometimes there is a conflict between global ambient and ambient colored lighting in regards to shadows. Try commenting out the global ambient and the 2 directional lights and see if you can get shadows with just a simple point light

light = new PointLight();
          light.setDiffuse(new ColorRGBA(1f, 1f, 1f, .8f));
         light.setAmbient(new ColorRGBA(1f, 1f, 1f, .1f));
         light.setLocation(new Vector3f(0, 18, 0));
         light.setShadowCaster(true);
         light.setEnabled(true);


also I use ShadowedRenderPass.MODULATIVE instead of additive, I got better performance that way.
If that doesnt help im out of ideas :) good luck

Hi, thanks for the input. Still no shadows.  Although without ambient light the scene is much darker than I would have expected, only just seeing some slight lighting from a single point light - but it's almost completely black.



I've been looking for some examples online of using the passmanager in conjunction with a gamesate and have not been successful in finding a good example.



Further suggestions are indeed welcome.




Check this thread, it might help you:



http://www.jmonkeyengine.com/jmeforum/index.php?topic=6539.0

Ahh thanks!  That's helped a huge amount. 



The stencilbits settings was my problem.



I've been relying on google to search the JME forums - which is obviously not a good idea then!


Might be if you want to do searches for whole words and be able to exclude some key words, but I would say not in general.  :wink: