简体   繁体   English

使用顶点着色器确定线方向

[英]Determining line orientation using vertex shaders

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. 我的想法是在每对顶点的模型视图变换之后使用atan2(Gy / Gx)计算方向梯度,然后将该值量化为颜色强度以传递到片段着色器。 How can I get access to the positions of pairs of vertices to achieve this or is there another method I should use? 如何才能访问顶点对的位置来实现这一目标,还是应该使用另一种方法?
Thanks 谢谢

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. 如果几何着色器不是一个选项(因为您的目标受众),您可以复制几何体(在每个顶点存储实际顶点加上下一个顶点),然后在顶点着色器中进行计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM