Shadow problem: shadow of object on other objects

First some pictures:



As you can see the shadow of the object on itself is correct, but the smaller sphere shouldn’t be visible since the big one covers it from the light source. So why is it visible?


I don't see any shadowing at all in that image, only basic openGL lighting…

well that would explain a lot but when i turn of the shadows with the tweaker it certanly changes:

what kind of shadow do you use?



check out jmetest.renderer.TestShadowPass or jmetest.renderer.TestDirectionalShadowMapPass to see how to enable shadowing.

I didn't find any differences in using of shadowpass



well here some code maybe somone sees the error(please excuse some german names … bad habit of mine):



                        HashMap<String, Sphere> planeten = new HashMap<String, Sphere>(); 

Node occluders = new Node();

new ShadowTweaker(sPass).setVisible(true);



rootNode.attachChild(scene);



/** Set up a basic, default light. /

                        PointLight light = new PointLight();

                        //light.setDiffuse( new ColorRGBA(2.4f,1.4f,0.15f,0.1f));

                        //light.setAmbient( new ColorRGBA(2.4f,1.4f,0.15f,0.1f) );

                        light.setLocation( new Vector3f(65,0,65) );

                        light.setShadowCaster(true);

                        light.setEnabled( true );

     

                        /
* Attach the light to a lightState and the lightState to rootNode. */

                        lightState = display.getRenderer().createLightState();

                        lightState.setEnabled( true );

                        lightState.attach( light );

                        scene.setRenderState( lightState );



       

                        materialState = display.getRenderer().createMaterialState();

                        materialState.setEnabled(true);

                        materialState.setMaterialFace(MaterialFace.FrontAndBack);

                        materialState.setDiffuse(light.getDiffuse());

                        materialState.setShininess(100);

                        //materialState.setColorMaterial(ColorMaterial.Emissive);

                        scene.setRenderState(materialState);

       

       

       

                        cullState = display.getRenderer().createCullState();

                        cullState.setCullFace(Face.Back);

                        cullState.setEnabled(true);

                        scene.setRenderState(cullState);

       

                        zBufferState = display.getRenderer().createZBufferState();

                        //zBufferState.setFunction(ZBufferState.TestFunction.LessThan);

                        zBufferState.setEnabled(true);

                        scene.setRenderState(zBufferState);





                        /URL mond = Sonnensystem.class.getClassLoader().getResource("ressourcen/mond.obj");

                        FormatConverter converter=new ObjToJme();

                        Spatial map;



                        ByteArrayOutputStream BO=new ByteArrayOutputStream();

                        try

                      {

                            converter.convert(mond.openStream(), BO);

                            map=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));

                            map.setLocalScale(4f);



                            map.setModelBound(new BoundingBox());

                            map.updateModelBound();

                            scene.attachChild(map);

                      }

                      catch (Exception e)

                      {

                            System.out.println("Damn exceptions! O_o n" + e);

                            e.printStackTrace();

                            System.exit(0);

                        }
/



     





planeten.put("Sonne", new Sphere("Sonne", new Vector3f(65,0,65),45,45,10));

planeten.put("Merkur", new Sphere("Merkur", new Vector3f(45,0,45),15,15,2));

planeten.put("Venus", new Sphere("Venus", new Vector3f(40,0,40),15,15,2));

planeten.put("Erde", new Sphere("Erde", new Vector3f(30,0,30),15,15,3));

planeten.put("Mond", new Sphere("Mond", new Vector3f(27,0,27),15,15,1));



/planeten.put("Mars", new Sphere("Mars", new Vector3f(,0),));

planeten.put("Jupiter", new Sphere("Jupiter", new Vector3f(,0),));

planeten.put("Saturn", new Sphere("Saturn", new Vector3f(,0),));

planeten.put("Uranus", new Sphere("Uranus", new Vector3f(,0),));

planeten.put("Neptun", new Sphere("Neptun", new Vector3f(,0),));

planeten.put("Pluto", new Sphere("Pluto", new Vector3f(,0),));
/



MaterialState sunState = display.getRenderer().createMaterialState();

sunState.setAmbient(new ColorRGBA(2.4f,1.4f,0.15f,1));

sunState.setDiffuse(new ColorRGBA(2.4f,1.1f,0.15f,1));

                        planeten.get("Sonne").setRenderState(sunState);

                        planeten.get("Sonne").updateRenderState();



                        Quaternion roll90 = new Quaternion();

                        roll90.fromAngleAxis( FastMath.PI/2 , new Vector3f(65,0,65) );

       

for(Sphere s: planeten.values())

{

s.setModelBound(new BoundingSphere());

s.updateModelBound();

scene.attachChild(s);

if(!s.getName().equals("Sonne"))

{

occluders.attachChild(s);

s.setLocalRotation(roll90);

}

/else

{

scene.attachChild(s);

}
/

}

occluders.lock();

scene.attachChild(occluders);

scene.updateGeometricState(0.0f, true);







rPass.add(scene);

rPass.setEnabled(true);



sPass.add(scene);

sPass.addOccluder(occluders);

sPass.setShadowColor(ColorRGBA.black);

sPass.setEnabled(true);

sPass.setRenderShadows(true);

sPass.setLightingMethod(ShadowedRenderPass.LightingMethod.Additive);



pManager.add(rPass);

pManager.add(sPass);



rootNode.setCullHint(CullHint.Dynamic);

rootNode.updateWorldBound();

rootNode.updateModelBound();

rootNode.updateGeometricState( 0.0f, true );

                        rootNode.updateRenderState();

rootNode.lock();

Please post a complete SimplePassGame test, rather than making someone guess at what game implementation you are using and your global variables…



(test should be based off of SimplePassGame and one should be able to copy/paste it in its entirety and then run it)

there you are … entire sourcecode:



package ownStuff;



import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.io.OutputStream;

import java.net.URL;

import java.util.HashMap;

import java.util.logging.Level;

import java.util.logging.Logger;



import jmetest.flagrushtut.lesson9.Lesson9;

import jmetest.renderer.ShadowTweaker;



import com.jme.app.BaseGame;

import com.jme.bounding.BoundingBox;

import com.jme.bounding.BoundingSphere;

import com.jme.input.FirstPersonHandler;

import com.jme.input.InputHandler;

import com.jme.input.KeyBindingManager;

import com.jme.input.KeyInput;

import com.jme.light.DirectionalLight;

import com.jme.light.LightNode;

import com.jme.light.PointLight;

import com.jme.math.FastMath;

import com.jme.math.Quaternion;

import com.jme.math.Vector3f;

import com.jme.renderer.Camera;

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.Line;

import com.jme.scene.Node;

import com.jme.scene.Spatial;

import com.jme.scene.Spatial.CullHint;

import com.jme.scene.Spatial.LightCombineMode;

import com.jme.scene.shape.Box;

import com.jme.scene.shape.Quad;

import com.jme.scene.shape.Sphere;

import com.jme.scene.state.CullState;

import com.jme.scene.state.LightState;

import com.jme.scene.state.MaterialState;

import com.jme.scene.state.ZBufferState;

import com.jme.scene.state.CullState.Face;

import com.jme.scene.state.MaterialState.ColorMaterial;

import com.jme.scene.state.MaterialState.MaterialFace;

import com.jme.system.DisplaySystem;

import com.jme.system.JmeException;

import com.jme.util.GameTaskQueue;

import com.jme.util.GameTaskQueueManager;

import com.jme.util.Timer;

import com.jme.util.export.binary.BinaryImporter;

import com.jmex.model.converters.FormatConverter;

import com.jmex.model.converters.ObjToJme;











public class Sonnensystem extends BaseGame{



private static final Logger logger = Logger.getLogger(Sonnensystem.class.getName());



protected Node rootNode = new Node();

protected Node scene = new Node();

protected Camera cam;

protected InputHandler input;

protected Timer timer;

protected LightState lightState;

protected MaterialState materialState;

protected CullState cullState;

protected ZBufferState zBufferState;

protected RenderPass rPass = new RenderPass();

protected ShadowedRenderPass sPass = new ShadowedRenderPass();

protected BasicPassManager pManager = new BasicPassManager();

   

public static void main(String[] args) {

Sonnensystem app = new Sonnensystem();

app.setConfigShowMode(ConfigShowMode.AlwaysShow);

app.start();

}



@Override

protected void cleanup() {

// TODO Auto-generated method stub



}



@Override

protected void initGame() {



HashMap<String, Sphere> planeten = new HashMap<String, Sphere>(); 

Node occluders = new Node();

new ShadowTweaker(sPass).setVisible(true);



rootNode.attachChild(scene);



/** Set up a basic, default light. /

        PointLight light = new PointLight();

        //light.setDiffuse( new ColorRGBA(2.4f,1.4f,0.15f,0.1f));

        //light.setAmbient( new ColorRGBA(2.4f,1.4f,0.15f,0.1f) );

        light.setLocation( new Vector3f(65,0,65) );

        light.setShadowCaster(true);

        light.setEnabled( true );

     

        /
* Attach the light to a lightState and the lightState to rootNode. /

        lightState = display.getRenderer().createLightState();

        lightState.setEnabled( true );

        lightState.attach( light );

        scene.setRenderState( lightState );



       

        materialState = display.getRenderer().createMaterialState();

        materialState.setEnabled(true);

        materialState.setMaterialFace(MaterialFace.FrontAndBack);

        materialState.setDiffuse(light.getDiffuse());

        materialState.setShininess(100);

        //materialState.setColorMaterial(ColorMaterial.Emissive);

        scene.setRenderState(materialState);

       

       

       

        cullState = display.getRenderer().createCullState();

        cullState.setCullFace(Face.Back);

        cullState.setEnabled(true);

        scene.setRenderState(cullState);

       

        zBufferState = display.getRenderer().createZBufferState();

        //zBufferState.setFunction(ZBufferState.TestFunction.LessThan);

        zBufferState.setEnabled(true);

        scene.setRenderState(zBufferState);





        /URL mond = Sonnensystem.class.getClassLoader().getResource("ressourcen/mond.obj");

        FormatConverter converter=new ObjToJme();

        Spatial map;



        ByteArrayOutputStream BO=new ByteArrayOutputStream();

        try {

            converter.convert(mond.openStream(), BO);

            map=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));

            map.setLocalScale(4f);



            map.setModelBound(new BoundingBox());

            map.updateModelBound();

            scene.attachChild(map);

        } catch (Exception e) {

            System.out.println("Damn exceptions! O_o n" + e);

            e.printStackTrace();

            System.exit(0);

        }
/



     





planeten.put("Sonne", new Sphere("Sonne", new Vector3f(65,0,65),45,45,10));

planeten.put("Merkur", new Sphere("Merkur", new Vector3f(45,0,45),15,15,2));

planeten.put("Venus", new Sphere("Venus", new Vector3f(40,0,40),15,15,2));

planeten.put("Erde", new Sphere("Erde", new Vector3f(30,0,30),15,15,3));

planeten.put("Mond", new Sphere("Mond", new Vector3f(27,0,27),15,15,1));



/planeten.put("Mars", new Sphere("Mars", new Vector3f(,0),));

planeten.put("Jupiter", new Sphere("Jupiter", new Vector3f(,0),));

planeten.put("Saturn", new Sphere("Saturn", new Vector3f(,0),));

planeten.put("Uranus", new Sphere("Uranus", new Vector3f(,0),));

planeten.put("Neptun", new Sphere("Neptun", new Vector3f(,0),));

planeten.put("Pluto", new Sphere("Pluto", new Vector3f(,0),));
/



MaterialState sunState = display.getRenderer().createMaterialState();

sunState.setAmbient(new ColorRGBA(2.4f,1.4f,0.15f,1));

sunState.setDiffuse(new ColorRGBA(2.4f,1.1f,0.15f,1));

        planeten.get("Sonne").setRenderState(sunState);

        planeten.get("Sonne").updateRenderState();



        Quaternion roll90 = new Quaternion();

        roll90.fromAngleAxis( FastMath.PI/2 , new Vector3f(65,0,65) );

       

for(Sphere s: planeten.values())

{

s.setModelBound(new BoundingSphere());

s.updateModelBound();

scene.attachChild(s);

if(!s.getName().equals("Sonne"))

{

occluders.attachChild(s);

s.setLocalRotation(roll90);

}

/else

{

scene.attachChild(s);

}
/

}

occluders.lock();

scene.attachChild(occluders);

scene.updateGeometricState(0.0f, true);







rPass.add(scene);

rPass.setEnabled(true);



sPass.add(scene);

sPass.addOccluder(occluders);

sPass.setShadowColor(ColorRGBA.black);

sPass.setEnabled(true);

sPass.setRenderShadows(true);

sPass.setLightingMethod(ShadowedRenderPass.LightingMethod.Additive);



pManager.add(rPass);

pManager.add(sPass);



rootNode.setCullHint(CullHint.Dynamic);

rootNode.updateWorldBound();

rootNode.updateModelBound();

rootNode.updateGeometricState( 0.0f, true );

        rootNode.updateRenderState();

rootNode.lock();

}



@Override

protected void initSystem() {



//Auslesen der daten aus dem Settingfenster

try {

            display = DisplaySystem.getDisplaySystem(settings.getRenderer());

            display.setMinStencilBits(8);

            display.setMinAlphaBits(4);

            display.setMinDepthBits(8);

            display.setMinSamples(4);

            display.createWindow(

                settings.getWidth(),

                settings.getHeight(),

                settings.getDepth(),

                settings.getFrequency(),

                settings.isFullscreen());

            cam =

                display.getRenderer().createCamera(

                    settings.getWidth(),

                    settings.getHeight());



        } catch (JmeException e) {

            logger.log(Level.SEVERE, "Could not create displaySystem", e);

            System.exit(1);

        }



       

       

        display.getRenderer().setBackgroundColor(ColorRGBA.black); //Hintergrund Schwarz

        //Kameraperspektive/position

        cam.setFrustum(1.0f, 1000.0f, -0.55f, 0.55f, 0.4125f, -0.4125f);

        Vector3f loc = new Vector3f(4.0f, 0.0f, 0.0f);

        Vector3f left = new Vector3f(0.0f, -1.0f, 0.0f);

        Vector3f up = new Vector3f(0.0f, 0.0f, 1.0f);

        Vector3f dir = new Vector3f(-1.0f, 0f, 0.0f);

        cam.setFrame(loc, left, up, dir);



        display.getRenderer().setCamera(cam);



        input = new FirstPersonHandler(cam, 50, 1); //1st Person handler erstellen



        /
* Get a high resolution timer for FPS updates. /

        timer = Timer.getTimer();



        KeyBindingManager.getKeyBindingManager().set(

              "exit",

              KeyInput.KEY_ESCAPE);



}



@Override

protected void reinit() {

// TODO Auto-generated method stub



}



@Override

protected void render(float interpolation) {





display.getRenderer().clearBuffers();

//display.getRenderer().draw(scene);

pManager.renderPasses(display.getRenderer());

}



@Override

protected void update(float interpolation) {

/
* Recalculate the framerate. /

        timer.update();

          /
* Update tpf to time per frame according to the Timer. /

        float tpf = timer.getTimePerFrame();

        GameTaskQueueManager.getManager().getQueue(GameTaskQueue.UPDATE).execute();

        if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit", false)) {

            finish();

        }



        /
* Check for key/mouse updates. */

        input.update(tpf);

        pManager.updatePasses(tpf);

        scene.updateGeometricState(tpf, true);

       

}



   

}



works fine, except the shadows.

Try to set Stencilbits and use this ZBuffer setting


display.setMinStencilBits(8);
zBufferState.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);



also use [ code ] [ / code]  tags ;)

lol, good catch core-dump; sometimes it's too obvious :slight_smile:

well thanks buddies it seems it's right now. I'm still quiet a beginner with JME so be prepared for more obvious questions ^^



PS: I'll rembember the Code tags