Oh yeah, I forgot the filter is just going to assign a different output FrameBuffer to the viewport itâs assigned to so if you assign just one filter to the last viewport then youâll only see that viewport.
I used the postQueue(RenderQueue rq) method in one of my ScreenController classes to do my glow filter which is applied to multiple cameras:
glowQuad.updateGeometricState();
quad.updateGeometricState();
if (UI.getState() == UI.STATE_GAME && Opts.glow > Opts.GLOW_OFF) {
renderManager.getRenderer().setBackgroundColor(ColorRGBA.Black);
renderManager.getRenderer().setFrameBuffer(glowBuff);
renderManager.getRenderer().clearBuffers(true, true, true);
UI.getGameCam().getMidCam().resize(glowBuff.getWidth(), glowBuff.getHeight(), true);
UI.getGameCam().getForeCam().resize(glowBuff.getWidth(), glowBuff.getHeight(), true);
renderManager.setForcedTechnique("Glow");
renderManager.renderViewPortRaw(UI.getGameCam().getMidPort());
renderManager.getRenderer().clearBuffers(false, true, true);
renderManager.renderViewPortRaw(UI.getGameCam().getForePort());
renderManager.setForcedTechnique(null);
UI.getGameCam().getMidCam().resize(w, h, true);
UI.getGameCam().getForeCam().resize(w, h, true);
glowQuad.setMaterial(vBlur);
renderManager.setCamera(glowCam, true);
renderManager.renderGeometry(glowQuad);
glowQuad.setMaterial(hBlur);
renderManager.setCamera(glowCam, true);
renderManager.renderGeometry(glowQuad);
if (Opts.glow == Opts.GLOW_HIGH) {
glowQuad.setMaterial(vBlur);
renderManager.setCamera(glowCam, true);
renderManager.renderGeometry(glowQuad);
glowQuad.setMaterial(hBlur);
renderManager.setCamera(glowCam, true);
renderManager.renderGeometry(glowQuad);
}
//Set the renderer back to default background color
renderManager.getRenderer().setBackgroundColor(ColorRGBA.BlackNoAlpha);
quad.setMaterial(glowMat);
//Set the renderer back to the main frame buffer and render the final quad using a /MatDefs/Common/Misc/Unshaded material with getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Additive) set so it renders adds the glow to the original scene.
renderManager.getRenderer().setFrameBuffer(defaultBuffer);
renderManager.setCamera(cam, true);
renderManager.renderGeometry(quad);
}
Iâm using a class that extends NiftyJmeDisplay, because Iâm using NiftyGUI, and instantiating that when I create the Nifty display so my constructor looks something like this:
public NiftyDiemDisplay(
final AssetManager assetManager,
final InputManager inputManager,
final AudioRenderer audioRenderer,
final ViewPort viewport,
final FrameBuffer defaultBuffer) {
super(assetManager, inputManager, audioRenderer, viewport);
this.defaultBuffer = defaultBuffer;
cam.resize(w, h, true);
quad.setWidth(w);
quad.setHeight(h);
vBlur = new Material(assetManager, "MatDefs/Post/VGaussianBlur.j3md");
hBlur = new Material(assetManager, "MatDefs/Post/HGaussianBlur.j3md");
glowMat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
glowMat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Additive);
glowBuff = new FrameBuffer((int)FastMath.ceil(w * 0.5f),
(int)FastMath.ceil(h * 0.5f), 0);
glowBuff.setColorBuffer(Image.Format.RGBA8);
glowBuff.setDepthBuffer(Image.Format.Depth);
glowTex = new Texture2D(glowBuff.getWidth(),
glowBuff.getHeight(), Image.Format.RGBA8);
glowTex.setWrap(Texture.WrapMode.MirroredRepeat);
glowBuff.setColorTexture(glowTex);
vBlur.setTexture("Texture", glowTex);
vBlur.setFloat("Scale", 2f);
vBlur.setFloat("Size", glowBuff.getHeight());
hBlur.setTexture("Texture", glowTex);
hBlur.setFloat("Scale", 2f);
hBlur.setFloat("Size", glowBuff.getWidth());
glowCam.resize(glowBuff.getWidth(), glowBuff.getHeight(), true);
glowQuad.setWidth(glowBuff.getWidth());
glowQuad.setHeight(glowBuff.getHeight());
glowMat.setTexture("ColorMap", glowTex);
}
I rewrote some of that code from what I have because thereâs more going on in that class and methods that isnât relevant to this issue so I may have made a flub here or there in copy pasting
Edit: Hereâs the full unaltered class:
package carpeDiem.UI;
import carpeDiem.Opts;
import com.jme3.asset.AssetManager;
import com.jme3.audio.AudioRenderer;
import com.jme3.input.InputManager;
import com.jme3.material.Material;
import com.jme3.material.RenderState;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.renderer.Camera;
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.texture.FrameBuffer;
import com.jme3.texture.Image;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture2D;
import com.jme3.ui.Picture;
/**
*
* @author Adam T. Ryder http://1337atr.weebly.com
*/
public class NiftyDiemDisplay extends NiftyJmeDisplay {
public final FrameBuffer uiBuff;
public final Camera cam = new Camera(1, 1);
public final Picture quad = new Picture("Nifty Quad");
public final Material frostMat;
public final Texture2D uiTex;
public final FrameBuffer defaultBuffer;
private FrameBuffer glowBuff;
private Texture2D glowTex;
private final Picture glowQuad = new Picture("Glow Quad");
private final Material glowMat;
private final Material vBlur;
private final Material hBlur;
private final Camera glowCam = new Camera(1, 1);
public NiftyDiemDisplay(
final AssetManager assetManager,
final InputManager inputManager,
final AudioRenderer audioRenderer,
final ViewPort viewport,
final int atlasWidth,
final int atlasHeight,
final FrameBuffer defaultBuffer) {
super(assetManager, inputManager, audioRenderer, viewport, atlasWidth, atlasHeight);
this.defaultBuffer = defaultBuffer;
uiBuff = new FrameBuffer(w, h, 0);
uiBuff.setColorBuffer(Image.Format.RGBA8);
uiBuff.setDepthBuffer(Image.Format.Depth);
if (Opts.uifrost > Opts.FROST_LOW) {
viewport.setOutputFrameBuffer(uiBuff);
}
uiTex = new Texture2D(w, h, Image.Format.RGBA8);
uiTex.setWrap(Texture.WrapMode.MirroredRepeat);
uiBuff.setColorTexture(uiTex);
cam.resize(uiBuff.getWidth(), uiBuff.getHeight(), true);
quad.setWidth(uiBuff.getWidth());
quad.setHeight(uiBuff.getHeight());
frostMat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
frostMat.setTexture("ColorMap", uiTex);
quad.setMaterial(frostMat);
vBlur = new Material(assetManager, "MatDefs/Post/VGaussianBlur.j3md");
hBlur = new Material(assetManager, "MatDefs/Post/HGaussianBlur.j3md");
glowMat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
glowMat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Additive);
setGlowMode();
}
public NiftyDiemDisplay(
final AssetManager assetManager,
final InputManager inputManager,
final AudioRenderer audioRenderer,
final ViewPort viewport,
final FrameBuffer defaultBuffer) {
super(assetManager, inputManager, audioRenderer, viewport);
this.defaultBuffer = defaultBuffer;
uiBuff = new FrameBuffer(w, h, 0);
uiBuff.setColorBuffer(Image.Format.RGBA8);
uiBuff.setDepthBuffer(Image.Format.Depth);
if (Opts.uifrost > Opts.FROST_LOW) {
viewport.setOutputFrameBuffer(uiBuff);
}
uiTex = new Texture2D(w, h, Image.Format.RGBA8);
uiTex.setWrap(Texture.WrapMode.MirroredRepeat);
uiBuff.setColorTexture(uiTex);
cam.resize(uiBuff.getWidth(), uiBuff.getHeight(), true);
quad.setWidth(uiBuff.getWidth());
quad.setHeight(uiBuff.getHeight());
frostMat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
frostMat.setTexture("ColorMap", uiTex);
quad.setMaterial(frostMat);
vBlur = new Material(assetManager, "MatDefs/Post/VGaussianBlur.j3md");
hBlur = new Material(assetManager, "MatDefs/Post/HGaussianBlur.j3md");
glowMat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
glowMat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Additive);
setGlowMode();
}
public void setFrostMode() {
if (Opts.uifrost < Opts.FROST_MED) {
vp.setOutputFrameBuffer(defaultBuffer);
} else {
vp.setOutputFrameBuffer(uiBuff);
}
}
public void setGlowMode() {
if (Opts.glow == Opts.GLOW_HIGH) {
glowCam.resize(w, h, true);
glowQuad.setWidth(w);
glowQuad.setHeight(h);
glowBuff = new FrameBuffer(w, h, 0);
glowBuff.setColorBuffer(Image.Format.RGBA8);
glowBuff.setDepthBuffer(Image.Format.Depth);
glowTex = new Texture2D(w, h, Image.Format.RGBA8);
glowTex.setWrap(Texture.WrapMode.MirroredRepeat);
glowBuff.setColorTexture(glowTex);
vBlur.setTexture("Texture", glowTex);
vBlur.setFloat("Scale", 2f);
vBlur.setFloat("Size", h);
hBlur.setTexture("Texture", glowTex);
hBlur.setFloat("Scale", 2f);
hBlur.setFloat("Size", w);
glowMat.setTexture("ColorMap", glowTex);
} else if (Opts.glow == Opts.GLOW_LOW) {
glowBuff = new FrameBuffer((int)FastMath.ceil(w * 0.5f),
(int)FastMath.ceil(h * 0.5f), 0);
glowBuff.setColorBuffer(Image.Format.RGBA8);
glowBuff.setDepthBuffer(Image.Format.Depth);
glowTex = new Texture2D(glowBuff.getWidth(),
glowBuff.getHeight(), Image.Format.RGBA8);
glowTex.setWrap(Texture.WrapMode.MirroredRepeat);
glowBuff.setColorTexture(glowTex);
vBlur.setTexture("Texture", glowTex);
vBlur.setFloat("Scale", 2f);
vBlur.setFloat("Size", glowBuff.getHeight());
hBlur.setTexture("Texture", glowTex);
hBlur.setFloat("Scale", 2f);
hBlur.setFloat("Size", glowBuff.getWidth());
glowCam.resize(glowBuff.getWidth(), glowBuff.getHeight(), true);
glowQuad.setWidth(glowBuff.getWidth());
glowQuad.setHeight(glowBuff.getHeight());
glowMat.setTexture("ColorMap", glowTex);
} else {
glowBuff = null;
glowTex = null;
}
}
@Override
public void postQueue(RenderQueue rq) {
glowQuad.updateGeometricState();
quad.updateGeometricState();
if (UI.getState() == UI.STATE_GAME && Opts.glow > Opts.GLOW_OFF) {
renderManager.getRenderer().setBackgroundColor(ColorRGBA.Black);
renderManager.getRenderer().setFrameBuffer(glowBuff);
renderManager.getRenderer().clearBuffers(true, true, true);
UI.getGameCam().getMidCam().resize(glowBuff.getWidth(), glowBuff.getHeight(), true);
UI.getGameCam().getForeCam().resize(glowBuff.getWidth(), glowBuff.getHeight(), true);
renderManager.setForcedTechnique("Glow");
renderManager.renderViewPortRaw(UI.getGameCam().getMidPort());
renderManager.getRenderer().clearBuffers(false, true, true);
renderManager.renderViewPortRaw(UI.getGameCam().getForePort());
renderManager.setForcedTechnique(null);
UI.getGameCam().getMidCam().resize(w, h, true);
UI.getGameCam().getForeCam().resize(w, h, true);
glowQuad.setMaterial(vBlur);
renderManager.setCamera(glowCam, true);
renderManager.renderGeometry(glowQuad);
glowQuad.setMaterial(hBlur);
renderManager.setCamera(glowCam, true);
renderManager.renderGeometry(glowQuad);
if (Opts.glow == Opts.GLOW_HIGH) {
glowQuad.setMaterial(vBlur);
renderManager.setCamera(glowCam, true);
renderManager.renderGeometry(glowQuad);
glowQuad.setMaterial(hBlur);
renderManager.setCamera(glowCam, true);
renderManager.renderGeometry(glowQuad);
}
renderManager.getRenderer().setBackgroundColor(ColorRGBA.BlackNoAlpha);
quad.setMaterial(glowMat);
renderManager.getRenderer().setFrameBuffer(defaultBuffer);
renderManager.setCamera(cam, true);
renderManager.renderGeometry(quad);
if (Opts.uifrost > Opts.FROST_LOW) {
renderManager.getRenderer().setFrameBuffer(uiBuff);
}
}
if (Opts.uifrost > Opts.FROST_OFF) {
renderManager.getRenderer().copyFrameBuffer(defaultBuffer,
uiBuff, false);
quad.setMaterial(frostMat);
}
super.postQueue(rq);
if (Opts.uifrost > Opts.FROST_LOW) {
quad.updateGeometricState();
renderManager.getRenderer().setFrameBuffer(defaultBuffer);
renderManager.setCamera(cam, true);
renderManager.renderGeometry(quad);
}
}
}
I setup NiftyGUI as follows:
niftyDisplay = new NiftyDiemDisplay(assetManager, inputManager,
audioRenderer, guiViewPort, guiViewPort.getOutputFrameBuffer());
nifty = niftyDisplay.getNifty();
guiViewPort.addProcessor(niftyDisplay);