【问题标题】:RGB to YUV using shader使用着色器将 RGB 转为 YUV
【发布时间】:2015-10-26 06:45:37
【问题描述】:

我想使用片段着色器通过着色器将 RGB 转换为 YUV420P。

1,我算出了当前纹理颜色的坐标。

2,我计算了4个Y,放在当前颜色上。

我的代码:

    precision mediump float;
    varying vec2 vTextureCoord;
    uniform sampler2D tex;
    uniform float width;
    uniform float height;
    uniform float offset;
    uniform vec3 scal;

    void main(void) {
        vec2 nowTxtPos = vTextureCoord;
        vec2 size = vec2(width, height);
    // y
        if(nowTxtPos.y<0.25){
    // y1 postion
            vec2 now_pos = nowTxtPos * size;
            vec2 basePos = now_pos * vec2(4.0,4.0);
            float addY = float(int(basePos.x / width));
            basePos.x = basePos.x - addY * width;
            basePos.y += addY;

            float y1,y2,y3,y4;
            vec2 samplingPos = basePos / size;
            vec4 texel = texture2D(tex, samplingPos);
            y1 = dot(texel.rgb, scal);
            y1 += offset;

            basePos.x+=1.0;
            samplingPos = basePos/size;
            texel = texture2D(tex, samplingPos);
            y2 = dot(texel.rgb, scal);
            y2 += offset;

            basePos.x+=1.0;
            samplingPos = basePos/size;
            texel = texture2D(tex, samplingPos);
            y3 = dot(texel.rgb, scal);
            y3 += offset;

            basePos.x+=1.0;
            samplingPos = basePos/size;
            texel = texture2D(tex, samplingPos);
            y4 = dot(texel.rgb, scal);
            y4 += offset;

            gl_FragColor = vec4(y1, y2, y3, y4);
        }
    }

图片(YUV420P):

picture

Enlarged post picture

它有别名。 我不知道为什么。

【问题讨论】:

    标签: opengl glsl shader rgb yuv


    【解决方案1】:

    我已经解决了。 因为计算精度不够。

    在这里编辑:

    "精度中等p浮点数;" -> "精度高浮点;"

    【讨论】:

      猜你喜欢
      • 2014-02-25
      • 2019-09-19
      • 2019-12-12
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多