OpenGL Triangle Gradient

I am trying to make a triangle as shown in the image below:

triangles

The problem is that I want to achieve a color gradient from vertices 1 and 2 derived from C.

As far as I know, this is impossible, since the vertex C must have its own color, which will also mix with 1 and 2 colors, as in the left triangle of the image. If I set C to the color of the midpoint, this produces an undesirable result, since the higher the triangle, the less noticeable are the other colors of the vertices.

Line C1 must be black and line C2 must be white.

Is there a way to achieve this in OpenGL?

+5
source share
1 answer

There are two ways, but I do not know what makes sense for your application. At a very high level:

  • . , , .

  • . , "" /.


: , :

varying vec2 coords . 1 0,0, 2 - 1,0, C - 0,1. , attribute. , . , coords :

y
1 +-----+
  |\    |
  |#\   |
  |##\  |
  |###\ |
  |####\|
0 +-----+ x
  0     1

coords - . , , coords 0,1 x. coords : coords.x coords.y. f. ( , C, , . , .)

coords c ., f - 0 1:

y
1 +-----+
  |\    |
  |.\   |
  |#c\  |
  |#.#\ |
  |##.#\|
0 +--f--+ x
  0     1

, uniform vec4 colour1 uniform vec4 colour2, 1 2 . : f colour2 1-f colour1 . GLSL mix .

+6

All Articles