solvespace/res/shaders/edge.vert
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

42 lines
1.2 KiB
GLSL

//-----------------------------------------------------------------------------
// SolveSpace Edge rendering shader
//
// Copyright 2016 Aleksey Egorov
//-----------------------------------------------------------------------------
const float feather = 0.5;
attribute vec3 pos;
attribute vec3 loc;
attribute vec3 tan;
uniform mat4 modelview;
uniform mat4 projection;
uniform float width;
uniform float pixel;
varying vec3 fragLoc;
void main() {
// get camera direction from modelview matrix
vec3 dir = vec3(modelview[0].z, modelview[1].z, modelview[2].z);
// calculate line contour extension basis for constant width and caps
vec3 norm = normalize(cross(tan, dir));
norm = normalize(norm - dir * dot(dir, norm));
vec3 perp = normalize(cross(dir, norm));
// calculate line extension width considering antialiasing
float ext = width + feather * pixel;
// extend line contour
vec3 vertex = pos;
vertex += ext * loc.x * normalize(perp);
vertex += ext * loc.y * normalize(norm);
// write fragment location for calculating caps and antialiasing
fragLoc = loc;
// transform resulting vertex with modelview and projection matrices
gl_Position = projection * modelview * vec4(vertex, 1.0);
}