I've asked the same question on SO here and they suggested I should ask here instead.
I'm currently trying to create a gaussian blur shader, and while I've successfully created the blur effect my shader only renders the lower right quarter of my screen like the image shows:

Here's my shader code with comments of my thoughts:
Vertex (horizontal, vertical almost identical. See below)
#version 400
in vec2 a_texCoord0; //My tex coords
out vec2 blurTextureCoords[11]; //Sample 11px (i.e, 5 right 5 left of center)
uniform float u_width; //Width of the screen. Used to calculate pixel size
void main(void){
gl_Position = vec4(a_texCoord0, 0.0, 1.0);
vec2 centerTexCoords = a_texCoord0 * 0.5 + 0.5; //Maybe this is somehow wrong?
float pixelSize = 1.0 / u_width; //This is kind of interesting, because my shader sometimes tells me that "no uniform value was found with name 'u_width', but it still seems to work as if I change the values manually (ex. set it to 1920) it still looks normal.
for(int i=-5; i<=5; i++) {
blurTextureCoords[i+5] = centerTexCoords + vec2(pixelSize * i, 0.0); //I also thought that it might be because I multiply a float with an integer, but if I do float(i) instead of just i it still looks the same.
}
}
Fragment
#version 400
#ifdef GL_ES
precision mediump float;
#endif
in vec2 blurTextureCoords[11];
out vec4 out_colour;
uniform sampler2D u_texture;
void main(void){
//The actual bluring
out_colour = vec4(0.0);
out_colour += texture(u_texture, blurTextureCoords[0]) * 0.0093;
out_colour += texture(u_texture, blurTextureCoords[1]) * 0.028002;
out_colour += texture(u_texture, blurTextureCoords[2]) * 0.065984;
out_colour += texture(u_texture, blurTextureCoords[3]) * 0.121703;
out_colour += texture(u_texture, blurTextureCoords[4]) * 0.175713;
out_colour += texture(u_texture, blurTextureCoords[5]) * 0.198596;
out_colour += texture(u_texture, blurTextureCoords[6]) * 0.175713;
out_colour += texture(u_texture, blurTextureCoords[7]) * 0.121703;
out_colour += texture(u_texture, blurTextureCoords[8]) * 0.065984;
out_colour += texture(u_texture, blurTextureCoords[9]) * 0.028002;
out_colour += texture(u_texture, blurTextureCoords[10]) * 0.0093;
}
Additional code
Creating a shader:
//I also have one for the vertical shader, it's almost exactly the same.
horizontalShader = new ShaderProgram(
Gdx.files.internal("graphics/shaders/post-processing/blur/horizontalBlur.vert"),
Gdx.files.internal("graphics/shaders/post-processing/blur/blur.frag"));
horizontalShader.pedantic = false;
horizontalShader.begin();
horizontalShader.setUniformf("u_width", Gdx.graphics.getWidth());
horizontalShader.end();
if (horizontalShader.getLog().length() != 0) {
System.out.println("Horizontal shader! \n" + horizontalShader.getLog());
}
Rendering to FBO then to screen:
// Horozontal blur
horizontalFBO.begin();
spriteBatch.begin();
spriteBatch.setShader(horizontalShader);
background_image.draw(spriteBatch);
spriteBatch.end();
horizontalFBO.end();
// Vertical blur
verticalFBO.begin();
spriteBatch.begin();
spriteBatch.setShader(verticalShader);
spriteBatch.draw(horizontalFBO.getColorBufferTexture(), 0, 0);
spriteBatch.end();
verticalFBO.end();
// Normal FBO (screen)
spriteBatch.begin();
spriteBatch.setShader(null);
spriteBatch.draw(verticalFBO.getColorBufferTexture(), 0, 0);
spriteBatch.end();
Additional info
I use two FBOs, but it seems that those are not the root of the problem, as the problem still persists if I just render directly to the screen using these shaders.
I have two vertex shaders, one for the horizontal and one for the vertical blur. The only difference is the uniform name u_width
becomes u_height
and the blurTextureCoords[i+5] = centerTexCoords + vec2(pixelSize * i, 0.0);
becomes blurTextureCoords[i+5] = centerTexCoords + vec2(0.0, pixelSize * i);