Let’s assume that I have a triangle with coordinates x,y,z=0,0,0 x,y,z=1,0,0 x,y,z=0.5,1,0
I would like to achieve efect in which one half of the triangle is ( for example red ) and second blue. I ask for the code (in GLSL) in which I will be able to change
colour of the pixel depending on coordinates of the triangle.
You can give each Vertex a 1D ‘texture coordinate’ (0.0, 0.5 and 1.0) and color in the fragmentshader dependent on that value (provided by the VS as a varying):
in float texCoord;
out vec3 color;
void main() {
if (texCoord > 0.5) {
color = vec3(1.0, 0.0, 0.0);
} else {
color = vec3(0.0, 0.0, 1.0);
}
}