Hi,
I’ve had a stab at updating the “Glow Effect” code (http://www.jmonkeyengine.com/forum/index.php?topic=7031.msg61907#msg61907). I’ve done OK (it compiles), and there is some good news in that I can see a glowing set of pipes… But that’s all. The box itself does not display. I suspect this is down to my changes on the lighting, but I can’t quite spot it. Help!
Here is the code. In order to get it to load the files, you’ll need to download the two attachments, and point the ctexFile and gtexFile variables to them as appropriate.
If anyone could finish the job off, then I guess we should repoint the wiki to this newer link.
import com.jme.app.BaseGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.light.DirectionalLight;
import com.jme.math.Quaternion;
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.Spatial.LightCombineMode;
import com.jme.scene.Text;
import com.jme.scene.shape.Box;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.CullState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
import com.jmex.effects.glsl.BloomRenderPass;
import java.io.File;
public class GlowScene extends BaseGame {
private static int width, height, depth, freq;
private static boolean fullscreen;
private Camera cam;
private Node scene, gScene;
protected Timer timer;
float rot = 0;
Quaternion rotation = new Quaternion();
private TextureState ts;
private TextureState ts2;
float tpf;
private BloomRenderPass bloomPass = null;
protected BasicPassManager pManager;
public static void main(String[] args) {
GlowScene app = new GlowScene();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
protected void update(float interpolation) {
timer.update();
interpolation = timer.getTimePerFrame();
tpf = timer.getTimePerFrame();
if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
finished = true;
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand(
"screen_shot", false)) {
display.getRenderer().takeScreenShot("SimpleGameScreenShot");
}
pManager.updatePasses(tpf);
}
protected void render(float interpolation) {
Renderer r = display.getRenderer();
r.clearBuffers();
rotation = rotation.fromAngleAxis(rot, new Vector3f(0.25f, 1, 0.5f));
scene.setLocalRotation(rotation);
gScene.setLocalRotation(rotation);
rot += 0.001f;
if (rot > Math.PI * 2) {
rot = 0;
}
scene.updateGeometricState(tpf, true);
gScene.updateGeometricState(tpf, true);
pManager.renderPasses(r);
}
protected void initSystem() {
// width = DisplaySystem.getDisplaySystem().getWidth();
// height = DisplaySystem.getDisplaySystem().getHeight();
// depth = DisplaySystem.getDisplaySystem().getBitDepth();
// freq = DisplaySystem.getDisplaySystem().getFrequency();
// fullscreen = DisplaySystem.getDisplaySystem().isFullScreen();
width = 640;
height = 480;
depth = 16;
freq = 60;
fullscreen = false;
pManager = new BasicPassManager();
try {
display = DisplaySystem.getDisplaySystem(DisplaySystem.getDisplaySystem().getDisplayRenderer());
display.createWindow(width, height, depth, freq, fullscreen);
cam = display.getRenderer().createCamera(width, height);
} catch (JmeException e) {
e.printStackTrace();
System.exit(1);
}
display.getRenderer().setBackgroundColor(ColorRGBA.black);
cam.setFrustumPerspective(45.0f, (float) width / (float) height, 1, 1000);
Vector3f loc = new Vector3f(0.0f, 45.0f, 90.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.5f, -1.0f);
cam.setFrame(loc, left, up, dir);
cam.update();
timer = Timer.getTimer();
display.getRenderer().setCamera(cam);
KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
KeyBindingManager.getKeyBindingManager().set("screen_shot", KeyInput.KEY_C);
}
protected void initGame() {
scene = new Node("Scene graph node");
gScene = new Node("Scene graph node");
Box s = new Box("Box", new Vector3f(-25, -25, -25), new Vector3f(25, 25, 25));
Box sGlow = new Box("Box2", new Vector3f(-25, -25, -25), new Vector3f(25, 25, 25));
s.setModelBound(new BoundingBox());
s.updateModelBound();
sGlow.setModelBound(new BoundingBox());
sGlow.updateModelBound();
LightState ls = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(0.0f, -1.0f, 0.5f));
dl.setDiffuse(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));
dl.setAmbient(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
dl.setEnabled(true);
ls.setEnabled(true);
ls.attach(dl);
scene.setRenderState(ls);
CullState cs = display.getRenderer().createCullState();
cs.setCullFace(CullState.Face.Back);
s.setRenderState(cs);
sGlow.setRenderState(cs);
BlendState as = display.getRenderer().createBlendState();
as.setDestinationFunction(BlendState.DestinationFunction.One);
as.setSourceFunction(BlendState.SourceFunction.One);
ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
File ctexFile = new File("images/ctex.jpg");
try {
Texture ctexTexture = TextureManager.loadTexture(ctexFile.toURI().toURL(), Texture.MinificationFilter.BilinearNoMipMaps, Texture.MagnificationFilter.Bilinear);
ts.setTexture(ctexTexture);
} catch (Exception ex) {
System.err.println("Unable to load ctex texture: " + ex);
}
ts2 = display.getRenderer().createTextureState();
ts2.setEnabled(true);
File gtexFile = new File("images/gtex.jpg");
try {
Texture gtexTexture = TextureManager.loadTexture(gtexFile.toURI().toURL(), Texture.MinificationFilter.BilinearNoMipMaps, Texture.MagnificationFilter.Bilinear);
ts2.setTexture(gtexTexture);
} catch (Exception ex) {
System.err.println("Unable to load gtex texture: " + ex);
}
s.setRenderState(ts);
sGlow.setRenderState(ts2);
scene.attachChild(s);
gScene.attachChild(sGlow);
bloomPass = new BloomRenderPass(cam, 4);
bloomPass.add(sGlow);
bloomPass.setEnabled(true);
scene.updateGeometricState(0.0f, true);
scene.setRenderState(ls);
scene.updateRenderState();
gScene.updateGeometricState(0.0f, true);
gScene.updateRenderState();
RenderPass pass1 = new RenderPass();
pass1.add(scene);
pManager.add(pass1);
bloomPass.setBlurIntensityMultiplier(1.7f);
bloomPass.setBlurSize(0.01f);
RenderPass pass2 = new RenderPass();
pass2.add(gScene);
pass2.setPassState(as);
pManager.add(pass2);
if (!bloomPass.isSupported()) {
Text t = new Text("Text", "GLSL Not supported on this computer.");
t.setRenderQueueMode(Renderer.QUEUE_ORTHO);
t.setLightCombineMode(LightCombineMode.Off);
t.setLocalTranslation(new Vector3f(0, 20, 0));
} else {
bloomPass.setUseCurrentScene(true);
pManager.add(bloomPass);
}
}
protected void reinit() {
display.recreateWindow(width, height, depth, freq, fullscreen);
}
protected void cleanup() {
ts.deleteAll();
ts2.deleteAll();
}
}