2
votes

New to Opengl and GLSL.

I am using OpenGL es 3.0 and my GLSL version #version 300 es.

i want to get pixel(ARGB data) at every position in my vertex shader(vertex texture fetch). i have verified that my Android tablet supports vertex texture fetch.

Now i pass in the texture(image) and Texture coordinates to the vertex shader and execute

GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);

Is this the right way or should i use GL_POINTS . if i am using GL_POINTS how to pass the texture cooordinate?

could you provide any samples/example code that does a full pixel read(ARGB) in the vertex shader.

attaching my vertex shader

uniform sampler2D sTexture; 
in vec4 aTextureCoord;
out vec3 colorFactor;
vec2 vTextureCoord;
vec4 tex;
void main() 
{
   vTextureCoord = aTextureCoord.xy;
   tex =  texture(sTexture,vTextureCoord);
   float luminance = 0.299 * tex.r + 0.587 * tex.g + 0.114 * tex.b;
   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;
};

My texture coordinates passed are {0.f,1.f}
{1.f,1.f} {0.f,0.f} {1.f,0.f}

and the shader is triggered by

GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
2

2 Answers

0
votes

Just declare a sampler and sample it exactly as per usual. E.g.

"#version 150\n"

in vec4 position;
in vec2 texCoordinate;

uniform sampler2D texID;
uniform mat4 modelViewProjection;

void main()
{
    gl_Position = modelViewProjection * (position + texture(texID, texCoordinate));
}

That will sample a 4d vector from the texture unit texID at location texCoordinate, using that to perturb position prior to applying the model-view-projection matrix. The type of geometry you're drawing makes no difference.

-1
votes

gl_Position = vec4(-1.0 + (luminance * 0.00784313725), 0.0, 0.0, 1.0);

That's clever. It's not going to work, but that's clever.

The thing that is confusing everyone is what you haven't told us. That you're computing the histogram by using blending. That you compute the location for each fragment based on the luminance, so you get lots of overlap. And blending just adds everything together, thus producing your histogram.

FYI: It's always best to explain what it is you're actually trying to accomplish in your question, rather than hoping that someone can deduce what you're attempting to do.

That's not going to work because you only have four vertices in this case. You have lots of fragments, but they will be generated based on interpolation from your 4 vertices. And you can't change the position of a fragment from within a fragment shader.

If you want to do what you're trying to do, you still have to render one vertex for every texel you fetch. You still need to use GL_POINTS.