Strange effect with Shadows





Hi!



I’m working with a BaseGame and I’m trying to show shadows in my game, but you as the image depicts the shadow of the model (ninja) turns to be… some sort of amorphous green thing!!! I have used the code posted in the forum, these are the extensions of my code:



Lights in initGame():

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

lightState.setEnabled(true);

lightState.setGlobalAmbient(new ColorRGBA(1, 1, 1, 1));

PointLight pl = new PointLight();

pl.setAmbient(new ColorRGBA(1f, 1f, 1f, 1.0f));

pl.setLocation(new Vector3f(0, 45, 0));

pl.setEnabled(true);

pl.setShadowCaster(true);

lightState.attach(pl);

rootNode.setRenderState(lightState);



PassManager in initGame:

passManager = new BasicPassManager();

ShadowedRenderPass sPass = new ShadowedRenderPass();

sPass.add(rootNode);

sPass.setRenderShadows(true);

sPass.setRenderVolume(true);

sPass.setLightingMethod(ShadowedRenderPass.ADDITIVE);

sPass.addOccluder(rootNode.getChild(“Player”));

passManager.add(sPass);

RenderPass rPass = new RenderPass();

rPass.add(rootNode);

passManager.add(rPass);



Render method:



Renderer r = display.getRenderer();

r.clearStatistics();

r.clearBuffers();

GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER)

.execute();

r.draw(rootNode);

simpleRender();

Renderer renderer = DisplaySystem.getDisplaySystem().getRenderer();

renderer.setBackgroundColor(ColorRGBA.blue);

renderer.clearBuffers();

passManager.renderPasses(renderer);



And update:

passManager.updatePasses(tpf);



Any ideas?

Any help much appreciated, I’m going crazy with this!!

did you try to attach the ShadowTweaker and play with the values?

just for the "amorphous green thing", should be the shadow volume ? Just remove "sPass.setRenderVolume(true);"

Thank you. I'll try and let you know.


orelero said:

just for the "amorphous green thing", should be the shadow volume ? Just remove "sPass.setRenderVolume(true);"


When I do that everything related with shadows removes (not just the green thing).  Anyway, Thank you.
Core-Dump said:

did you try to attach the ShadowTweaker and play with the values?


I tried to change the ShadowedRenderPass parameters with the ShadowTweaker . When I tried the 'MODULATIVE' way everything related with shadows is gone and If I change any other parameter nothing changes in my scene.

In the 'ADDITIVE' mode the green thing is always in the scene (and also the transparent nodes can be seen). When I change the other values of the JSpinners the scene changes (textures more transparent, scene darker, etc), but the green thing is always there.

Any other ideas?

Thank you very much.

That's weird, I thought renderVolume was written for debug purpose  :?



Can you try this ?



Render method:



Renderer r = display.getRenderer();

r.clearStatistics();

r.clearBuffers();

GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER)

            .execute();

r.draw(rootNode);

simpleRender();

Renderer renderer = DisplaySystem.getDisplaySystem().getRenderer();

passManager.renderPasses(renderer);



And update:


passManager.updatePasses(tpf);
r.updateGeometricState(tpf, true);

and change this also:



PassManager in initGame:


passManager = new BasicPassManager();
ShadowedRenderPass sPass = new ShadowedRenderPass();
sPass.add(rootNode);
sPass.setRenderShadows(true);
sPass.setRenderVolume(false);
sPass.setLightingMethod(ShadowedRenderPass.MODULATIVE);
sPass.addOccluder(rootNode.getChild("Player"));
passManager.add(sPass);
RenderPass rPass = new RenderPass();
rPass.add(rootNode);
passManager.add(rPass);

orelero said:

That's weird, I thought renderVolume was written for debug purpose  :?

Can you try this ?

Render method:

Renderer r = display.getRenderer();
r.clearStatistics();
r.clearBuffers();
GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER)
            .execute();
r.draw(rootNode);
simpleRender();
Renderer renderer = DisplaySystem.getDisplaySystem().getRenderer();
passManager.renderPasses(renderer);

And update:

passManager.updatePasses(tpf);
r.updateGeometricState(tpf, true);




I'm sorry but I don't know which kind of object is the last 'r' (A Render doesn't have this method)...
orelero said:

and change this also:

PassManager in initGame:

passManager = new BasicPassManager();
ShadowedRenderPass sPass = new ShadowedRenderPass();
sPass.add(rootNode);
sPass.setRenderShadows(true);
sPass.setRenderVolume(false);
sPass.setLightingMethod(ShadowedRenderPass.MODULATIVE);
sPass.addOccluder(rootNode.getChild("Player"));
passManager.add(sPass);
RenderPass rPass = new RenderPass();
rPass.add(rootNode);
passManager.add(rPass);




I'd tried this before. The 'green thing' disappears but I can't see any shadow. If it may help I'm using a PointLight in the scene.

Thank you for trying.

oeps sorry, it was supposed to be

rootNode.updateGeometricState(tpf, true);

but you may not need it since u r in BaseGame



Edit:


I'd tried this before. The 'green thing' disappears but I can't see any shadow. If it may help I'm using a PointLight in the scene.


Did you also apply the other changes I posted even before ?

Yes, I tried. I don' know what's happening, I've look through it several times.

Can’t help you more I’m just a newbie at Jme.

I feel stupid to steer you to that simple example I made:

http://www.jmonkeyengine.com/wiki/doku.php?id=working_with_shadows_-_from_basegame_to_standardgame

but maybe it could help (needs some comments tho’ !)

I think a lot of people are scratching there heads over this, which is why you haven't gotten more help.

A lot of times this weird issues turns out to be a forgotten updateRenderState(), however you should run the shadowPass test and see if everything looks okay there.  And maybe verify you have current vcard drivers.



I read through your pseudo code and everything looks okay to me, except for this:

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



I am not sure that is needed since you are calling the pass manager to render. 



Also you are clearing the vcard buffers then drawing your rootNode then clearing the buffers again and then setting the background color and finally rendering your shadows, I think you may want this order of operations: clearBuffers --> setBackground --> render stuff

basixs said:

I think a lot of people are scratching there heads over this, which is why you haven't gotten more help.
A lot of times this weird issues turns out to be a forgotten updateRenderState(), however you should run the shadowPass test and see if everything looks okay there.  And maybe verify you have current vcard drivers.

I read through your pseudo code and everything looks okay to me, except for this:

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


I am not sure that is needed since you are calling the pass manager to render. 

Also you are clearing the vcard buffers then drawing your rootNode then clearing the buffers again and then setting the background color and finally rendering your shadows, I think you may want this order of operations: clearBuffers --> setBackground --> render stuff


I've rewrited the render method. This is the new code:


protected void render(float interpolation) {
      Renderer r = display.getRenderer();
      r.clearStatistics();
      r.clearBuffers();
      r.draw(rootNode);
      Renderer renderer = DisplaySystem.getDisplaySystem().getRenderer();
      passManager.renderPasses(renderer);
      simpleRender();
}



With this render method the 'green thing' disappears in both cases (ADDITIVE and MODULATIVE). However, nothing changes when I play with the shadow parameters in the MODULATIVE case. In the ADDITIVE case, things changes but I never see the shadow.

I added this: setShadowCaster(true) to all lights in the scene. I want to make sure that I don't have to add anything more to any other nodes in order to see the shadows.

Thank you for your help.

Hmm, I really don't know then; one thing though.  Why are you getting 2 renderers?? Why not just use the first one ® for the renderPasses() method also?