Reputation: 865
i want to make gray scale filter on runtime i succeed to make it by this code
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);
}
);
what i want now is to access the rgb values of each point and apply on it my algorithm then change the point rgb values based on my algorithm
my question in other word
i want to access the rgb values of a point and set the rgb values of the same point
Upvotes: 0
Views: 521
Reputation: 13458
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);
OR this to maintain the alpha of the original pixel:
vec4 pixel = texture2D(inputImageTexture, textureCoordinate).rgba;
.
.
.
gl_FragColor = vec4(red, green, blue, pixel.a);
Upvotes: 1
Reputation: 11597
If by point you mean pixel, then I think what you are looking for is a framebuffer object (FBO). It will allow you to render a scene to an image, which then you can feed back into a shader to do whatever you want to it, then you can render that as the final output.
Upvotes: 0