OK二维网格所以我有,我已经决定了使用三角形一个真正的大广场(网格),然后应用高度图撞它。现在我试图做的是获取网格线。我已经找到了一种方法来做到这一点,但是这会导致在片段着色器中为33个if语句只为x,然后在另一个33中为y。我被告知我可以使用现在正在做的事情,并且稍微不同地使用它(使用一些GLSL函数),只需要1或2条if语句。这是我当前的代码(不是全部做完,但给你的是什么即时通讯做的想法。)创建使用OpenGL和顶点和片段着色器
#version 330
uniform sampler2D texture;
in vec2 texCoord;
layout (location=0) out vec4 fragColour;
void main(void) {
vec4 newColor;
vec2 line = texCoord * 32; // makes texCoords easier to number (as divided by 32 in the C++array)
if(line.x > 0 && line.x < 0.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 1 && line.x < 1.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 2 && line.x < 2.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 3 && line.x < 3.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 4 && line.x < 4.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 5 && line.x < 5.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 6 && line.x < 6.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 7 && line.x < 7.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 8 && line.x < 8.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 9 && line.x < 9.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 10 && line.x < 10.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 11 && line.x < 11.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 12 && line.x < 12.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 13 && line.x < 13.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 14 && line.x < 14.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 15 && line.x < 15.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 16 && line.x < 16.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 17 && line.x < 17.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 18 && line.x < 18.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 19 && line.x < 19.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 20 && line.x < 20.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 21 && line.x < 21.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 22 && line.x < 22.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 23 && line.x < 23.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 24 && line.x < 24.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else
{
newColor = vec4(0.0,0.0,0.0,1.0);
}
fragColour = newColor;
}
您可能想要使用discard()函数 –
@Mike:仅供参考,您不需要编辑问题以将* answers *添加到它们中。回答下面,问题在上面。你接受了一个答案,这意味着这个问题得到了满意答复。你不需要将他的解决方案放在你的问题上,因为那样会使人们疑惑开始时的问题。 –
那么这只是浪费创建一个新的线程到相关的问题,但它现在无论如何 –