People,
Where is it possible to find a good example of StandardGame producing shadows in an scene with a few objects. Let's say a simple example as light directed to an object and the shadow of this last projected on another object. So simple as that…
Any idea where is a clear example of StandardGame and shadows?
Thank you.
Should be nearly identical to the SimpleGame based examples with only slight changes…
I’m very interested in this too ! I’ve been trying to make these shadows working in my FixedFramerate game for like 10 hours with no success.
I read a tone of messages on this forum and checked my code many times. Tryed many combinations of source lights.
I checked the stencilbits (=8 or 4), pManager.updatePasses(tpf) is made in the end of update, etc
I also checked if shadows work for me tx to the demo and it’s the case.
I used for each try, the shadow tweaker…
Nothing :x
Even a small help would be very appreciated
EDIT: my project file here if anyone have time to have a look: http://www.mediafire.com/?xanydyb3txx
Perhaps someone else here has done or is willing to put together a simple example of StandardGame with shadows?
i am working on a physics play-area.
Right now it uses StandardGame / Gamestates, has a reflection and shadows pass.
You can grab a snapshot of the eclipse project here:
physics fun
webstart (java 6 needed)
(press space to release an object)
i’ll post it again once its ‘done’.
(muahaha like i will ever get something ‘done’ … }:-@)
edit:
basically the interesting part is only the following Gamestate:
public class RenderPassGamestate extends GameState {
private Renderer renderer = DisplaySystem.getDisplaySystem().getRenderer();
private ShadowedRenderPass shadowPass = null;
private BasicPassManager pManager = null;
public RenderPassGamestate(Node scene) {
pManager = new BasicPassManager();
shadowPass = new ShadowedRenderPass();
shadowPass.add(scene);
shadowPass.addOccluder(scene);
shadowPass.setLightingMethod(ShadowedRenderPass.MODULATIVE);
shadowPass.setRenderShadows(true);
pManager.add(shadowPass);
}
@Override
public void cleanup() {
}
@Override
public void render(float tpf) {
pManager.renderPasses(renderer);
}
@Override
public void update(float tpf) {
pManager.updatePasses(tpf);
}
}
hehe, thanks Core-Dump.
Thanks a lot CoreDump ! ! I’m gonna have a look right now
I tryed your demo and it’s really funny to play with but I’m not sure if the rendering of the balls are supposed to be like this:
its in a very early state, there are many known problems:
- somtimes a few GUI elements are missing in jME DesktopState
- reflections of boxes seems to be wrong
- overall poor performance
- jME Desktop somehow caches keyboard events even if disabled
- creating the physics representation for cylinders wrong
- the code is overall needs to be cleaned up
and many more
Even with your source code I still can't see any difference with what I've done to enable shadow casting
If no suggestion, I'm gonna restart my project from scratch and try to make shadowing work in a first time.
Ok I rewrote the code in the simplest manner I could and it doesn't work at all.
Anyone can try ? Maybe the problem is my hardware configuration.
public class Central extends FixedFramerateGame
{
private static final Logger logger = Logger.getLogger(Central.class
.getName());
protected Camera cam;
protected Node rootNode;
protected InputHandler input;
protected Timer timer;
protected Node fpsNode;
protected Text fps;
protected int alphaBits = 0;
protected int depthBits = 8;
protected int stencilBits = 4;
protected int samples = 0;
protected float tpf;
protected boolean showDepth = false;
protected boolean showBounds = false;
protected boolean showNormals = false;
protected WireframeState wireState;
protected LightState lightState;
public static String fontLocation = Text.DEFAULT_FONT;
protected StringBuffer updateBuffer = new StringBuffer( 30 );
protected StringBuffer tempBuffer = new StringBuffer();
protected boolean pause;
protected BasicPassManager pManager;
protected static ShadowedRenderPass shadowPass = new ShadowedRenderPass();
//********************************
public void createScene()
{
Node scene = new Node();
TextureState sandTextureState = getDisplay().getRenderer().createTextureState();
TextureState grassTextureState = getDisplay().getRenderer().createTextureState();
URL sandURL = Central.class.getClassLoader().getResource("resources/sand.png");
sandTextureState.setTexture(TextureManager.loadTexture(sandURL,Texture.MM_LINEAR, Texture.FM_LINEAR));
Node boxes = new Node();
Box b = new Box("box", new Vector3f(), new Vector3f(1,1,1));
b.setRenderState(sandTextureState);
b.setLocalTranslation(2,10,2);
b.setModelBound(new BoundingBox());
b.updateModelBound();
URL grassURL = Central.class.getClassLoader().getResource("resources/grass.png");
grassTextureState.setTexture(TextureManager.loadTexture(grassURL,Texture.MM_LINEAR, Texture.FM_LINEAR));
Quad quad = new Quad("ground",40,40);
quad.setRenderState(grassTextureState);
quad.setLocalTranslation(0,0,0);
Quaternion roll90 = new Quaternion();
roll90.fromAngleAxis( FastMath.PI/2 , new Vector3f(1,0,0) );
quad.setLocalRotation( roll90 );
quad.setModelBound(new BoundingBox());
quad.updateModelBound();
boxes.attachChild(b);
scene.attachChild(quad);
scene.attachChild(boxes);
rootNode.attachChild(scene);
shadowPass.add(rootNode);
shadowPass.addOccluder(boxes);
shadowPass.setLightingMethod(ShadowedRenderPass.MODULATIVE);
shadowPass.setRenderShadows(true);
RenderPass rPass = new RenderPass();
rPass.add(fpsNode);
pManager.add(shadowPass);
}
public void init()
{
new ShadowTweaker(shadowPass).setVisible(true);
pManager = new BasicPassManager();
MouseInput.get().setCursorVisible(true);
createScene();
}
public void step()
{
}
public void render()
{
}
//*******DO NO TOUCH BELOW*********
protected void initGame()
{
pManager = new BasicPassManager();
rootNode = new Node( "rootNode" );
ZBufferState buf = getDisplay().getRenderer().createZBufferState();
buf.setEnabled( true );
buf.setFunction( ZBufferState.CF_LEQUAL );
rootNode.setRenderState( buf );
fps = Text.createDefaultTextLabel( "FPS label" );
fps.setCullMode( SceneElement.CULL_NEVER );
fps.setTextureCombineMode( TextureState.REPLACE );
fpsNode = new Node( "FPS node" );
fpsNode.setRenderState( fps.getRenderState( RenderState.RS_ALPHA ) );
fpsNode.setRenderState( fps.getRenderState( RenderState.RS_TEXTURE ) );
fpsNode.attachChild( fps );
fpsNode.setCullMode( SceneElement.CULL_NEVER );
DirectionalLight dr1 = new DirectionalLight();
dr1.setEnabled(true);
dr1.setDiffuse(ColorRGBA.white);
dr1.setAmbient(new ColorRGBA(0.2f, 0.2f, 0.2f, 0.4f));
dr1.setDirection(new Vector3f(-0.2f, -0.3f, 0.4f).normalizeLocal());
dr1.setShadowCaster(true);
lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
lightState.attach(dr1);
lightState.setEnabled(true);
lightState.setGlobalAmbient(new ColorRGBA(0.6f, 0.6f, 0.6f, 1.0f));
rootNode.setRenderState(lightState);
//****************************
init();
//****************************
timer.reset();
rootNode.updateGeometricState( 0.0f, true );
rootNode.updateRenderState();
fpsNode.updateGeometricState( 0.0f, true );
fpsNode.updateRenderState();
timer.reset();
}
protected void initSystem() throws JmeException
{
logger.info(getVersion());
try
{
setDisplay(DisplaySystem.getDisplaySystem( properties.getRenderer() ));
getDisplay().setMinDepthBits( depthBits );
getDisplay().setMinStencilBits( stencilBits );
getDisplay().setMinAlphaBits( alphaBits );
getDisplay().setMinSamples( samples );
getDisplay().createWindow( properties.getWidth(), properties.getHeight(),
properties.getDepth(), properties.getFreq(), properties
.getFullscreen() );
logger.info("Running on: " + getDisplay().getAdapter()
+ "nDriver version: " + getDisplay().getDriverVersion() + "n"
+ getDisplay().getDisplayVendor() + " - "
+ getDisplay().getDisplayRenderer() + " - "
+ getDisplay().getDisplayAPIVersion());
cam = getDisplay().getRenderer().createCamera( getDisplay().getWidth(),
getDisplay().getHeight() );
}
catch ( JmeException e )
{
logger.log(Level.SEVERE, "Could not create displaySystem", e);
System.exit( 1 );
}
getDisplay().getRenderer().setBackgroundColor( ColorRGBA.black.clone() );
cam.setFrustumPerspective( 45.0f, (float) getDisplay().getWidth()
/ (float) getDisplay().getHeight(), 1, 1000 );
cam.setParallelProjection( false );
cam.update();
cam.setLocation(new Vector3f(0,40,0));
cam.setDirection(new Vector3f(0.0f,-1.0f,0.0f));
cam.setLeft(new Vector3f(0.0f,0.0f,1.0f));
cam.setUp(new Vector3f(1.0f,0.0f,0.0f));
cam.update();
getDisplay().getRenderer().setCamera( cam );
/** Create a basic input controller. */
FirstPersonHandler firstPersonHandler = new FirstPersonHandler( cam, 50,
1 );
input = firstPersonHandler;
timer = Timer.getTimer();
getDisplay().setTitle( "TankSport" );
getDisplay().getRenderer().enableStatistics( true );
}
protected void render( float interpolation )
{
Renderer r = getDisplay().getRenderer();
r.clearStatistics();
r.clearBuffers();
GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).execute();
pManager.renderPasses(getDisplay().getRenderer());
r.draw(rootNode);
r.draw(fpsNode);
render();
doDebug(getDisplay().getRenderer());
}
protected final void update(float interpolation)
{
timer.update();
tpf = timer.getTimePerFrame();
GameTaskQueueManager.getManager().getQueue(GameTaskQueue.UPDATE).execute();
updateBuffer.setLength( 0 );
updateBuffer.append( "FPS: " ).append( (int) timer.getFrameRate() ).append(" - " );
updateBuffer.append( getDisplay().getRenderer().getStatistics( tempBuffer ) );
fps.print( updateBuffer );
if ( !pause )
{
step();
rootNode.updateGeometricState(tpf, true);
fpsNode.updateGeometricState(tpf, true);
pManager.updatePasses(tpf);
}
}
public void reinit()
{
}
protected void cleanup()
{
logger.info( "Cleaning up resources." );
TextureManager.doTextureCleanup();
if (getDisplay() != null && getDisplay().getRenderer() != null) getDisplay().getRenderer().cleanup();
KeyInput.destroyIfInitalized();
MouseInput.destroyIfInitalized();
JoystickInput.destroyIfInitalized();
}
protected void doDebug(Renderer r)
{
if (showDepth) {
r.renderQueue();
Debugger.drawBuffer(Texture.RTT_SOURCE_DEPTH, Debugger.NORTHEAST, r);
}
}
}
A demonstration of this has already been made in jmetest.renderer.TestShadowPass. You should check it out.
Of course I had a look, but no wonder why I can't rely on this:
TestShadowPass extends SimplePassGame
try this in your update method:
// update the firstperson handler
input.update(tpf);
// update renderpasses
pManager.updatePasses(tpf);
// update the scenes geometric state
fpsNode.updateGeometricState(tpf, true);
rootNode.updateGeometricState(tpf, true);
there is still something wrong with the camera setup or the input handler, it seem inverted.
and the shadow is flickering somehow.
Hey big thanks CoreDump.
It's a big help cause by moving around with inputs I found out there is a shadow casted but like you said it's flickering. In fact it's like it's rendered then erased just after.
Ok it works finally !
The only one mistake is a bad ordering in the render method.
Here is the final code, hope that helps some people by the way !
public class Central extends FixedFramerateGame
{
private static final Logger logger = Logger.getLogger(Central.class
.getName());
protected Camera cam;
protected Node rootNode;
protected InputHandler input;
protected Timer timer;
protected Node fpsNode;
protected Text fps;
protected int alphaBits = 0;
protected int depthBits = 8;
protected int stencilBits = 4;
protected int samples = 0;
protected float tpf;
protected boolean showDepth = false;
protected boolean showBounds = false;
protected boolean showNormals = false;
protected WireframeState wireState;
protected LightState lightState;
public static String fontLocation = Text.DEFAULT_FONT;
protected StringBuffer updateBuffer = new StringBuffer( 30 );
protected StringBuffer tempBuffer = new StringBuffer();
protected boolean pause;
protected BasicPassManager pManager;
protected static ShadowedRenderPass shadowPass = new ShadowedRenderPass();
//********************************
public void createScene()
{
Node scene = new Node();
TextureState sandTextureState = getDisplay().getRenderer().createTextureState();
TextureState grassTextureState = getDisplay().getRenderer().createTextureState();
URL sandURL = Central.class.getClassLoader().getResource("resources/sand.png");
sandTextureState.setTexture(TextureManager.loadTexture(sandURL,Texture.MM_LINEAR, Texture.FM_LINEAR));
Node boxes = new Node();
Box b = new Box("box", new Vector3f(), new Vector3f(1,1,1));
b.setRenderState(sandTextureState);
b.setLocalTranslation(4,10,5);
b.setModelBound(new BoundingBox());
b.updateModelBound();
URL grassURL = Central.class.getClassLoader().getResource("resources/grass.png");
grassTextureState.setTexture(TextureManager.loadTexture(grassURL,Texture.MM_LINEAR, Texture.FM_LINEAR));
Quad quad = new Quad("ground",40,40);
quad.setRenderState(grassTextureState);
quad.setLocalTranslation(0,0,0);
Quaternion roll90 = new Quaternion();
roll90.fromAngleAxis( FastMath.PI/2 , new Vector3f(1,0,0) );
quad.setLocalRotation( roll90 );
quad.setModelBound(new BoundingBox());
quad.updateModelBound();
boxes.attachChild(b);
scene.attachChild(quad);
scene.attachChild(boxes);
rootNode.attachChild(scene);
rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
shadowPass.add(rootNode);
shadowPass.addOccluder(boxes);
shadowPass.setLightingMethod(ShadowedRenderPass.MODULATIVE);
shadowPass.setRenderShadows(true);
pManager.add(shadowPass);
RenderPass rPass = new RenderPass();
rPass.add(fpsNode);
}
public void init()
{
new ShadowTweaker(shadowPass).setVisible(true);
pManager = new BasicPassManager();
MouseInput.get().setCursorVisible(true);
createScene();
}
public void step()
{
}
public void render()
{
}
//*******DO NO TOUCH BELOW*********
protected void initGame()
{
pManager = new BasicPassManager();
rootNode = new Node( "rootNode" );
ZBufferState buf = getDisplay().getRenderer().createZBufferState();
buf.setEnabled( true );
buf.setFunction( ZBufferState.CF_LEQUAL );
rootNode.setRenderState( buf );
fps = Text.createDefaultTextLabel( "FPS label" );
fps.setCullMode( SceneElement.CULL_NEVER );
fps.setTextureCombineMode( TextureState.REPLACE );
fpsNode = new Node( "FPS node" );
fpsNode.setRenderState( fps.getRenderState( RenderState.RS_ALPHA ) );
fpsNode.setRenderState( fps.getRenderState( RenderState.RS_TEXTURE ) );
fpsNode.attachChild( fps );
fpsNode.setCullMode( SceneElement.CULL_NEVER );
DirectionalLight dr1 = new DirectionalLight();
dr1.setEnabled(true);
dr1.setDiffuse(ColorRGBA.white);
dr1.setAmbient(new ColorRGBA(0.2f, 0.2f, 0.2f, 0.4f));
dr1.setDirection(new Vector3f(-1f, -1f, 1f).normalizeLocal());
dr1.setShadowCaster(true);
lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
lightState.attach(dr1);
lightState.setEnabled(true);
lightState.setGlobalAmbient(new ColorRGBA(0.6f, 0.6f, 0.6f, 1.0f));
rootNode.setRenderState(lightState);
//****************************
init();
//****************************
timer.reset();
rootNode.updateGeometricState( 0.0f, true );
rootNode.updateRenderState();
fpsNode.updateGeometricState( 0.0f, true );
fpsNode.updateRenderState();
timer.reset();
}
protected void initSystem() throws JmeException
{
logger.info(getVersion());
try
{
setDisplay(DisplaySystem.getDisplaySystem( properties.getRenderer() ));
getDisplay().setMinDepthBits( depthBits );
getDisplay().setMinStencilBits( stencilBits );
getDisplay().setMinAlphaBits( alphaBits );
getDisplay().setMinSamples( samples );
getDisplay().createWindow( properties.getWidth(), properties.getHeight(),
properties.getDepth(), properties.getFreq(), properties
.getFullscreen() );
logger.info("Running on: " + getDisplay().getAdapter()
+ "nDriver version: " + getDisplay().getDriverVersion() + "n"
+ getDisplay().getDisplayVendor() + " - "
+ getDisplay().getDisplayRenderer() + " - "
+ getDisplay().getDisplayAPIVersion());
cam = getDisplay().getRenderer().createCamera( getDisplay().getWidth(),
getDisplay().getHeight() );
}
catch ( JmeException e )
{
logger.log(Level.SEVERE, "Could not create displaySystem", e);
System.exit( 1 );
}
getDisplay().getRenderer().setBackgroundColor( ColorRGBA.black.clone() );
cam.setFrustumPerspective( 45.0f, (float) getDisplay().getWidth()
/ (float) getDisplay().getHeight(), 1, 1000 );
cam.setParallelProjection( false );
cam.update();
cam.setLocation(new Vector3f(0,40,0));
cam.setDirection(new Vector3f(0.0f,-1.0f,0.0f));
cam.setLeft(new Vector3f(0.0f,0.0f,1.0f));
cam.setUp(new Vector3f(1.0f,0.0f,0.0f));
cam.update();
getDisplay().getRenderer().setCamera( cam );
/** Create a basic input controller. */
FirstPersonHandler firstPersonHandler = new FirstPersonHandler( cam, 50,
1 );
input = firstPersonHandler;
timer = Timer.getTimer();
getDisplay().setTitle( "TankSport" );
getDisplay().getRenderer().enableStatistics( true );
}
protected void render( float interpolation )
{
Renderer r = getDisplay().getRenderer();
r.clearStatistics();
r.clearBuffers();
GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).execute();
r.draw(rootNode);
r.draw(fpsNode);
pManager.renderPasses(getDisplay().getRenderer());
render();
doDebug(getDisplay().getRenderer());
}
protected final void update(float interpolation)
{
timer.update();
tpf = timer.getTimePerFrame();
GameTaskQueueManager.getManager().getQueue(GameTaskQueue.UPDATE).execute();
updateBuffer.setLength( 0 );
updateBuffer.append( "FPS: " ).append( (int) timer.getFrameRate() ).append(" - " );
updateBuffer.append( getDisplay().getRenderer().getStatistics( tempBuffer ) );
fps.print( updateBuffer );
if ( !pause )
{
step();
pManager.updatePasses(tpf);
fpsNode.updateGeometricState(tpf, true);
rootNode.updateGeometricState(tpf, true);
input.update(tpf);
}
}
public void reinit()
{
}
protected void cleanup()
{
logger.info( "Cleaning up resources." );
TextureManager.doTextureCleanup();
if (getDisplay() != null && getDisplay().getRenderer() != null) getDisplay().getRenderer().cleanup();
KeyInput.destroyIfInitalized();
MouseInput.destroyIfInitalized();
JoystickInput.destroyIfInitalized();
}
protected void doDebug(Renderer r)
{
if (showDepth) {
r.renderQueue();
Debugger.drawBuffer(Texture.RTT_SOURCE_DEPTH, Debugger.NORTHEAST, r);
}
}
}
good to hear
I've been rushing so fast at using Jme that I missed basics. In my previous code, it has nothing to do with StandardGame in fact but that still might help.
So I'm currently porting the same code into StandardGame+Gamestates. I'll post it here ( if I succeed XD !)
Arrhh Struggling again to get shadows working.
The only one effect I get is having a darker scene ://.
Maybe I just don't use GameState as it's supposed to be ?
Here is the code:
StandardGame:
public class TsStandardGame
{
public TsStandardGame()
{
StandardGame game = new StandardGame("TankSport");
try
{
GameSettingsPanel.prompt(game.getSettings());
}
catch (InterruptedException e)
{
e.printStackTrace();
}
game.start();
init();
TsGameState tsGameState = new TsGameState("tsGameState");
GameStateManager.getInstance().attachChild(tsGameState);
tsGameState.setActive(true);
TsRenderPassState tsRenderPassState = new TsRenderPassState("tsRenderPassState");
GameStateManager.getInstance().attachChild(tsRenderPassState);
tsRenderPassState.setActive(true);
}
public void init()
{
MouseInput.get().setCursorVisible(true);
DisplaySystem.getDisplaySystem().setMinDepthBits( 8 );
DisplaySystem.getDisplaySystem().setMinStencilBits(4);
DisplaySystem.getDisplaySystem().setMinAlphaBits( 0 );
DisplaySystem.getDisplaySystem().setMinSamples( 0 );
}
}
main GameState:
public class TsGameState extends GameState
{
private Renderer renderer = DisplaySystem.getDisplaySystem().getRenderer();
protected StringBuffer updateBuffer = new StringBuffer( 30 );
protected StringBuffer tempBuffer = new StringBuffer();
protected Timer timer;
protected Camera cam;
protected Node fpsNode;
protected Text fps;
protected InputHandler input;
public static String fontLocation = Text.DEFAULT_FONT;
private Node rootNode = null;
private Node occluders = null;
private Node scene = null;
public TsGameState(String name)
{
setName(name);
cam = renderer.getCamera();
cam.setFrustumPerspective( 45.0f, (float) DisplaySystem.getDisplaySystem().getWidth() / (float) DisplaySystem.getDisplaySystem().getHeight(), 1, 1000 );
cam.setParallelProjection( false );
cam.update();
cam.setLocation(new Vector3f(0,40,0));
cam.setDirection(new Vector3f(0.0f,-1.0f,0.0f));
cam.setLeft(new Vector3f(0.0f,0.0f,1.0f));
cam.setUp(new Vector3f(1.0f,0.0f,0.0f));
cam.update();
timer = Timer.getTimer();
/** Create a basic input controller. */
FirstPersonHandler firstPersonHandler = new FirstPersonHandler( cam, 50,1 );
input = firstPersonHandler;
fps = Text.createDefaultTextLabel( "FPS label" );
fps.setCullMode( SceneElement.CULL_NEVER );
fps.setTextureCombineMode( TextureState.REPLACE );
fpsNode = new Node( "FPS node" );
fpsNode.setRenderState( fps.getRenderState( RenderState.RS_ALPHA ) );
fpsNode.setRenderState( fps.getRenderState( RenderState.RS_TEXTURE ) );
fpsNode.attachChild( fps );
fpsNode.setCullMode( SceneElement.CULL_NEVER );
//creating the scene
rootNode = new Node("rootNode");
ZBufferState buf = renderer.createZBufferState();
buf.setEnabled( true );
buf.setFunction( ZBufferState.CF_LEQUAL );
rootNode.setRenderState( buf );
scene = new Node();
TextureState sandTextureState = renderer.createTextureState();
TextureState grassTextureState = renderer.createTextureState();
URL sandURL = TsGameState.class.getClassLoader().getResource("resources/sand.png");
sandTextureState.setTexture(TextureManager.loadTexture(sandURL,Texture.MM_LINEAR, Texture.FM_LINEAR));
occluders = new Node();
Box b = new Box("box", new Vector3f(), new Vector3f(1,1,1));
b.setRenderState(sandTextureState);
b.setLocalTranslation(4,10,5);
b.setModelBound(new BoundingBox());
b.updateModelBound();
URL grassURL = TsGameState.class.getClassLoader().getResource("resources/grass.png");
grassTextureState.setTexture(TextureManager.loadTexture(grassURL,Texture.MM_LINEAR, Texture.FM_LINEAR));
Quad quad = new Quad("ground",40,40);
quad.setRenderState(grassTextureState);
quad.setLocalTranslation(0,0,0);
Quaternion roll90 = new Quaternion();
roll90.fromAngleAxis( FastMath.PI/2 , new Vector3f(1,0,0) );
quad.setLocalRotation( roll90 );
quad.setModelBound(new BoundingBox());
quad.updateModelBound();
occluders.attachChild(b);
scene.attachChild(quad);
scene.attachChild(occluders);
rootNode.attachChild(scene);
rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
DirectionalLight dr1 = new DirectionalLight();
dr1.setEnabled(true);
dr1.setDiffuse(ColorRGBA.white);
dr1.setAmbient(new ColorRGBA(0.2f, 0.2f, 0.2f, 0.4f));
dr1.setDirection(new Vector3f(-1f, -1f, 1f).normalizeLocal());
dr1.setShadowCaster(true);
LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
lightState = renderer.createLightState();
lightState.attach(dr1);
lightState.setEnabled(true);
lightState.setGlobalAmbient(new ColorRGBA(0.6f, 0.6f, 0.6f, 1.0f));
rootNode.setRenderState(lightState);
timer.reset();
rootNode.updateGeometricState( 0.0f, true );
rootNode.updateRenderState();
fpsNode.updateGeometricState( 0.0f, true );
fpsNode.updateRenderState();
timer.reset();
renderer.enableStatistics( true );
}
public Node getOccludersNode()
{
return occluders;
}
public Node getRootNode()
{
return rootNode;
}
public Node getFpsNode()
{
return fpsNode;
}
public Node getSceneNode()
{
return scene;
}
@Override
public void render(float tpf)
{
renderer.draw(rootNode);
renderer.draw(fpsNode);
}
@Override
public void update(float tpf)
{
timer.update();
tpf = timer.getTimePerFrame();
updateBuffer.setLength( 0 );
updateBuffer.append( "FPS: " ).append( (int) timer.getFrameRate() ).append(" - " );
updateBuffer.append( renderer.getStatistics( tempBuffer ) );
fps.print( updateBuffer );
//if ( !pause )
//{
fpsNode.updateGeometricState(tpf, true);
rootNode.updateGeometricState(tpf, true);
input.update(tpf);
//}
}
@Override
public void cleanup()
{
TextureManager.doTextureCleanup();
if (DisplaySystem.getDisplaySystem() != null && renderer != null) renderer.cleanup();
KeyInput.destroyIfInitalized();
MouseInput.destroyIfInitalized();
JoystickInput.destroyIfInitalized();
}
}
RenderPassState:
public class TsRenderPassState extends GameState
{
private Renderer renderer = DisplaySystem.getDisplaySystem().getRenderer();
private ShadowedRenderPass shadowPass = null;
private BasicPassManager pManager = null;
public TsRenderPassState(String name)
{
setName(name);
//new ShadowTweaker(shadowPass).setVisible(true);
shadowPass = new ShadowedRenderPass();
pManager = new BasicPassManager();
TsGameState tsGameState = ((TsGameState)GameStateManager.getInstance().getChild("tsGameState"));
Node rootNode = tsGameState.getRootNode();
Node occluders = tsGameState.getOccludersNode();
shadowPass.add(rootNode);
shadowPass.addOccluder(occluders);
//shadowPass.setRenderVolume(true);
shadowPass.setLightingMethod(ShadowedRenderPass.MODULATIVE);
shadowPass.setRenderShadows(true);
RenderPass rPass = new RenderPass();
rPass.add(tsGameState.fpsNode);
pManager.add(shadowPass);
pManager.add(rPass);
}
@Override
public void render(float tpf)
{
pManager.renderPasses(renderer);
}
@Override
public void update(float tpf)
{
pManager.updatePasses(tpf);
}
@Override
public void cleanup()
{
}
}
It's supposed to be a very light example lol.
hmm ok there are a few things:
- and most important settings need to be set before StandardGame is started:
game.getSettings().setStencilBits(4);
game.getSettings().setDepth( 16 );
game.getSettings().setAlphaBits( 0 );
game.getSettings().setSamples( 0 );
game.start();
MouseInput.get().setCursorVisible(true);
2. i think your cam is set up strange, but maybe you want it this way :)
i would set it up this way:
cam.setLocation(new Vector3f(0, 0, 4));
cam.setDirection(new Vector3f(0.0f, 0.0f, -1.0f));
cam.setLeft(new Vector3f(-1.0f, 0.0f, 0.0f));
cam.setUp(new Vector3f(0.0f, 1.0f, 0.0f));
then i moved the box in front of the quad and there shall be shadows :)
Core-Dump you rock.
I bet it took you 2 minutes to find out the wrong thing and me 2 hours and didn't find it XD.
For the camera, how did you see the shadow when the cam's height is 0 ? But I definitely had to change the other settings so the "mouse-looking" doesn't look weird.
THanks !