Heat Camera in JME

Hi!



I’m doing an artificial intelligence simulation using JME3 and I’m simulating as many robotic sensors as possible! I’ve got stereo camera, depth camera, and now I’m working on a heat camera. My idea for this one was to have a particle emitter for every heat source, but only render these emitters for the heat camera’s viewport, so only the heat camera can see the ‘heat’. I’m currently doing this using by attaching and detaching the particle emitters from the rootnode using the scene processor’s preframe and postframe callbacks like this:



public void preFrame(float tpf){



//tester box only seen by heatcam

Box box2 = new Box(new Vector3f(3,2,0), 0.5f, 0.5f, 0.5f);

Geometry red = new Geometry(“Box”, box2);

Material mat2 = new Material(world.getAssetManager(), “Common/MatDefs/Misc/SolidColor.j3md”);

mat2.setColor(“Color”, ColorRGBA.Red);

red.setMaterial(mat2);

red.setName(“test”);

world.getRootNode().attachChild(red);



//add the heat sources to the scene

world.getWorldDesc().attachAllHotObjects();

world.getRootNode().updateGeometricState();

}



@Override



public void updateImageContents(){

cpuBuf.clear();



world.getRenderer().readFrameBuffer(buf, cpuBuf);





synchronized (image) {

Screenshots.convertScreenShot(cpuBuf, image);

}

}



@Override



public void postFrame(FrameBuffer out){



super.postFrame(out);

world.getRootNode().detachChildNamed(“test”);



//detach the heat sources from the scene so other cameras can’t see them

world.getWorldDesc().detachAllHotObjects();

world.getRootNode().updateGeometricState();

}





I can currently see the test box geometry (only on the heat camera viewport, as desired), but the particle emitters are not visible. Is it something special about particle emitters that they wont render well when being rapidly attached and detached from the scenegraph like this?



Cheers



Adam

Not sure about the particles, but wouldn’t it be more natural to use something similar to glowmap for heat sources? You would specify glow color for each uniform object and glow map for more complicated things, you will get heat ‘bleeding’ for free…Then just render glowmap using normal Bloom filter, but use the texture directly instead of composing it with main frame.

You have to emit the particle, I don’t know if you do it. Also particles need time to be emitted, if you attach and detach on each frame, they won’t display at all.



But you should follow abies advice, post processing Filter is a better way of doing this IMO, but the glow filter won’t give you what you are looking for.



Hopefully, someone on the internet already did this :smiley:

(Shader Library) Predator's Thermal Vision Post Processing Filter (GLSL) | Geeks3D

there is GLSL shader code of a post processing effect on this page, i guess it wouldn’t require a lot of effort to be adapted to jME3.

So basically you need to create your own Filter!



here is a screen of the effect

http://newsodrome.com/hardware_news/predator-s-thermal-vision-post-processing-filter-glsl-22138382



Maybe it’s not exactly what you are looking for though, but I would try if I were you.

Keep the particles always attached. If updateLogicalState is not called on them, they won’t update at all.

Instead of attaching them to the root node for example, attach it to your “heat root node”, which is only rendered in your heat viewport

Wow, thanks for the ideas guys. Nehon the predator thermal vision looks really cool, but its really important for my simulation that the thermal camera can actually see things that normal cameras can’t see, otherwise there’s no additional benifit in having the sensor.



But that would be achieved either by


  1. rendering a “non-hot” root node with cold objects for the vision camera viewport, and a “hot” root node which has particle emitters attached for the thermal camera viewport. as momoko suggested


  2. or by using a glowmap to indicate the (hot) areas which would glow, and only putting the post processing filter on the heat camera viewport. as abie and nehon suggested.



    Have I understood your plans correctly, and is there a feeling over which would be better?

Hey momoko, I’m trying to do what you suggested and have a separate node with particle filters attached and render that in the heat camera viewport, but i’m getting an exception when I attach particle filters to a new node and try to render it. Here is a short example where i create a new node called ‘other’ and try to render it to a new viewport.

[java]package mygame;

import com.jme3.app.SimpleApplication;

import com.jme3.effect.ParticleEmitter;

import com.jme3.effect.ParticleMesh;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.Camera;

import com.jme3.renderer.RenderManager;

import com.jme3.renderer.ViewPort;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.scene.Node;

public class Main extends SimpleApplication {

Node other = new Node(“alt”);

public static void main(String[] args) {

Main app = new Main();

app.start();

}

@Override

public void simpleInitApp() {

Box b = new Box(Vector3f.ZERO, 1, 1, 1);

Geometry geom = new Geometry(“Box”, b);

geom.setLocalTranslation(new Vector3f(2,2,2));

//cam.setViewPort(0, 0.5f, 0, 1);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat.setColor(“m_Color”, ColorRGBA.Blue);

geom.setMaterial(mat);

rootNode.attachChild(geom);

viewPort.detachScene(rootNode);

Camera altcam = cam.clone();

//altcam.setViewPort(0.5f, 1, 0, 1);

Geometry geom2 = new Geometry(“Box”, b);

Material mat2 = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat2.setColor(“m_Color”, ColorRGBA.Red);

geom2.setMaterial(mat2);

ParticleEmitter heat = new ParticleEmitter(“Emitter”, ParticleMesh.Type.Triangle, 30);

Material mat_red = new Material(getAssetManager(), “Common/MatDefs/Misc/Particle.j3md”);

mat_red.setTexture(“Texture”, getAssetManager().loadTexture(“Effects/Explosion/flame.png”));

heat.setMaterial(mat_red);

heat.setImagesX(2); heat.setImagesY(2); // 2x2 texture animation

heat.setEndColor( new ColorRGBA(1f, 0f, 0f, 1f)); // red

heat.setStartColor(ColorRGBA.Red); // yellow

heat.setInitialVelocity(new Vector3f(0, 2f, 0));

heat.setStartSize(1.5f);

heat.setEndSize(0.1f);

heat.setGravity(0);

heat.setLowLife(0.5f);

heat.setHighLife(3f);

heat.setVelocityVariation(0.3f);

rootNode.attachChild(heat);

other = (Node) rootNode.clone();

other.attachChild(geom2);

ViewPort otherview = getRenderManager().createMainView(“test”,altcam);

otherview.attachScene(rootNode);

}

@Override

public void simpleUpdate(float tpf) {

other.updateGeometricState();

other.updateLogicalState(tpf);

}

@Override

public void simpleRender(RenderManager rm) {

//TODO: add render code

}

}[/java]

If I attach the particle emitter to the rootnode, and then attach the rootnode to the viewport (as above) it renders fine. But if i try to render a different node, by replacing the line otherview.attachScene(rootNode); with otherview.attachScene(other); , i get an exception. is there something special about the rootnode, shouldnt I be able to render any node?

You’re supposed to call updateLogicalState and then updateGeometricState, e.g.

[java]other.updateLogicalState(tpf);

other.updateGeometricState();[/java]