Wireframe shader - a problem with barycentric coordinates when using common vertices

I am working on landscape painting in WebGL. The problem is that I use only 4 vertices to draw one quad using indexes to exchange vertices. Therefore, I cannot load unique barycentric coordinates for each vertex because it was split.

Here is an image that shows the problem more clearly.

enter image description here

There is no barycentric coordinate that I can use for a question mark. (0,1,0) the upper left is used, (0,0,1) is used above and (1,0,0) is used on the left. Therefore, I absolutely can not do this when I use indexes to save the number of vertices.

, 6? , . , .

, GL_LINES, , (, ).

, , :

http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/

, , :

  • , , 6 4? , , .
  • 4 , ?

!

+2
3

, , . , . 2 :

0,2----1,2----2,2----3,2----4,2
 |      |      |      |      |
 |      |      |      |      |
 |      |      |      |      |
0,1----1,1----2,1----3,1----4,1
 |      |      |      |      |
 |      |      |      |      |
 |      |      |      |      |
0,0----1,0----2,0----3,0----4,0

, 4 .

, .

, , 0, 1, . , : vQC vBC :

varying vec2 vQC;
...
void main() {
    vec2 vRel = fract(vQC);
    if (any(lessThan(vec4(vRel, 1.0 - vRel), vec4(0.02)))) {
        gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
    } else {
        gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0);
    }
}
+3

, , . ( 4x), , , - .

enter image description here

+1

(100, 010 001). HTO ( , , - ). :

O H T O H
T O H T O
H T O H T
O H T O H
T O H T O

, , , , "" , . , , , ( , , Os TOH-THO ).

, , . , :

verts = [ A B C D E F ];
barycentric = [ T O H O H T ];
indices = [ 0 1 4 0 4 3 1 2 5 1 5 4 ];

:

barycentricTiles = [[1,0,0],[0,1,0],[0,0,1]];
// looping where i, j are indexes for each point on your mesh from 0,0 to m,n
barycentric.push(barycentricTiles[ (i+j)%3 ]);

I spent some time last week figuring this out, so I decided to pass it on. Excuse me for three years now!

+1
source

All Articles