Defining line orientation using vertex shaders

I want to be able to calculate the direction of the line coordinates in the eye and save this value for each pixel on the line using the vertex and fragment shader. My idea was to calculate the direction gradient using atan2 (Gy / Gx) after transforming the model for each pair of vertices, then quantize this value as the color intensity to go to the fragment shader. How can I access the positions of vertex pairs to achieve this, or is there another method I should use?
Thanks

+3
source share
1 answer

How can I access the positions of pairs of vertices?

You cannot do this simply if you just use the vertex and fragment shader. A simple way is to use geometric shaders . Inside this shader stage, you can access the pair of vertices that make up your line segment. Then just determine the line orientation and pass it to the fragment shader.

If the geometric shader is not an option (because of your target audience), you can duplicate the geometry (keeping at each vertex the actual vertex plus the next vertex), and then perform the calculations in the vertex shader.

+1
source

Source: https://habr.com/ru/post/1739452/


All Articles