Lensflare Z-order problem

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?

It's a guess, but maybe your palm tree doesn't have boundings? (lensflare casts a ray to see if there is anything inbetween it and the camera, and that needs boundings)

llama said:

It's a guess, but maybe your palm tree doesn't have boundings? (lensflare casts a ray to see if there is anything inbetween it and the camera, and that needs boundings)

Appearently the tree has a *huge* bounding sphere:


But it doesn't block the lensflare effect. I've tried applying other types of bounds using .setWorldBound( new BoundingBox() ) and .updateWorldBound(), but without any effect, the bounding sphere is still used.  :(

.setModelBound() and .updateModelBound()



another reason we need to change the name of setWorldBound()



anyways…



flare.setRootNode(someSpatial) defines what can block the lens flare. Are you sure your tree is being passed in here?

mojomonk said:

.setModelBound() and .updateModelBound()

But the palm tree is in a Node object, so it doesn't have the ModelBound methods but the only the WorldBound methods.  :?

mojomonk said:

flare.setRootNode(someSpatial) defines what can block the lens flare. Are you sure your tree is being passed in here?

The palm tree node is inserted into the rootNode object, so it ought to block the flare as well...
rootNode.attachChild( palm );
(...)
flare.setRootNode(rootNode);

if the tree is a Node your loading it as a model I'm assuming… use the loader properties to set the boundings.



JmeBinaryReader.setProperty("bound", "box");



As far as the occlusion, I'm not sure off the top of my head. It's either failing at the initial pick or the checkRealOcclusion check in LensFlare. If you are working with jME source, you can put some checks in the draw and checkRealOcclusion methods to determine where it's failing to find the tree.

mojomonk said:

if the tree is a Node your loading it as a model I'm assuming... use the loader properties to set the boundings.

JmeBinaryReader.setProperty("bound", "box");

That worked, now it's using a bounding box instead of a bounding sphere. But the lens flare effect still goes right through the tree...  :(

As mojo said, it'd help a lot if you can tell us wether the method checkRealOcclusion() in LensFlare.java is ever called (put a breakpoint there or something). If it does get called, we can be pretty sure the problem isn't with the boundings, and focus on other things.