Shadow problem

Hey all i have some questions about shadows,



I’m currently trying to get shadows working correctly in my extension of basegame. I have basic shadows working, however i also have an animated dwarf thats uses a JointController to play animations. The shadows on the dwarfs aren’t correctly updated, the previous location of the axe is shown as a shadow in mid-air. ( not just the axe, but the axe is clearly visible in the picture)



http://www.imgsync.com/view/img/3872267shadowbug.JPG



i came across a post http://www.jmonkeyengine.com/jmeforum/index.php?topic=6539.0 that mentions something about set setHasDirtyVertices(true) which might be what i need, but where/how do i set this ?



What is the difference between shadowpass.add(spatial)  and shadowpass.addOccluder(spatial) ?

from what i can see if i play around with the shadowtweaker is that if u only add something in the occluder it wont give shadow depending on the lightningmethod while only adding via add it will never give shadow.



why can’t i add a terrainblock as occluder ? if i do this the game will start up and keep running but never display anything, when i open the taskmanager it says the game is not responding.



and my final question is how do you let the shadowpass play nice with semitransparent objects ?

if i use modulative it does render most object correct but when i use additive it doesent



i also set the minstencilbits manually on 4 but this doesn’t seem to make any difference if i leave it out.



some code i use



the terrainblock i use

      FaultFractalHeightMap heightMap = new FaultFractalHeightMap(512, 15, 4,
            30, 0.8f);
      Vector3f terrainScale = new Vector3f(10, 1f, 10);
      heightMap.setHeightScale(0.5f);
      terrain = new TerrainBlock("Terrain", heightMap.getSize(),
            terrainScale, heightMap.getHeightMap(), new Vector3f(0, 0, 0),
            false);
      terrain.setDetailTexture(1, 64);

      terrain.setModelBound(new BoundingBox());
      terrain.updateModelBound();



the renderpasses i have

      normalPass.add(rootNode);
      normalPass.setEnabled(true);
      passManager = new BasicPassManager();
      passManager.add(normalPass);
      passManager.add(shadowPass);

      shadowPass.addOccluder(dude);
      shadowPass.setLightingMethod(ShadowedRenderPass.MODULATIVE);
      shadowPass.setRenderShadows(true);
      new ShadowTweaker(shadowPass).setVisible(true);



and my render method

      Renderer r = display.getRenderer();
      r.clearBuffers();
      passManager.renderPasses(r);



any help is appreciated

It could very well be that the dangling shadow is the self shadow of the model… I have not a lot of experience, but I would guess you need to also update the shadow pass geometry to reflect the animation, but I don't know if it is possible… (I am assuming the screenshot only is with one shadow-caster light)

In the picture above i have 3 lights that are shadow casters, i also tried it with only 1 light  but the problem is the same. In the update method i also call

passManager.updatePasses(tpf);



The shadow of the dwarf is only update after i move him around (translate his position). The floating axe shadow is the position his axe was when i stopped moving him.



this picture shows it with only 1 light and after the animation of the dwarf has run for some time



This picture clearly shows that the shadow of the dwarf is not updated by the animation.



also i noticed this strange shadow into oblivion ??  the only items i have added are the quad that is used as the floor, 2 boxes and the model.

Howcome there is a shadow on well basically “nothing”





this last picture also shows that the floating shadow is only visible from 1 side






Ok i can fix the shadow from the dwarf by adding

      for (int i = 0; i < ((Node) model).getQuantity(); i++)
      {
         Geometry geom = ((Geometry) ((Node) model).getChild(i));

         for (int j = 0; j < geom.getBatchCount(); j++)
         {
            geom.getBatch(j).setHasDirtyVertices(true);
         }
      }


in the update method

Is there a better way to do this ?
So that just leaves these questions
Hellmaster said:


What is the difference between shadowpass.add(spatial)  and shadowpass.addOccluder(spatial) ?
from what i can see if i play around with the shadowtweaker is that if u only add something in the occluder it wont give shadow depending on the lightningmethod while only adding via add it will never give shadow.

why can't i add a terrainblock as occluder ? if i do this the game will start up and keep running but never display anything, when i open the taskmanager it says the game is not responding.

and my final question is how do you let the shadowpass play nice with semitransparent objects ?
if i use modulative it does render most object correct but when i use additive it doesent

That seems to be like the right way of doing it, if you ask me… this invalidates the vertex data, and has to be re-read from the current version. (Of course there is a performance hit with this)



As for the other part, I don't know, really… But from the Javadoc:


list of occluders that will be casting shadows in this pass. If no occluders set, pass acts like normal RenderPass.


In other words, add simply adds the object to render, and addOccluder means its shadow will be rendered, buy not the object itself (at least by this pass)