Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top