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;
}