TestMotionBlur

I found out that TestMotionBlur was not working so I fixed it. Hear is the code. I can not get rid of the white tint.



package jmetest.effects;

import com.jme.app.VariableTimestepGame;
import com.jme.image.Texture;
import com.jme.input.FirstPersonHandler;
import com.jme.input.InputHandler;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.TextureRenderer;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.AlphaState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;

/**
 * @author Ahmed
 * @version $Id: TestMotionBlur.java, Jul 1, 2004 11:56:16 AM
 */
public class TestMotionBlur extends VariableTimestepGame {
   
    private Camera cam;
    private InputHandler input;
   
    private Node rootNode, sceneNode, blurNode;
   
    private TextureRenderer tRenderer;
    private Texture fakeTex;
   
    private boolean firstFrame = true;
    Box box;
    float ratation;
    float posittion;
    protected void update(float timeD) {
        float time = timeD * 10;
        input.update(time);
       
        //The flowing code is used to make the box move
        //If you do not need it remove it
        //box.setLocalTranslation(new Vector3f(posittion,0,0));
        box.getLocalRotation().fromAngleAxis(ratation,new com.jme.math.Vector3f(1,1,0).normalize());
        ratation+=time;
        if(ratation>360)
            ratation=0;
        posittion+=timeD*4;
        if(posittion>20)
            posittion=-20;
        //End box move code.
       
        if (firstFrame == false) {
            tRenderer.updateCamera();
            tRenderer.render(rootNode, fakeTex);
        } else {
            firstFrame = false;
        }
       
       
        rootNode.updateGeometricState(time, false);
    }
   
    protected void render(float timeD) {
        display.getRenderer().clearBuffers();
        display.getRenderer().draw(rootNode);
    }
   
    protected void initSystem() {
        try {
            display = DisplaySystem.getDisplaySystem(properties.getRenderer());
            display.createWindow(properties.getWidth(),
            properties.getHeight(),
            properties.getDepth(),
            properties.getFreq(),
            properties.getFullscreen());
            cam = display.getRenderer().createCamera(properties.getWidth(),
            properties.getHeight());
        } catch (JmeException je) {
            je.printStackTrace();
            System.exit(1);
        }
       
        display.getRenderer().setBackgroundColor(ColorRGBA.black);
       
        cam.setFrustum(1f, 1000f, -0.55f, 0.55f, 0.4125f, -0.4125f);
        Vector3f loc = new Vector3f(0, 0, 25);
        Vector3f left = new Vector3f(-1, 0, 0);
        Vector3f up = new Vector3f(0, 1, 0);
        Vector3f dir = new Vector3f(0, 0, -1);
        cam.setFrame(loc, left, up, dir);
        cam.update();
        display.getRenderer().setCamera(cam);
       
        input = new FirstPersonHandler(this, cam, properties.getRenderer());
        input.setMouseSpeed(0.5f);
        input.setKeySpeed(2f);
    }
    protected void initGame() {
        // init nodes
        rootNode = new Node("Root Node");
        sceneNode = new Node("SceneNode");
        blurNode = new Node("Blur Node");
       
        // set render queues
        blurNode.setRenderQueueMode(com.jme.renderer.Renderer.QUEUE_ORTHO);
        sceneNode.setRenderQueueMode(com.jme.renderer.Renderer.QUEUE_OPAQUE);
        // alpha state for the quadratic
        AlphaState as = display.getRenderer().createAlphaState();
        as.setBlendEnabled(true);
        as.setEnabled(true);
        as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
        as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
       
        ZBufferState zstate = display.getRenderer().createZBufferState();
        zstate.setWritable(false);
        zstate.setEnabled(false);
        blurNode.setRenderState(zstate);
       
       
        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(TextureManager
        .loadTexture(TestMotionBlur.class.getClassLoader()
        .getResource("jmetest/data/images/Monkey.jpg"),
        Texture.MM_LINEAR,
        Texture.FM_LINEAR,
        true));
       
        tRenderer = display.createTextureRenderer(512,
        512,
        false,
        true,
        false,
        false,
        TextureRenderer.RENDER_TEXTURE_2D,
        0);
        tRenderer.setBackgroundColor(ColorRGBA.white);
        tRenderer.setCamera(cam);
        tRenderer.updateCamera();
        fakeTex = tRenderer.setupTexture();
       
        TextureState blurTS = display.getRenderer().createTextureState();
        blurTS.setTexture(fakeTex);
        blurTS.setEnabled(true);
       
        Quad quad = new Quad("Blur Quad", display.getWidth(),display.getHeight());
        quad.setSolidColor(new ColorRGBA(1, 1, 1, 0.5f));
        quad.setRenderState(blurTS);
        quad.setRenderState(as);
        quad.setLocalTranslation(new com.jme.math.Vector3f(display.getWidth()/2,display.getHeight()/2,0));
       
        Vector3f min = new Vector3f(-0.1f, -0.1f, -0.1f);
        Vector3f max = new Vector3f(0.1f, 0.1f, 0.1f);
        box = new Box("Scene", min.mult(5), max.mult(5));
        box.setRenderState(ts);
       
        blurNode.attachChild(quad);
        sceneNode.attachChild(box);
       
        ZBufferState zEnabled = display.getRenderer().createZBufferState();
        zEnabled.setEnabled(true);
       
        rootNode.setRenderState(zEnabled);
        rootNode.attachChild(sceneNode);
        rootNode.attachChild(blurNode);
        rootNode.updateGeometricState(0.0f, true);
        rootNode.updateRenderState();
       
    }
   
    protected void cleanup() {
       
    }
   
    protected void reinit() {
       
    }
   
    public static void main(String[] args) {
        TestMotionBlur app = new TestMotionBlur();
        app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
    }
}



If we have demos I think that they should work.

There’s a motion blur? ok…

DP made it. I think that it is a good way of showing that you can do complex effects with jme with relative ease. If you do not commit my changes I would recommend removing it, It dose not look good having a broken test in the test directory. Are you going to use my code?

Ran the test, I don’t really know how that shows off motion blurring very well. It’s hard to see, if you can see it at all through the white tint.



I’m going to go ahead and remove the test altogether.

"mojomonk" wrote:
I'm going to go ahead and remove the test altogether.

Fine with me.