I am using OpenGL es 3.0 and my GLSL version #version 300 es.
I am trying to calculate luminous histogram in GPU. i had identified that my device supports Vertex texture fetch and trying to read color information in vertex shader using texelFetch function.i am using texelFetch because i pass in every texture coordinate so as to read color information at every pixel.
Attaching the code
#version 300 es
uniform sampler2D imageTexture;
in vec2 texturePosition;
const float SCREEN_WIDTH = 1024.0;
in vec4 position;
vec2 texturePos;
out vec3 colorFactor;
const vec3 W = vec3(0.299, 0.587, 0.114);
void main() {
texturePos = texturePosition / SCREEN_WIDTH;
vec3 color = texelFetch(imageTexture, texturePos.xy,0).rgb;
float luminance = dot(color.xyz,W);
colorFactor = vec3(1.0, 1.0, 1.0);
gl_Position = vec4(-1.0 + (luminance * 0.00784313725), 0.0, 0.0, 1.0);
gl_PointSize = 1.0;
};
now getting the error 'texelFetch' : no matching overloaded function found.
Could somebody help with error and provide suggestion to calculate luminous histogram in GPU.
texturePos needs to be an ivec2, with integer texture coordinates (i.e. the pixel position in the texture) rather than normalized [0.0 1.0] floating point coordinates.
The code below should work:
#version 300 es
uniform sampler2D imageTexture;
in ivec2 texturePosition;
in vec4 position;
out vec3 colorFactor;
const vec3 W = vec3(0.299, 0.587, 0.114);
void main() {
vec3 color = texelFetch(imageTexture, texturePosition, 0).rgb;
float luminance = dot(color, W);
colorFactor = vec3(1.0, 1.0, 1.0);
gl_Position = vec4(-1.0 + (luminance * 0.00784313725), 0.0, 0.0, 1.0);
gl_PointSize = 1.0;
};
But you need to feed the 'texturePosition' input array with integers containing all the (x,y) pixel coordinates you want to include in your histogram as integers. (with VBOs).
As pointed out in the comments, you'll need to use glVertexAttribIPointer() to feed integer types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With