Postprocessing filter

Hi guy, first of all, thx for f*cking up the login system. My Old nick was sytrox i cant login now and cant receive email for restoring password (what happened?).

Never mind :).

Im trying to do some post processing with the filters. But even if i set a solig color in the fragment shader, i only get a black screen. What have i done wrong? I’m using this build: GitHub - phr00t/jmonkeyengine: jMonkeyEngine is a 3D game engine for adventurous Java developers. It’s open source, cross platform and cutting edge. And it is all beautifully documented. This is Phr00t's version of that library; better performance, bleeding-edge commits, support for Virtual Reality & multithreading. but have’nt tried it yet with the original.

This is my filter

 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mygame;

import com.jme3.asset.AssetManager;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.post.Filter;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import java.io.IOException;

/**
 *
 * @author db-141205
 */
public class GodrayFilter extends Filter{
    private int screenWidth;
    private int screenHeight;    
    private RenderManager renderManager;
    private ViewPort viewPort;

    private AssetManager assetManager;
    private int initalWidth;
    private int initalHeight;

    private float exposure = 0.0094f;
    private float decay = 0.95f;
    private float density = 1.0f;
    private float weight = 15.00f;
    private Vector2f lightPositionOnScreen = new Vector2f();
    public GodrayFilter(){
        super("GodrayFilter");
    }
    
    @Override
    protected void initFilter(AssetManager assetManager, RenderManager renderManager, ViewPort vp, int w, int h) {
        this.renderManager = renderManager;
        this.viewPort = vp;

        this.assetManager = assetManager;
        this.initalWidth = w;
        this.initalHeight = h;
        
        material = new Material(assetManager, "MatDefs/godray.j3md");
    }

    @Override
    protected Material getMaterial() {
        material.setVector2("lightPositionOnScreen", Vector2f.ZERO);
        material.setFloat("exposure", 0.0094f);
        material.setFloat("decay", 0.95f);
        material.setFloat("density", 1.00f);
        material.setFloat("weight", 15.00f);
        return material;
    }
    
    @Override
    public void write(JmeExporter ex) throws IOException {
        super.write(ex);
        OutputCapsule oc = ex.getCapsule(this);
        oc.write(exposure, "exposure", 0.0094f);
        oc.write(decay, "decay", 0.95f);
        oc.write(density, "density", 1.00f);
        oc.write(weight, "weight",  15.00f);
        oc.write(lightPositionOnScreen, "lightPositionOnScreen", Vector2f.ZERO);
    }
    
     @Override
    public void read(JmeImporter im) throws IOException {
        super.read(im);
        InputCapsule ic = im.getCapsule(this);
        exposure = (Float) ic.readFloat("exposure", 0.0094f);
        decay = (Float) ic.readFloat("decay", 0.95f);
        density = (Float) ic.readFloat("density", 1.00f);
        weight = (Float) ic.readFloat("weight",  15.00f);
        lightPositionOnScreen = (Vector2f) ic.readSavable("lightPositionOnScreen", Vector2f.ZERO);
    }
    
}

j3md:

MaterialDef godray {
    MaterialParameters {
        Float exposure
        Float decay
        Float density
        Float weight
        Vector2 lightPositionOnScreen
        Texture2D Texture
        Int NumSamples
        
    }
    Technique {
        WorldParameters {
            WorldViewProjectionMatrix
            ProjectionMatrix
            inPosition
            inTexCoord
        }
        VertexShader GLSL150:   Shaders/godray.vert
        FragmentShader GLSL150: Shaders/godray.frag
    }
}

fragment shader:

uniform float m_exposure;
uniform float m_decay;
uniform float m_density;
uniform float m_weight;
uniform vec2 m_lightPositionOnScreen;
uniform sampler2D m_texture;
varying vec2 vUv;
const int NUM_SAMPLES = 100 ;

void main()
{
    vec2 deltaTextCoord = vec2( vUv - m_lightPositionOnScreen.xy );
    vec2 textCoo = vUv;
    deltaTextCoord *= 1.0 /  float(NUM_SAMPLES) * m_density;
    float illuminationDecay = 1.0;
    gl_FragColor = vec4(0,0,0,0);
    for(int i=0; i < NUM_SAMPLES ; i++)
    {
             textCoo -= deltaTextCoord;
             vec4 sample = texture2D(m_texture, textCoo );

             sample *= illuminationDecay * m_weight;

             gl_FragColor += sample;

             illuminationDecay *= m_decay;
     }
     gl_FragColor *= m_exposure;
gl_FragColor = vec4(1.0f,1.0f,1.0f,1.0f);
}

vertex shader:

varying vec2 vUv;
uniform mat4 g_WorldViewProjectionMatrix;
in vec4 inPosition;
in vec2 inTexCoord;

void main()
{
        vUv = inTexCoord;
        gl_Position = g_WorldViewProjectionMatrix * inPosition;
}

Is it working if you’re not running in VR mode, ie with only one view port?

Well we did our best. Sad part is that I could have helped you but you just made it to my ignore list with that rant.

2 Likes

Hi, sorry for my rude start.
I received the mail minutes after i created this thread.
It makes me crazy if a login wont work (im using pw-manager) and restoring functionality does’nt respond.

In the meantime i tested it without ovr support. Sadly i cant take a snapshot, it just shows a black screen (even not the debug info). Vertices and triangles are bouncing the whole time (more than tens of thousand changes each frame) and i just see a small plane with white color rotating arroud the camera in y axis. Its the output of my shader.

With the original build, it seems to work, but i cant set the ovr mode.

With the build from phroot, i only see something in fullscreenview, otherwise, the frame keeps black (even no debug info).

We want to create a game like the movie enders game.
We started a while ago with kinect and oculus rift under together with unity.

We know “integrated” the kinect and the oculus rift in jme, but the post processing filters wont work as expected.

This filter is the RadialBlurFilter right? or light scattering?
@rickard could be an issue when the filters are cloned for the second viewport.

it’s not a build in filter, its the filter i posted here first in the thread.
build in filters like bloom or volumetric lights are working nice, but i want to create own and hang up with a black screen in ovr mode.

There could definitely be a problem with cloning.
One thing you can try is to add a proper clone() method to the filter. It might be a problem with both viewports using the same instance of the filter. With a clone() method, it will create one for each (should happen automatically).

i dont get it

i took the radialblurfilter as template for my filter.

thers no clone, my filter is even simpler (should only show a white plane) but shows alwas a black screen when in ovr mode.

The OVRAppState tries to clone any filter to both viewports. Without an implemented clone() method custom filters may have problems displaying correctly.
Does the radial blur filter work correctly in VR mode? I don’t believe I’ve tried it.

no it does not work as it should do. the images are not the same.
but how can i get it work correctly, just for me as an exercise.
what should the clone exactly do?

if i only create a new filter in the clone method, nothing changes.