【问题标题】:Blur frame buffer content模糊帧缓冲区内容
【发布时间】:2015-06-18 09:15:20
【问题描述】:

我可以不模糊纹理而是模糊帧缓冲区吗?以下着色器模糊了纹理:

#ifdef GL_ES
precision mediump float;
#endif

varying vec4 v_fragmentColor;
varying vec2 v_texCoord;

uniform vec2 resolution;
uniform float blurRadius;
uniform float sampleNum;

vec3 blur(vec2);

void main(void)
{
    vec3 col = blur(v_texCoord);
    gl_FragColor = vec4(col, 1.0) * v_fragmentColor;
}

vec3 blur(vec2 p)
{
    if (blurRadius > 0.0 && sampleNum > 1.0)
    {
        vec3 col = vec3(0);
        vec2 unit = 1.0 / resolution.xy;

        float r = blurRadius;
        float sampleStep = r / sampleNum;

        float count = 0.0;

        for(float x = -r; x < r; x += sampleStep)
        {
            for(float y = -r; y < r; y += sampleStep)
            {
                float weight = (r - abs(x)) * (r - abs(y));
                col += texture2D(CC_Texture0, p + vec2(x * unit.x, y * unit.y)).rgb * weight;
                count += weight;
            }
        }

        return col / count;
    }

    return texture2D(CC_Texture0, p).rgb;
}

我怎样才能不模糊纹理像素,而是已经绘制的帧缓冲区像素?

【问题讨论】:

  • 您必须将帧缓冲区复制到纹理并对其进行模糊处理。附带说明一下,那里的 2D 内核非常昂贵。您可以使用高斯权重将其拆分为单独的水平和垂直操作(尽管其他函数也是可分离的)。我找到的第一个链接是this
  • 我知道这个着色器很糟糕。没有权重预计算,复杂度为O(n^2) 而不是O(n)。但是为什么我必须将帧缓冲区复制到纹理@jozxyqk?
  • 据我所知,因为您无法从着色器中读取默认的片段缓冲区。
  • @jozxyqk 我已经检查过了,因为 GPU 可以并行处理多个像素:gamedev.stackexchange.com/questions/10964/…

标签: opengl-es opengl-es-2.0 blur


【解决方案1】:

您可以将该模糊着色器应用于已附加到帧缓冲区的纹理,因为帧缓冲区的绘图会将像素数据写入选定的颜色附件。

This page 提供了一种方法信息,该方法可以通过使用着色器将帧缓冲区颜色附件绘制到屏幕上来完成。虽然它在 opengl 3.3 中,但所有使用的函数都应该存在于 opengl es 2.0 中。

【讨论】:

    猜你喜欢
    • 2013-02-27
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 2012-04-26
    • 2023-03-07
    • 2014-06-26
    相关资源
    最近更新 更多