0

我有以下片段着色器:

varying highp vec2 coordinate;
precision mediump float;

uniform vec4 maskC;
uniform float threshold;
uniform sampler2D videoframe;
uniform sampler2D videosprite;
uniform vec4 mask;
uniform vec4 maskB;


uniform int recording;

vec3 normalize(vec3 color, float meanr)
{
    return color*vec3(0.75 + meanr, 1., 1. - meanr);
}

void main() {
    float d;
    float dB;
    float dC;

    float meanr;
    float meanrB;
    float meanrC;

    float minD;

    vec4 pixelColor;
    vec4 spriteColor;

    pixelColor = texture2D(videoframe, coordinate);
    spriteColor = texture2D(videosprite, coordinate);

    meanr   = (pixelColor.r + mask.r)/8.;
    meanrB  = (pixelColor.r + maskB.r)/8.;
    meanrC  = (pixelColor.r + maskC.r)/8.;

    d   = distance(normalize(pixelColor.rgb, meanr), normalize(mask.rgb, meanr));
    dB  = distance(normalize(pixelColor.rgb, meanrB), normalize(maskB.rgb, meanrB));
    dC  = distance(normalize(pixelColor.rgb, meanrC), normalize(maskC.rgb, meanrC));

    minD = min(d, dB);
    minD = min(minD, dC);

    gl_FragColor = spriteColor;
    if (minD > threshold) {
        gl_FragColor = pixelColor;
    }

}

现在,根据recording是 0 还是 1,我想旋转uniform sampler2D videosprite180 度(在 x 轴上反射,垂直翻转)。我怎样才能做到这一点?

我找到了函数 glRotatef(),但是如何指定要旋转videosprite而不是旋转videoframe

4

1 回答 1

2

呃,你不能只修改videosprite片段着色器中的访问方式吗?

vec2 c2;
if(recording == 0) {
    c2 = coordinate;
} else {
    c2 = vec2(coordinate.x, 1.0 - coordinate.y);
}
于 2012-04-07T17:28:51.397 回答