[Kind of solved] Strange crash, LensFX filter

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]
Code:
run: 2012-jul-30 19:13:58 com.jme3.system.JmeDesktopSystem initialize INFO: Running on jMonkeyEngine 3.0.0 Beta 2012-jul-30 19:13:58 com.jme3.system.Natives extractNativeLibs INFO: Extraction Directory: /Users/kwando/jMonkeyProjects/LensFX 2012-jul-30 19:13:58 com.jme3.system.lwjgl.LwjglAbstractDisplay run INFO: Using LWJGL 2.8.3 2012-jul-30 19:13:58 com.jme3.system.lwjgl.LwjglDisplay createContext INFO: Selected display mode: 1024 x 768 x 0 @0Hz 2012-jul-30 19:13:58 com.jme3.system.lwjgl.LwjglContext printContextInitInfo INFO: Adapter: null 2012-jul-30 19:13:58 com.jme3.system.lwjgl.LwjglContext printContextInitInfo INFO: Driver Version: null 2012-jul-30 19:13:58 com.jme3.system.lwjgl.LwjglContext printContextInitInfo INFO: Vendor: ATI Technologies Inc. 2012-jul-30 19:13:58 com.jme3.system.lwjgl.LwjglContext printContextInitInfo INFO: OpenGL Version: 2.1 ATI-1.0.25 2012-jul-30 19:13:58 com.jme3.system.lwjgl.LwjglContext printContextInitInfo INFO: Renderer: AMD Radeon HD 6750M OpenGL Engine 2012-jul-30 19:13:58 com.jme3.system.lwjgl.LwjglContext printContextInitInfo INFO: GLSL Ver: 1.20 2012-jul-30 19:13:58 com.jme3.system.lwjgl.LwjglTimer <init> INFO: Timer resolution: 1 000 ticks per second 2012-jul-30 19:13:58 com.jme3.renderer.lwjgl.LwjglRenderer initialize INFO: Caps: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample, OpenGL20, OpenGL21, ARBprogram, GLSL100, GLSL110, GLSL120, VertexTextureFetch, TextureArray, FloatTexture, FloatColorBuffer, FloatDepthBuffer, PackedFloatTexture, SharedExponentTexture, PackedFloatColorBuffer, NonPowerOfTwoTextures, MeshInstancing, Multisample] 2012-jul-30 19:13:58 com.jme3.asset.AssetConfig loadText VARNING: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader 2012-jul-30 19:13:58 com.jme3.asset.DesktopAssetManager <init> INFO: DesktopAssetManager created. 2012-jul-30 19:13:59 com.jme3.renderer.Camera <init> INFO: Camera created (W: 1 024, H: 768) 2012-jul-30 19:13:59 com.jme3.renderer.Camera <init> INFO: Camera created (W: 1 024, H: 768) 2012-jul-30 19:13:59 com.jme3.input.lwjgl.LwjglMouseInput initialize INFO: Mouse created. 2012-jul-30 19:13:59 com.jme3.input.lwjgl.LwjglKeyInput initialize INFO: Keyboard created. 2012-jul-30 19:13:59 com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread INFO: AudioRenderer supports 64 channels 2012-jul-30 19:13:59 com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread VARNING: OpenAL EFX not available! Audio effects won't work. 2012-jul-30 19:13:59 com.jme3.material.MaterialDef <init> INFO: Loaded material definition: Unshaded 2012-jul-30 19:13:59 com.jme3.scene.Node attachChild INFO: Child (BitmapFont) attached to this node (null) 2012-jul-30 19:13:59 com.jme3.scene.Node attachChild INFO: Child (Box) attached to this node (Root Node) 2012-jul-30 19:13:59 com.jme3.renderer.Camera <init> INFO: Camera created (W: 1, H: 1)

<< 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)

@kwando said:
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
[/code]


Note: the name that appears in the log is just whatever is specified in the j3md file. So if you have custom material defs then maybe they were cut and pasted from Bloom and this was never changed.
@pspeed said:
Note: the name that appears in the log is just whatever is specified in the j3md file. So if you have custom material defs then maybe they were cut and pasted from Bloom and this was never changed.


Yepp, they are apparently from the "Common/MatDefs/Blur/HGaussianBlur.j3md" and "Common/MatDefs/Blur/VGaussianBlur.j3md".. thanks for the clue @pspeed. Now I'm going too figure out why it is complaining about the NumSamples.

Turns out that FilterPostProcessor is setting the NumSamples materialParameter on the “finalPass” renderPass… it’s some multisample thing that I don’t quite understand (yet). It works when adding “Int NumSamples” to my finalPass matdef.



Might have to dig a bit deeper into the engine to discover why it works.