Commit 14d0a11d authored by Jan Möbius's avatar Jan Möbius

Basic patches for better geometry shader support.

Additional Shaders to support Line width via geometry shader

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17513 383ad7c9-94d9-4d36-a494-682f7c89f535
parent f532b2bb
// template file for shader generator
in vec3 outGeometryBary;
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*1.5, outGeometryBary);
return min(min(a3.x, a3.y), a3.z);
}
void main()
{
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
}
\ No newline at end of file
// template file for shader generator
in vec3 outGeometryBary;
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*1.5, outGeometryBary);
return min(min(a3.x, a3.y), a3.z);
}
void main()
{
SG_FRAGMENT_BEGIN
sg_cColor.xyz = mix(vec3(0.0), sg_cColor.xyz, 1-edgeFactor());
SG_FRAGMENT_END
}
\ No newline at end of file
// template file for shader generator
void main()
{
const float lineWidth = 0.005;
const vec2 screenSize = vec2(1.0, 1.0);
// start/end points of line
vec4 p0 = gl_in[0].gl_Position;
vec4 p1 = gl_in[1].gl_Position;
// convert to screen space
p0.xy = p0.xy / p0.w * screenSize;
p1.xy = p1.xy / p1.w * screenSize;
// compute dir and normal
vec2 lineDir = p1.xy - p0.xy;
vec2 lineNormal = normalize(vec2(-lineDir.y, lineDir.x));
// create screen-aligned quad
vec2 offset = lineNormal * lineWidth;
sg_MapIO(0); // default IO mapping
gl_Position = vec4( (p0 + offset) * p0.w / screenSize, p0.z, p0.w);
EmitVertex();
sg_MapIO(0); // default IO mapping
gl_Position = vec4( (p0 - offset) * p0.w / screenSize, p0.z, p0.w);
EmitVertex();
sg_MapIO(1); // default IO mapping
gl_Position = vec4( (p1 + offset) * p1.w / screenSize, p1.z, p1.w);
EmitVertex();
sg_MapIO(1); // default IO mapping
gl_Position = vec4( (p1 - offset) * p1.w / screenSize, p1.z, p1.w);
EmitVertex();
EndPrimitive();
}
\ No newline at end of file
// template file for shader generator
// send barycentric coords to fragment
out vec3 outGeometryBary;
void main()
{
sg_MapIO(0); // IO mapping provided by ShaderGen, send vertex 0
outGeometryBary = vec3(1, 0, 0);
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