Skip to content

Instantly share code, notes, and snippets.

@paulhoux
Created March 16, 2014 13:36
Show Gist options
  • Save paulhoux/9583347 to your computer and use it in GitHub Desktop.
Save paulhoux/9583347 to your computer and use it in GitHub Desktop.
#version 150
uniform sampler2D uTexture;
in VertexData {
vec3 baricentric;
vec4 color;
vec2 texcoord;
} vVertexIn;
out vec4 oColor;
float edgeFactor()
{
vec3 d = fwidth( vVertexIn.baricentric );
vec3 a3 = smoothstep( vec3(0.0), d * 1.5, vVertexIn.baricentric );
return min(min(a3.x, a3.y), a3.z);
}
void main(void) {
// determine frag distance to closest edge
float fEdgeIntensity = 1.0 - edgeFactor();
// blend between edge color and face color
vec4 vFaceColor = texture( uTexture, vVertexIn.texcoord ) * vVertexIn.color; vFaceColor.a = 0.85;
vec4 vEdgeColor = vec4(1.0, 1.0, 1.0, 0.85);
oColor = mix(vFaceColor, vEdgeColor, fEdgeIntensity);
}
#version 150
layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;
in VertexData {
vec4 color;
vec2 texcoord;
} vVertexIn[];
out VertexData {
vec3 baricentric;
vec4 color;
vec2 texcoord;
} vVertexOut;
void main(void)
{
vVertexOut.baricentric = vec3(1, 0, 0);
vVertexOut.color = vVertexIn[0].color;
vVertexOut.texcoord = vVertexIn[0].texcoord;
gl_Position = gl_in[0].gl_Position;
EmitVertex();
vVertexOut.baricentric = vec3(0, 1, 0);
vVertexOut.color = vVertexIn[1].color;
vVertexOut.texcoord = vVertexIn[1].texcoord;
gl_Position = gl_in[1].gl_Position;
EmitVertex();
vVertexOut.baricentric = vec3(0, 0, 1);
vVertexOut.color = vVertexIn[2].color;
vVertexOut.texcoord = vVertexIn[2].texcoord;
gl_Position = gl_in[2].gl_Position;
EmitVertex();
EndPrimitive();
}
#version 150
uniform mat4 ciModelViewProjection;
in vec4 ciPosition;
in vec4 ciColor;
in vec2 ciTexCoord0
out VertexData {
vec4 color;
vec2 texcoord;
} vVertexOut;
void main(void) {
vVertexOut.color = ciColor;
vVertexOut.texcoord = ciTexCoord0;
gl_Position = ciModelViewProjection * ciPosition;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment