solvespace/res/shaders/edge.frag
whitequark c8ff17f4a2 Add OpenGL 2 support on Windows using ANGLE.
This commit performs two main changes:
  * Alters the shaders to use only strictly conformant GLSL 2.0.
  * Alters the Windows UI to use ANGLE via GL ES 2.0 and EGL 1.4.

This commit also drops official support for Windows XP, since ANGLE
requires a non-XP toolset to build. It is still possible to build
SolveSpace for Windows XP using:

  cmake -T v120_xp -DOPENGL=1
2016-11-18 11:38:45 +00:00

36 lines
1.0 KiB
GLSL

//-----------------------------------------------------------------------------
// SolveSpace Edge rendering shader
//
// Copyright 2016 Aleksey Egorov
//-----------------------------------------------------------------------------
const float feather = 0.5;
uniform vec4 color;
uniform float pixel;
uniform float width;
uniform float patternLen;
uniform float patternScale;
uniform sampler2D pattern;
varying vec3 fragLoc;
void main() {
// lookup distance texture
vec4 v = texture2D(pattern, vec2(fragLoc.z / patternScale, 0.0));
// decode distance value
float val = dot(v, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0));
// calculate cap
float dist = length(vec2(val * patternScale / (patternLen * width) + abs(fragLoc.x), fragLoc.y));
// perform antialising
float k = smoothstep(1.0 - 2.0 * feather * pixel / (width + feather * pixel), 1.0, abs(dist));
// perfrom alpha-test
if(k == 1.0) discard;
// write resulting color
gl_FragColor = vec4(color.rgb, color.a * (1.0 - k));
}