さて、三角形を使用して作成した非常に大きな正方形(グリッド)があり、高さマップを適用してバンプしました。今やろうとしているのは、グリッド線を取得することです。これを行う方法を考え出しましたが、これにより、フラグメントシェーダーのステートメントがxに対して33 ifになり、yに対してさらに33になります。私は今やっていることを使用して、それを少し異なる方法で(いくつかのGLSL関数を使用して)実装して、1つまたは2つのifステートメントだけを必要とすることができると言われました。これは私の現在のコードです(すべてが完成しているわけではありませんが、imが何をしているのかがわかります)。
#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;
}