Hi, I’m having a problem with the Z-ordering of my lens flare effect. I’ve pretty much copy-pasted the lens flare code from the TestLensFlare-application, but unlike that application, my lens flare seem to appear on top of everything else, with the exception of the terrain.
Here’s a screenshot where the lens flare shouldn’t be visible because the origin of the lens flare is directly behind the tree.
Here’s the code for the effect.
private void createLensFlare()
{
LightNode lightNode;
lightState.detachAll();
PointLight dr = new PointLight();
dr.setEnabled(true);
dr.setDiffuse(ColorRGBA.white);
dr.setAmbient(ColorRGBA.gray);
dr.setLocation(new Vector3f( 0.0f, 0.0f, 0.0f));
lightState.setTwoSidedLighting(true);
lightNode = new LightNode("light", lightState);
lightNode.setLocalTranslation( new Vector3f( -100f, 150f, -100f) );
lightNode.setLight(dr);
// Setup the lensflare textures.
TextureState[] tex = new TextureState[4];
tex[0] = getFlareTextureState( "flare1.png" );
tex[1] = getFlareTextureState( "flare2.png" );
tex[2] = getFlareTextureState( "flare3.png" );
tex[3] = getFlareTextureState( "flare4.png" );
LensFlare flare = LensFlareFactory.createBasicLensFlare("flare", tex);
flare.setLocalTranslation(lightNode.getLocalTranslation());
flare.setRootNode(rootNode);
lightNode.attachChild(flare);
rootNode.attachChild(lightNode);
// notice that it comes at the end
rootNode.attachChild(flare);
}
private TextureState getFlareTextureState( String textureFilename )
{
TextureState tex = display.getRenderer().createTextureState();
tex.setTexture( getTexture( textureFilename ) );
tex.setEnabled(true);
tex.apply();
return tex;
}
private Texture getTexture( String filename )
{
return TextureManager.loadTexture(
LensFlare.class.getClassLoader().getResource("jmetest/data/texture/" + filename),
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR);
}
Can you spot what I'm doing wrong?