Hi,
I want to be able to calculate the direction of a line to eye coordinates and store this value for every pixel on the line using a vertex and fragment shader. My idea was to calculate the direction gradient using atan2(Gy/Gx) after a modelview tranformation for each pair of vertices then quantize this value as a color intensity to pass to a fragment shader. How can I get access to the positions of pairs of vertices to achieve this or is there another method I should use?
Thanks
views:
101answers:
1
+1
A:
How can I get access to the positions of pairs of vertices?
You can't do that simply if you are just using a vertex and a fragment shader. Easy way is to use geometry shaders. Inside this shader stage you can have access to the pair of vertices that compose your line segment. Then it's straightforward to determine the line orientation and pass it to the fragment shader.
If geometry shader is not an option (because of your target audience) you could duplicate your geometry (storing in each vertex the actual vertex plus the next vertex) and then do the computation in the vertex shader.
Stringer Bell
2010-04-01 21:47:41
Sorry should have said using OpenGL 2.1 so no access to geometry shaders. I understand that I could pass the next vertex to the shader but how do I determine the current vertex being rendered. I currently use the drawElements function. Would I need to do something like list all vertices using glVertex3f after a glBegin(GL_QUADS), then after each call passing a uniform vec3 with the next vertex position?
Brett
2010-04-02 10:58:22