This little filter worked like charm some months ago, then I updated the SDK and now it throws a strange exception at me. I find it a bit odd that the Bloom MatDef is loaded since it’s not used or referenced in my code at all. I have looked through the code several times, (it’s not that much), but I’m out of things to try now…
[java]
package me.merciless.fx;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
/**
-
@author kwando
/
public class Main extends SimpleApplication {
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);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
rootNode.attachChild(geom);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(new LensFX());
viewPort.addProcessor(fpp);
}
@Override
public void simpleUpdate(float tpf) {
}
@Override
public void simpleRender(RenderManager rm) {
}
}
[/java]
[java]
/
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package me.merciless.fx;
import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.post.Filter;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture;
import java.util.ArrayList;
/**
*
-
@author kwando
*/
public class LensFX extends Filter {
private float downSampleFactor = 2f;
private float threshold = 0.75f;
private float blurScale = 1.5f;
private Vector3f chromatic = new Vector3f(0.1f, 0.2f, 0.3f).multLocal(0.07f);
private Material thresholdMaterial;
private Material radialBlurMaterial;
private float flareDispersal = .2f;
private float flareHaloWidth = .48f;
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
thresholdMaterial = new Material(manager, "MatDefs/Threshold.j3md");
thresholdMaterial.setFloat("Threshold", threshold);
radialBlurMaterial = new Material(manager, "MatDefs/RadialBlur.j3md");
material = new Material(manager, "MatDefs/FinalPass.j3md");
postRenderPasses = new ArrayList<Pass>();
Format format = Format.RGBA8;
final int width = (int) (w / downSampleFactor);
final int height = (int) (h / downSampleFactor);
final Pass thresholdPass = new Pass() {
@Override
public boolean requiresSceneAsTexture() {
return true;
}
};
thresholdPass.init(renderManager.getRenderer(), width, height, format, Format.Depth, 1, thresholdMaterial);
postRenderPasses.add(thresholdPass);
final Pass flarePass = new Pass() {
@Override
public boolean requiresSceneAsTexture() {
return false;
}
@Override
public void beforeRender() {
Texture texture = thresholdPass.getRenderedTexture();
radialBlurMaterial.setFloat("FlareHaloWidth", flareHaloWidth);
radialBlurMaterial.setFloat("FlareDispersal", flareDispersal);
radialBlurMaterial.setVector3("Chromatic", chromatic);
radialBlurMaterial.setTexture("Texture", texture);
}
};
flarePass.init(renderManager.getRenderer(), width, height, format, Format.Depth, 1, radialBlurMaterial);
postRenderPasses.add(flarePass);
// SETUP BLUR
final Material hBlurMat = new Material(manager, "Common/MatDefs/Blur/HGaussianBlur.j3md");
final Material vBlurMat = new Material(manager, "Common/MatDefs/Blur/VGaussianBlur.j3md");
final Pass hblurPass = new Pass() {
@Override
public boolean requiresSceneAsTexture() {
return false;
}
@Override
public void beforeRender() {
hBlurMat.setFloat("Size", height);
hBlurMat.setFloat("Scale", blurScale);
hBlurMat.setTexture("Texture", flarePass.getRenderedTexture());
}
};
hblurPass.init(renderManager.getRenderer(), width, height, format, Format.Depth, 1, hBlurMat);
postRenderPasses.add(hblurPass);
final Pass vblurPass = new Pass() {
@Override
public boolean requiresSceneAsTexture() {
return false;
}
@Override
public void beforeRender() {
vBlurMat.setTexture("Texture", hblurPass.getRenderedTexture());
vBlurMat.setFloat("Size", width);
vBlurMat.setFloat("Scale", blurScale);
}
};
vblurPass.init(renderManager.getRenderer(), width, height, format, Format.Depth, 1, vBlurMat);
postRenderPasses.add(vblurPass);
material.setTexture("Overlay", vblurPass.getRenderedTexture());
material.setTexture("Dirt", manager.loadTexture("Textures/lensdirt_lowc.tga"));
}
@Override
protected Material getMaterial() {
return material;
}
}
[/java]
<< removed some duplicated log entries >>
2012-jul-30 19:13:59 com.jme3.scene.Node attachChild
INFO: Child (null) attached to this node (Statistics View)
2012-jul-30 19:13:59 com.jme3.material.MaterialDef <init>
INFO: Loaded material definition: Threshold
2012-jul-30 19:13:59 com.jme3.material.MaterialDef <init>
INFO: Loaded material definition: RadialBlur
2012-jul-30 19:13:59 com.jme3.material.MaterialDef <init>
INFO: Loaded material definition: FinalPass
2012-jul-30 19:13:59 com.jme3.material.MaterialDef <init>
INFO: Loaded material definition: Bloom
2012-jul-30 19:13:59 com.jme3.material.MaterialDef <init>
INFO: Loaded material definition: Bloom
2012-jul-30 19:13:59 com.jme3.app.Application handleError
ALLVARLIG: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalArgumentException: Material parameter is not defined: NumSamples
at com.jme3.material.Material.checkSetParam(Material.java:442)
at com.jme3.material.Material.clearParam(Material.java:478)
at com.jme3.post.FilterPostProcessor.renderFilterChain(FilterPostProcessor.java:242)
at com.jme3.post.FilterPostProcessor.postFrame(FilterPostProcessor.java:293)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:978)
at com.jme3.renderer.RenderManager.render(RenderManager.java:1016)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:251)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:184)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:680)
2012-jul-30 19:13:59 com.jme3.renderer.lwjgl.LwjglRenderer cleanup
INFO: Deleting objects and invalidating state
2012-jul-30 19:13:59 com.jme3.scene.Node detachChildAt
INFO: Gui Node (Node): Child removed.
2012-jul-30 19:13:59 com.jme3.scene.Node detachChildAt
INFO: Gui Node (Node): Child removed.
2012-jul-30 19:13:59 com.jme3.input.lwjgl.LwjglMouseInput destroy
INFO: Mouse destroyed.
2012-jul-30 19:13:59 com.jme3.input.lwjgl.LwjglKeyInput destroy
INFO: Keyboard destroyed.
2012-jul-30 19:13:59 com.jme3.system.lwjgl.LwjglAbstractDisplay deinitInThread
INFO: Display destroyed.
BUILD SUCCESSFUL (total time: 6 seconds)