Lens Flare Texture Problem

Hi,

again as before:



same code same game same texture files on two computers



computer 1: VGA is Nvidia 6600 NX

computer 2: ATI Radeon 1400x



on computer1 the lens flare is rendered correctly (pic1.jpg)

on computer2 lens flare is looking very ugly          (pic2.jpg)



here is the code



    void initSun(String flare1_filename, String flare2_filename,
            String flare3_filename, String flare4_filename){

        TextureState[] tex = new TextureState[4];
        tex[0] = display.getRenderer().createTextureState();
        tex[0].setTexture(TextureManager.loadTexture(
                ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, flare1_filename),
                Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
        tex[0].setEnabled(true);

        tex[1] = display.getRenderer().createTextureState();
        tex[1].setTexture(TextureManager.loadTexture(
                ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, flare2_filename),
                Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
        tex[1].setEnabled(true);

        tex[2] = display.getRenderer().createTextureState();
        tex[2].setTexture(TextureManager.loadTexture(
                ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, flare3_filename),
                Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
        tex[2].setEnabled(true);

        tex[3] = display.getRenderer().createTextureState();
        tex[3].setTexture(TextureManager.loadTexture(
                ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_TEXTURE, flare4_filename),
                Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
        tex[3].setEnabled(true);

        sun = LensFlareFactory.createBasicLensFlare("Sun", tex);
        sun.setRootNode(rootNode);

        sun.updateGeometricState(0, false);
        sun.updateRenderState();
        
        rootNode.attachChild(sun);
    }




any help please?

you need to call updateRenderState() after the lensflare has been attached.

well that didnt work either



I spent the whole day going though my code to find the problem and I gave up :S

I wrote a little test class to test the LensFlare and it did the same render fault too: please take alook at the code and the attached pic … and btw, I ran this class on "computer 1" and it worked really fine :S!!!



if you take a look at the pic, you'll see w white rectangle … I think its something related to a faulty BlendState because if you open jmetest/data/texture/flare1.png in MsPaint, you will see the same white rectangle visible…



any help please?! I'm pulling my hair off, please save the hair left on my head hehe



package test;

import com.jme.image.Image;
import com.jme.image.Texture;
import com.jme.input.FirstPersonHandler;
import com.jme.input.InputHandler;
import com.jme.light.LightNode;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.renderer.pass.BasicPassManager;
import com.jme.renderer.pass.RenderPass;
import com.jme.scene.Node;
import com.jme.scene.Skybox;
import com.jme.scene.state.CullState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueueManager;
import com.jme.util.TextureManager;
import com.jmex.effects.LensFlare;
import com.jmex.effects.LensFlareFactory;
import com.jmex.game.StandardGame;
import com.jmex.game.state.GameState;
import com.jmex.game.state.GameStateManager;
import java.util.concurrent.Callable;
import jmetest.renderer.TestSkybox;

/**
 * @author Ahmad Shami <Shatazone@hotmail.com>
 * Created: Jan 31, 2010
 */
public class InGameState extends GameState{
    public static String NAME = "InGameState";

    protected Node rootNode;
    protected BasicPassManager pManager;
    protected InputHandler input;
    protected LightState lightState;
    protected Skybox skybox;
    protected Camera camera;
    protected DisplaySystem display;
    protected Renderer renderer;
    protected LightNode lightNode;

    public InGameState(){
        super.name = NAME;
        initSystem();
        initGame();
    }

    private void initSystem(){
        display = DisplaySystem.getDisplaySystem();
        renderer = display.getRenderer();
        camera = renderer.getCamera();

        camera.setFrustumPerspective(45.0f, (float)display.getWidth()/(float)display.getHeight(), 0.1f, 200);
        Vector3f loc = new Vector3f(1.0f, 1f, 1.0f);
        Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
        Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
        Vector3f dir = new Vector3f(0.0f, 0.0f, -1.0f);
        camera.setFrame(loc, left, up, dir);
        camera.update();
    }

    private void initGame(){
        rootNode = new Node("root");
        CullState cs = display.getRenderer().createCullState();
        cs.setCullFace(CullState.Face.Back);
        rootNode.setRenderState(cs);

      ZBufferState buf = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
        buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
        rootNode.setRenderState(buf);

        input = new FirstPersonHandler(camera, 50, 1);
        initLights();
        initLensFlare();
        initSkyBox();
        initPasses();

        rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
        rootNode.updateGeometricState( 0.0f, false );
        rootNode.updateRenderState();
    }

    private void initPasses(){
        pManager = new BasicPassManager();
        RenderPass renderPass = new RenderPass();
        renderPass.add(skybox);
        renderPass.add(rootNode);
        pManager.add(renderPass);
    }

    private void initLights(){
        // ---- LIGHTS
        /** Set up a basic, default light. */
        PointLight light = new PointLight();
        light.setDiffuse( new ColorRGBA( 0.75f, 0.75f, 0.75f, 0.75f ) );
        light.setAmbient( new ColorRGBA( 0.5f, 0.5f, 0.5f, 1.0f ) );
        light.setLocation( new Vector3f( 100, 100, 100 ) );
        light.setEnabled( true );

        /** Attach the light to a lightState and the lightState to rootNode. */
        lightState = display.getRenderer().createLightState();
        lightState.setEnabled( true );
        lightState.attach( light );
        rootNode.setRenderState( lightState );
    }

    private void initLensFlare(){
        PointLight dr = new PointLight();
        dr.setEnabled(true);
        dr.setDiffuse(ColorRGBA.white.clone());
        dr.setAmbient(ColorRGBA.gray.clone());
        dr.setLocation(new Vector3f(0f, 0f, 0f));

        lightState.attach(dr);
        lightState.setTwoSidedLighting(true);

        lightNode = new LightNode("light");
        lightNode.setLight(dr);

        // Setup the lensflare textures.
        TextureState[] tex = new TextureState[4];
        tex[0] = display.getRenderer().createTextureState();
        tex[0].setTexture(TextureManager.loadTexture(LensFlare.class
                .getClassLoader()
                .getResource("jmetest/data/texture/flare1.png"),
                Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear, Image.Format.RGBA8,
                0.0f, true));
        tex[0].setEnabled(true);

        tex[1] = display.getRenderer().createTextureState();
        tex[1].setTexture(TextureManager.loadTexture(LensFlare.class
                .getClassLoader()
                .getResource("jmetest/data/texture/flare2.png"),
                Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
        tex[1].setEnabled(true);

        tex[2] = display.getRenderer().createTextureState();
        tex[2].setTexture(TextureManager.loadTexture(LensFlare.class
                .getClassLoader()
                .getResource("jmetest/data/texture/flare3.png"),
                Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
        tex[2].setEnabled(true);

        tex[3] = display.getRenderer().createTextureState();
        tex[3].setTexture(TextureManager.loadTexture(LensFlare.class
                .getClassLoader()
                .getResource("jmetest/data/texture/flare4.png"),
                Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear));
        tex[3].setEnabled(true);

        LensFlare flare = LensFlareFactory.createBasicLensFlare("flare", tex);
        flare.setRootNode(rootNode);

        rootNode.attachChild(lightNode);

        // notice that it comes at the end
        lightNode.attachChild(flare);
    }

    @Override
    public void update(float tpf) {
        input.update(tpf);
        skybox.setLocalTranslation(camera.getLocation());
        pManager.updatePasses(tpf);
        skybox.updateGeometricState(0, true);
        rootNode.updateGeometricState(tpf, true);
    }

    @Override
    public void render(float tpf) {
        renderer.clearBuffers();
        pManager.renderPasses(renderer);
    }

    @Override
    public void cleanup() {
        pManager.cleanUp();
    }

    private void initSkyBox() {
        skybox = new Skybox("skybox", 10, 10, 10);

        Texture north = TextureManager.loadTexture(
            TestSkybox.class.getClassLoader().getResource(
            "jmetest/data/texture/north.jpg"),
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear);
        Texture south = TextureManager.loadTexture(
            TestSkybox.class.getClassLoader().getResource(
            "jmetest/data/texture/south.jpg"),
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear);
        Texture east = TextureManager.loadTexture(
            TestSkybox.class.getClassLoader().getResource(
            "jmetest/data/texture/east.jpg"),
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear);
        Texture west = TextureManager.loadTexture(
            TestSkybox.class.getClassLoader().getResource(
            "jmetest/data/texture/west.jpg"),
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear);
        Texture up = TextureManager.loadTexture(
            TestSkybox.class.getClassLoader().getResource(
            "jmetest/data/texture/top.jpg"),
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear);
        Texture down = TextureManager.loadTexture(
            TestSkybox.class.getClassLoader().getResource(
            "jmetest/data/texture/bottom.jpg"),
            Texture.MinificationFilter.BilinearNearestMipMap,
            Texture.MagnificationFilter.Bilinear);

        skybox.setTexture(Skybox.Face.North, north);
        skybox.setTexture(Skybox.Face.West, west);
        skybox.setTexture(Skybox.Face.South, south);
        skybox.setTexture(Skybox.Face.East, east);
        skybox.setTexture(Skybox.Face.Up, up);
        skybox.setTexture(Skybox.Face.Down, down);

        Callable preload = new Callable(){

            public Object call() throws Exception {
                skybox.preloadTextures();
                skybox.lockBounds();
                skybox.lockMeshes(); //it also calls updateRenderState()
                return null;
            }
        };

        GameTaskQueueManager.getManager().render(preload);
    }

    public static void main(String args[]){
        StandardGame game = new StandardGame("LensTest");
        game.start();

        GameStateManager.getInstance().attachChild(new InGameState());
        GameStateManager.getInstance().activateAllChildren();
    }
}

well i found out that the skybox textures are effecting/mixing up with the lensflare textures:


  1. if I build the skybox and call preloadTextures() + skybox.updateRenderState(), I get the weird white square on the lens flare
  2. if i dont build the skybox at all, the lens flare looks fine
  3. if I build the skybox and dont call preloadTextures() + skybox.updateRenderState(), the lens flare looks fine but the skybox faces are all textured with the lens flare textures!!! (look at the attached pic :cry: )


i ran your testcase and cant see the white rectangle.



Pretty sure it still a updateRenderstate() problem.

The Callable where you preloadTextures() is executed sometime after you started StandardGame, try to add a rootNode.updateRenderState(); at the end, but inside the callable. To make sure, the renderstated are correctly updated when its executed.

well I tried it and it didnt work :S :S … I have been using jme for a total of 6-7 months and i have never been faced with such a stupid meaningless problem like this one



and I noticed one more thing, if i run:


        Text text = Text.createDefaultTextLabel(name + ":Text", "testing");
        text.setLightCombineMode(Spatial.LightCombineMode.Off);
        text.updateRenderState();
        rootNode.attachChild(text);

        text.updateGeometricState(0, false);
        text.updateRenderState();


the text will be rendered as a white-filled rectangle
why is it working on computer1 and not computer2? is it driver/hardware issue??