资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

基于Qt的OpenGL可编程管线学习(11)-高斯模糊-创新互联

下图是使用高斯模糊和未使用高斯模糊的效果图对比

创新互联建站主要从事成都网站建设、网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务东兴,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792

正常图片

基于Qt的OpenGL可编程管线学习(11)- 高斯模糊

高斯模糊后

基于Qt的OpenGL可编程管线学习(11)- 高斯模糊

1、标准高斯模糊

原理:

每个像素周围对应的像素乘以对应的算子,然后除以算子的综合

算子为

1 2 1
2 4 2
1 2 1

fragment shader

varying vec2 M_coord;
varying vec3 M_normal;
varying vec3 M_WordPos;

uniform sampler2D U_MainTexture;
uniform sampler2D U_SubTexture;

void main()
{
    // 1 2 1
    // 2 4 2
    // 1 2 1
    int coreSize=3;
    int halfCoreSize=coreSize/2;
    float texelOffset=1/100.0;
    vec4 color = vec4(1.0);
    float nGaussionCore[9] = float[](1.0, 2.0, 1.0, 2.0, 4.0, 2.0, 6.0, 2.0, 1.0);

    int index = 0;
    for(int y=0;y

2、横向模糊

与高斯模糊类似 不过只是模糊横向分量

// 水平高斯模糊
varying vec2 M_coord;
varying vec3 M_normal;
varying vec3 M_WordPos;

uniform sampler2D U_MainTexture;
uniform sampler2D U_SubTexture;

void main()
{
    int coreSize=3;
    int halfCoreSize=coreSize/2;
    float texelOffset=1/100.0;
    vec4 color = vec4(0.0);
    float nGaussionCore[5] = float[](0.22, 0.19, 0.12, 0.08, 0.01);

    color = texture2D(U_MainTexture, M_coord) * nGaussionCore[0];
    for (int i=1; i<5; ++i)
    {
        color += texture2D(U_MainTexture, vec2(M_coord.x + i * texelOffset, M_coord.y))
                 * nGaussionCore[i];
        color += texture2D(U_MainTexture, vec2(M_coord.x + i * texelOffset, M_coord.y))
                 * nGaussionCore[i];
    }

    gl_FragColor=color ;
}

3、纵向模糊

与高斯模糊类似 不过只是模糊纵向分量

varying vec2 M_coord;
varying vec3 M_normal;
varying vec3 M_WordPos;

uniform sampler2D U_MainTexture;
uniform sampler2D U_SubTexture;

void main()
{
    int coreSize=3;
    int halfCoreSize=coreSize/2;
    float texelOffset=1/100.0;
    vec4 color = vec4(0.0);
    float nGaussionCore[5] = float[](0.22, 0.19, 0.12, 0.08, 0.01);

    color = texture2D(U_MainTexture, M_coord) * nGaussionCore[0];
    for (int i=1; i<5; ++i)
    {
        color += texture2D(U_MainTexture, vec2(M_coord.x, i * texelOffset + M_coord.y))
                 * nGaussionCore[i];
        color += texture2D(U_MainTexture, vec2(M_coord.x, i * texelOffset + M_coord.y))
                 * nGaussionCore[i];
    }

    gl_FragColor=color ;
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享文章:基于Qt的OpenGL可编程管线学习(11)-高斯模糊-创新互联
文章位置:http://cdkjz.cn/article/poood.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220