Commit df1966be authored by Christopher Tenter's avatar Christopher Tenter

unified edge rendering for triangle and poly meshes refs #2029

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18323 383ad7c9-94d9-4d36-a494-682f7c89f535
parent c6fe72c0
// template file for shader generator // hiddenline shader for tri meshes
in vec3 outGeometryBary; in float outGeometryHidden;
uniform float lineWidth;
uniform vec4 bkColor; uniform vec4 bkColor;
float edgeFactor()
{
// compute smoothed distance to edge, source:
// http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/
vec3 d = fwidth(outGeometryBary);
vec3 a3 = smoothstep(vec3(0.0), d*lineWidth, outGeometryBary);
return min(min(a3.x, a3.y), a3.z);
}
void main() void main()
{ {
SG_FRAGMENT_BEGIN SG_FRAGMENT_BEGIN
sg_cColor.xyz = mix(bkColor.xyz, sg_cColor.xyz, 1-edgeFactor()); sg_cColor.xyz = mix(sg_cColor.xyz, bkColor.xyz, outGeometryHidden);
SG_FRAGMENT_END SG_FRAGMENT_END
} }
\ No newline at end of file
// template file for shader generator
in vec3 outGeometryBary;
uniform float lineWidth;
uniform vec4 bkColor;
float edgeFactor()
{
// compute smoothed distance to edge, source:
// http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/
vec3 d = fwidth(outGeometryBary);
vec3 a3 = smoothstep(vec3(0.0), d*lineWidth, outGeometryBary);
return min(min(a3.x, a3.y), a3.z);
}
void main()
{
SG_FRAGMENT_BEGIN
sg_cColor.xyz = mix(bkColor, sg_cColor.xyz, 1-edgeFactor());
SG_FRAGMENT_END
}
\ No newline at end of file
// template file for shader generator // template file for shader generator
in vec3 outGeometryBary;
uniform float lineWidth;
float edgeFactor()
{
// compute smoothed distance to edge, source:
// http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/
vec3 d = fwidth(outGeometryBary);
vec3 a3 = smoothstep(vec3(0.0), d*lineWidth, outGeometryBary);
return min(min(a3.x, a3.y), a3.z);
}
void main() void main()
{ {
SG_FRAGMENT_BEGIN SG_FRAGMENT_BEGIN
float t = 1-edgeFactor();
// use alpha blending to fade out
sg_cColor.a = t;
// without alpha blending:
// sg_cColor.xyz *= t; //mix(vec3(0.0), sg_cColor.xyz, t);
// discard pixels inside face
if (t < 0.1)
discard;
SG_FRAGMENT_END SG_FRAGMENT_END
} }
\ No newline at end of file
...@@ -26,9 +26,14 @@ void main() ...@@ -26,9 +26,14 @@ void main()
// without alpha blending: // without alpha blending:
// sg_cColor.xyz *= t; //mix(vec3(0.0), sg_cColor.xyz, t); // sg_cColor.xyz *= t; //mix(vec3(0.0), sg_cColor.xyz, t);
gl_FragDepth = gl_FragCoord.z;
// discard pixels inside face // discard pixels inside face
if (t < 0.1) if (t < 0.1)
discard; {
gl_FragDepth = 1.0;
SG_FRAGMENT_END // discard; // depth write after discard might depend on gpu driver
}
SG_FRAGMENT_END
} }
\ No newline at end of file
// template file for shader generator // hiddenline shader for tri meshes
// emits screen quads for edges
// emits hidden triangle to update depth buffer
#include "createEdgeQuad.glsl"
layout(triangles) in; layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out; layout(triangle_strip, max_vertices = 15) out;
uniform float lineWidth;
uniform vec2 screenSize;
// send barycentric coords to fragment out float outGeometryHidden;
out vec3 outGeometryBary;
void main() void main()
{ {
// draw hidden triangle with background color
outGeometryHidden = 1.0;
sg_MapIO(0); // IO mapping provided by ShaderGen, send vertex 0 sg_MapIO(0);
outGeometryBary = vec3(1, 0, 0);
EmitVertex(); EmitVertex();
sg_MapIO(1);
sg_MapIO(1); // IO mapping provided by ShaderGen, send vertex 1
outGeometryBary = vec3(0, 1, 0);
EmitVertex(); EmitVertex();
sg_MapIO(2);
sg_MapIO(2); // IO mapping provided by ShaderGen, send vertex 2
outGeometryBary = vec3(0, 0, 1);
EmitVertex(); EmitVertex();
EndPrimitive(); EndPrimitive();
// draw edges
outGeometryHidden = 0.0;
createEdgeQuad(0,1, screenSize, lineWidth);
createEdgeQuad(1,2, screenSize, lineWidth);
createEdgeQuad(2,0, screenSize, lineWidth);
} }
\ No newline at end of file
// modified hiddenline shader that works for n-poly faces // modified hiddenline shader that works for n-poly faces
#include "createEdgeQuad.glsl"
layout(triangles) in; layout(triangles) in;
layout(triangle_strip, max_vertices = 15) out; layout(triangle_strip, max_vertices = 15) out;
...@@ -12,8 +14,6 @@ uniform vec2 screenSize; ...@@ -12,8 +14,6 @@ uniform vec2 screenSize;
out float outGeometryHidden; out float outGeometryHidden;
#include "createEdgeQuad.glsl"
void main() void main()
{ {
int polyEdge = int(texelFetch(polyEdgeBuffer, gl_PrimitiveIDIn/2).x); int polyEdge = int(texelFetch(polyEdgeBuffer, gl_PrimitiveIDIn/2).x);
......
// template file for shader generator // wireframe shader for tri meshes
// emits screen quads for edges
layout(triangles) in; layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out; layout(triangle_strip, max_vertices = 12) out;
// send barycentric coords to fragment uniform float lineWidth;
out vec3 outGeometryBary; uniform vec2 screenSize;
#include "createEdgeQuad.glsl"
void main() void main()
{ {
createEdgeQuad(0,1, screenSize, lineWidth);
sg_MapIO(0); // IO mapping provided by ShaderGen, send vertex 0 createEdgeQuad(1,2, screenSize, lineWidth);
outGeometryBary = vec3(1, 0, 0); createEdgeQuad(2,0, screenSize, lineWidth);
EmitVertex(); }
sg_MapIO(1); // IO mapping provided by ShaderGen, send vertex 1
outGeometryBary = vec3(0, 1, 0);
EmitVertex();
sg_MapIO(2); // IO mapping provided by ShaderGen, send vertex 2
outGeometryBary = vec3(0, 0, 1);
EmitVertex();
EndPrimitive();
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment