0

我想在运行时制作灰度过滤器我成功通过这段代码制作它

NSString *const kGPUImageLuminanceFragmentShaderString = SHADER_STRING
(
  precision highp float;

   varying vec2 textureCoordinate;

    uniform sampler2D inputImageTexture;

    const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);
   void main()
  {     
   float luminance = dot(texture2D(inputImageTexture, textureCoordinate).rgb, W);
    gl_FragColor = vec4(vec3(luminance), 1.0);
  }
 );

我现在想要的是访问每个点的 rgb 值并将其应用于我的算法,然后根据我的算法更改点 rgb 值

换句话说,我的问题

我想访问一个点的 rgb 值并设置同一点的 rgb 值

4

2 回答 2

1
vec3 pixel =  texture2D(inputImageTexture, textureCoordinate).rgb;
 float red = pixel.r;
 float green = pixel.g;
 float blue = pixel.b;


    .
    . manipulate the values as needed
    .

    gl_FragColor = vec4(red, green, blue, 1.0); 

或者这个来保持原始像素的 alpha:

vec4 pixel =  texture2D(inputImageTexture, textureCoordinate).rgba;
.
.
.

    gl_FragColor = vec4(red, green, blue, pixel.a); 
于 2012-08-23T14:59:38.797 回答
0

如果您的意思是像素,那么我认为您正在寻找的是帧缓冲区对象(FBO)。它将允许您将场景渲染为图像,然后您可以将其反馈到着色器中以执行您想要的任何操作,然后您可以将其渲染为最终输出。

于 2012-08-23T14:55:03.343 回答