Created
April 3, 2014 11:01
-
-
Save dougbinks/9952415 to your computer and use it in GitHub Desktop.
Revisions
-
dougbinks created this gist
Apr 3, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ One way to generate barycentric coordinates from a vertex stream is to use gl_VertexID. This requires that your vertices are ordered in the vertex buffer in a regular fashion as gl_VertexID is the vertex position in the buffer, so vertex optimization using an index buffer will likely break this. Step 1 is to generate a vec3 in the vertex shader: //VS out vec3 ex_BarycentricCoords; void main(void) { //your usual code vec3 bary; int i = gl_VertexID % 3; bary.x = float(i == 0); bary.y = float(i == 1); bary.z = float(i == 2); ex_BarycentricCoords = bary; } Step 2 is to use these to get outlining in the fs: //FS in vex3 ex_BarycentricCoords; out vec4 fragColor; void main(void) { vec3 line = 10.0 * (0.1 - clamp( ex_BarycentricCoords, 0.0, 0.1 )); fragColor = vec4(line,1.0); } Step 3 would be to get anti-aliasing by using derivatives (to come...).