Opengl 着色器仅渲染屏幕的1/4

Opengl 着色器仅渲染屏幕的1/4,opengl,libgdx,glsl,shader,Opengl,Libgdx,Glsl,Shader,我目前正在尝试创建一个高斯模糊着色器,虽然我已经成功创建了模糊效果,但我的着色器只渲染屏幕右下角的部分,如图所示:只是为了清楚起见;它没有重新缩放图像,只是不渲染图像的其余部分 以下是我的着色器代码和我的想法: 顶点(水平、垂直几乎相同。见下文) 附加代码 创建着色器: //I also have one for the vertical shader, it's almost exactly the same. horizontalShader = new ShaderProgram(

我目前正在尝试创建一个高斯模糊着色器,虽然我已经成功创建了模糊效果,但我的着色器只渲染屏幕右下角的部分,如图所示:只是为了清楚起见;它没有重新缩放图像,只是不渲染图像的其余部分

以下是我的着色器代码和我的想法:

顶点(水平、垂直几乎相同。见下文) 附加代码 创建着色器:

//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());
}
渲染到FBO,然后渲染到屏幕:

// 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();
附加信息 我使用了两个FBO,但这些似乎不是问题的根源,因为如果我使用这些着色器直接渲染到屏幕上,问题仍然存在


我有两个顶点着色器,一个用于水平方向,一个用于垂直方向的模糊。唯一的区别是统一名称
u_宽度
变为
u_高度
,而
blurTextureCoords[i+5]=centerTexCoords+vec2(像素大小*i,0.0)变为
模糊纹理单词[i+5]=centerTexCoords+vec2(0.0,像素大小*i)

您能提供主机代码吗?@Xirema您是指我在程序中创建和设置着色器的位置吗?是的,还有设置属性和制服的代码。我们需要能够验证数据是否正确。@Xirema补充道。看我的编辑。不知道你为什么会被否决,看起来是个好问题。也就是说,我发现我在电脑上使用3D图形运气更好。如果你在这里找不到答案,可能值得在那里询问。你能提供主机代码吗?@Xirema你是说我在程序中创建和设置着色器的位置吗?是的,还有设置属性和制服的代码。我们需要能够验证数据是否正确。@Xirema补充道。看我的编辑。不知道你为什么会被否决,看起来是个好问题。也就是说,我发现我在电脑上使用3D图形运气更好。如果你在这里找不到答案,也许值得在那里问一下。
//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());
}
// 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();