Thanks @nehon, I got all the pass stuff to work however I’m running into a ridiculous elementary problem that really has me irritated. The program is seeming to refuse to pass anything other than a Texture2D into my shaders. I very specifically have defined a uniform, put it in the .j3md file and passed it in through beforeRender() however whenever I print it out the program prints null. The shader automatically assigns the value to 0 (or just thinks of null as 0?) therefore I am essentially setting blur to 0/0 which doesn’t even throw an error for some reason. I thought dividing by zero was impossible.
Here’s the horizontal blur (it’s the same on the vertical, just switched to the y axis on the sum += part):
uniform float Scale;
uniform float Size;
uniform sampler2D m_Texture;
varying vec2 texCoord;
void main() {
vec4 color = texture2D(m_Texture, texCoord);
float s = float(Scaleint);
float blurSize = Scale/Size;
vec4 sum = vec4(0.0);
sum += texture2D(m_Texture, vec2(texCoord.x- 4.0*blurSize, texCoord.y )) * 0.05;
sum += texture2D(m_Texture, vec2(texCoord.x- 3.0*blurSize, texCoord.y )) * 0.09;
sum += texture2D(m_Texture, vec2(texCoord.x - 2.0*blurSize, texCoord.y)) * 0.12;
sum += texture2D(m_Texture, vec2(texCoord.x- blurSize, texCoord.y )) * 0.15;
sum += texture2D(m_Texture, vec2(texCoord.x, texCoord.y)) * 0.16;
sum += texture2D(m_Texture, vec2(texCoord.x+ blurSize, texCoord.y )) * 0.15;
sum += texture2D(m_Texture, vec2(texCoord.x+ 2.0*blurSize, texCoord.y )) * 0.12;
sum += texture2D(m_Texture, vec2(texCoord.x+ 3.0*blurSize, texCoord.y )) * 0.09;
sum += texture2D(m_Texture, vec2(texCoord.x+ 4.0*blurSize, texCoord.y )) * 0.05;
gl_FragColor = sum;
}
As well as the .j3md:
MaterialDef HGaussianBlur {
MaterialParameters {
Int NumSamples
Float Scale
Float Size
Texture2D Texture
}
Technique {
VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
FragmentShader GLSL150: Shaders/HGaussianBlur.frag
WorldParameters {
WorldViewProjectionMatrix
}
Defines {
RESOLVE_MS : NumSamples
}
}
Technique {
VertexShader GLSL100: Common/MatDefs/Post/Post.vert
FragmentShader GLSL100: Shaders/HGaussianBlur.frag
WorldParameters {
WorldViewProjectionMatrix
}
}
}
And finally the extends Filter class
[java]
public class CustomBloomFilter extends Filter {
Main main;
private float blurScale = 1.0f;
Material vGBlur, hGBlur;
Pass vGPass = new Pass(), hGPass = new Pass();
float downSamplingFactor = 1;
int screenWidth;
int screenHeight;
public CustomBloomFilter(Main main) {
super("CustomBloomFilter");
this.main = main;
}
@Override
protected Material getMaterial() {
return this.material;
}
@Override
protected void initFilter(final AssetManager manager, final RenderManager renderManager, final ViewPort vp, final int w, final int h) {
screenWidth = (int) Math.max(1, (w / downSamplingFactor));
screenHeight = (int) Math.max(1, (h / downSamplingFactor));
postRenderPasses = new ArrayList<Pass>();
System.out.println(screenWidth + " / " + screenHeight);
hGBlur = new Material(manager, "MatDefs/HGaussianBlur.j3md");
hGPass = new Pass() {
@Override
public boolean requiresSceneAsTexture() {
return true;
}
@Override
public void beforeRender() {
hGBlur.setFloat("Size", 512.0f);
hGBlur.setFloat("Scale", 1.0f);
}
};
hGPass.init(renderManager.getRenderer(), screenWidth, screenHeight, Image.Format.RGBA8, Image.Format.Depth, 1, hGBlur);
postRenderPasses.add(hGPass);
vGBlur = new Material(manager, "MatDefs/VGaussianBlur.j3md");
vGPass = new Pass() {
@Override
public void beforeRender() {
vGBlur.setFloat("Size", 512.0f);
vGBlur.setFloat("Scale", 1.0f);
vGBlur.setTexture("Texture", hGPass.getRenderedTexture());
}
};
vGPass.init(renderManager.getRenderer(), screenWidth, screenHeight, Image.Format.RGBA8, Image.Format.Depth, 1, vGBlur);
postRenderPasses.add(vGPass);
System.out.println(hGBlur.getParam("Size") + " : " + vGBlur.getParam("Scale"));
material = new Material(manager, "MatDefs/BloomFilter.j3md");
material.setTexture("BloomTex", vGPass.getRenderedTexture());
}
}
[/java]
I have set everything down to the variable names to the same as the built in bloom shader (don’t ask me why the variable names are the same, I do weird stuff when debugging) and I honestly can’t figure out what is going wrong. I thought maybe it was something to do with the values I was passing in so I just set them to 1.0 and 512.0, but still nothing.
I certainly don’t expect you to look through all this code and run it, debug it, and just give me correct code, but maybe could you just skim over it or just tell me what you think could be going on?
Thanks, it’s really appreciated