【问题标题】:libgdx heighmap shader distortion artefactlibgdx heighmap 着色器失真伪影
【发布时间】:2014-11-08 18:07:46
【问题描述】:

目前正在制作游戏,我想添加漂亮的着色器效果,例如水扭曲。 我将场景渲染到 FBO,然后在其上应用高度图失真着色器。 失真由片段着色器应用。 normalMapPosition 是法线贴图当前位置的颜色向量。

vec2 normalCoord = v_texCoord0;
vec4 normalMapPosition = 2 * texture2D(u_normals, v_texCoord0);
vec2 distortedCoord = normalCoord + (normalMapPosition.xz * 0.05);

然后将其渲染到屏幕上,我得到以下结果

问题是有一个对角线伪影穿过整个图像。 我认为这是由于openGL将纹理处理为两个三角形。 有没有很好的方法来处理这类问题?

【问题讨论】:

    标签: opengl libgdx shader


    【解决方案1】:

    我终于找到了解决方案,问题来自于使用相同的 FBO 来绘制场景然后渲染着色器,如下所示:

    batch.setShader(waterfallShaderProgram)
    fbo.begin();
    batch.begin();
    // here is the problem, fbo is started and used to 
    // draw at the same time
    batch.draw(fbo.getColorBufferTexture());
    batch.end()
    fbo.end();
    

    场景被渲染到 FBO fbo 以便在顶部应用其他效果。 引入新的 FBO fbo2 解决了这个问题。

    batch.setShader(waterfallShaderProgram)
    fbo2.begin();
    batch.begin();
    batch.draw(fbo.getColorBufferTexture());
    batch.end()
    fbo2.end();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-10
      • 1970-01-01
      • 2018-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多