I’ve been playing around with texturing and shadow and I am now wondering what would be the (best) way to create a transparent shadow plane. Given the screenshot of my test game (below), how would I render the shadows of the model over the background, but not the plane itself?
I’m extending StandardGame and have a PassManager for the Background, Shadow and Main pass. Any sample code with a transparent floor plane would help?
Here’s my part of my code if it helps.
Code that creates the floor plane for now:
public static void initGround() {
groundNode = new Node("Ground Node");
Box b = new Box("Ground", new Vector3f(0, 0, 0), 300, 200, 0.1f);
//Quad b = new Quad("Ground", 300, 200);
float[] xRotation = {(float)(Math.PI/2.0), 0.0f, 0.0f};
b.setLocalRotation(new Quaternion(xRotation));
groundNode.attachChild(b);
MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
ms.setAmbient(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f));
ms.setDiffuse(new ColorRGBA(0.0f, 0.0f, 1.0f, 0.5f));
groundNode.setRenderState(ms);
AlphaState as = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
as.setBlendEnabled(true);
as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
as.setTestEnabled(true);
as.setTestFunction(AlphaState.TF_GREATER);
as.setEnabled(true);
groundNode.setRenderState(as);
groundNode.updateRenderState();
gameState.getRootNode().attachChild(groundNode);
}
And from the extended GameState:
backNode = new Node("Background Node");
//XXX START OF STAGE (to replace)
Quad back = new Quad("Background Quad", this.width, this.height);
back.setRenderQueueMode(Renderer.QUEUE_ORTHO);
back.setLocalTranslation(this.width / 2, this.height / 2, 0);
back.setLightCombineMode(LightState.OFF);
//XXX should pass background texture folder and load them all
TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
ts.setTexture(TextureManager.loadTexture(
this.getClass().getClassLoader().getResource("data/habitats/hbhabitat/default.jpg"),
Texture.MM_LINEAR, Texture.FM_LINEAR, 1.0f, true));
ts.setEnabled(true);
back.setRenderState(ts);
back.updateRenderState();
//END OF STAGE
backNode.attachChild(back);
//create the pass manager
pManager = new BasicPassManager();
//add the background pass
backgroundPass = new RenderPass();
backgroundPass.add(backNode);
pManager.add(backgroundPass);
//add the shadow pass
shadowPass = new ShadowedRenderPass();
shadowPass.add(rootNode);
shadowPass.setShadowColor(ColorRGBA.black);
shadowPass.setLightingMethod(ShadowedRenderPass.ADDITIVE);
//shadowPass.setLightingMethod(ShadowedRenderPass.MODULATIVE);
shadowPass.setRenderShadows(true);
shadowPass.setEnabled(true);
shadowPass.addOccluder(rootNode);
pManager.add(shadowPass);
//add the main pass
rootPass = new RenderPass();
rootPass.add(rootNode);
pManager.add(rootPass);
Thanks