Simple Question for Bloom Pass (On/Off)

Hello,



I have a basic question: how to apply a [glow=red,2,300]BloomRenderPass[/glow] only to specific nodes in a scene? Whatever I do, see the code below, it always apply to all the nodes… A second related question would be how to add/remove a pass dynamically.



Thx v much - and jME rocks BTW.



import org.apache.log4j.Logger;



import com.jme.app.BaseSimpleGame;

import com.jme.app.SimpleGame;

import com.jme.bounding.BoundingBox;

import com.jme.math.Vector3f;

import com.jme.renderer.Camera;

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.Spatial;

import com.jme.scene.shape.Box;

import com.jme.util.Timer;

import com.jmex.effects.glsl.BloomRenderPass;



public final class RBPassTest extends SimpleGame {

/**

  • {@link Logger}

    */

    private static final Logger logger = Logger.getLogger(RBPassTest.class);



    /**
  • {@link Spatial}

    */

    private Spatial spatial1 = null, spatial2 = null;



    /**
  • {@link BasicPassManager}

    */

    private BasicPassManager basicPassManager = null;



    /**
  • {@link Timer}

    */

    private Timer timer = null;



    /**
  • {@link BloomRenderPass}

    */

    private BloomRenderPass bloomRenderPass = null;



    /**
  • {@link Node}

    */

    private Node scene = null;



    /**
  • Tpf

    */

    private float tpf;



    /**
  • @see BaseSimpleGame#simpleInitGame()

    */

    @Override

    protected void simpleInitGame() {

    // SPATIALS

    final Vector3f location1 = new Vector3f(0f, 0f, 0f);

    spatial1 = new Box("SpatialBox", location1, 1f, 1f, 1f);

    ((Box)spatial1).setRandomColors();

    spatial1.setModelBound(new BoundingBox());

    spatial1.updateModelBound();



    // SCENE

    scene = new Node("Graph");

    scene.attachChild(spatial1);



    final Vector3f location2 = new Vector3f(5f, 5f, 0f);

    spatial2 = new Box("SpatialBox", location2, 1.1f, 1.2f, 1.3f);

    spatial2.setModelBound(new BoundingBox());

    spatial2.updateModelBound();

    ((Box)spatial2).setRandomColors();

    scene.attachChild(spatial2);



    // // PERF IMP, DO NOT RENDER BACK

    // final CullState cullState = display.getRenderer().createCullState();

    // cullState.setCullFace(CullState.Face.Back);

    // spatial1.setRenderState(cullState);

    // spatial2.setRenderState(cullState);

           

    // CAMERA

    final Camera camera = display.getRenderer().getCamera();

    camera.setLocation(new Vector3f(0, 0, 50));

    logger.info(camera.getLocation() + ", looking at " + camera.getDirection());



    // PASSES

    basicPassManager = new BasicPassManager();

    timer = Timer.getTimer();



    // BLOOM PASS

    bloomRenderPass = new BloomRenderPass(camera, 4);

    bloomRenderPass.add(spatial1);

    bloomRenderPass.setEnabled(true);

    bloomRenderPass.setBlurIntensityMultiplier(4f);

    bloomRenderPass.setBlurSize(0.10f);



    scene.updateGeometricState(0f, true);

    scene.updateRenderState();



    final RenderPass renderPass = new RenderPass();

    renderPass.add(scene);

    basicPassManager.add(renderPass);



    bloomRenderPass.setUseCurrentScene(true);

    basicPassManager.add(bloomRenderPass);

    }



    /**
  • @see BaseSimpleGame#simpleUpdate()

    */

    @Override

    protected void simpleUpdate() {

    timer.update();

    tpf = timer.getTimePerFrame();

    basicPassManager.updatePasses(tpf);

    }



    /**
  • @see BaseSimpleGame#simpleRender()

    */

    @Override

    protected void simpleRender() {

    final Renderer renderer = display.getRenderer();

    renderer.clearBuffers();



    final float currentBlurSize = bloomRenderPass.getBlurSize();

    if (currentBlurSize > 0.3f) {

    bloomRenderPass.setBlurSize(0f);

    } else {

    bloomRenderPass.setBlurSize(currentBlurSize + 0.01f);

    }



    scene.updateGeometricState(tpf, true);

    basicPassManager.renderPasses(renderer);

    }



    /**
  • @param args

    */

    public static void main(String[] args) {

    new RBPassTest().start();

    }

    }

Hi,



Should this go into Graphics? Is it too "hard" or too "numb" as a question?



T

You're using the call

bloomRenderPass.setUseCurrentScene(true);

which means it effects the entire scene rather than nodes you added to the pass.

Thank you very much!

One question bringing another one…

I have a scene with 2000+ nodes, and I would like each of them to have its own Bloom renderer…

Instantiating one Bloom renderer per node does not work, and drags massively on resources…

any suggestion?