2017-10-09 17:14:24 -04:00
|
|
|
// pathfinder/shaders/gles2/xcaa-line.fs.glsl
|
2017-08-18 14:44:17 -04:00
|
|
|
//
|
2017-10-03 18:32:03 -04:00
|
|
|
// Copyright (c) 2017 The Pathfinder Project Developers.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
2017-08-18 14:44:17 -04:00
|
|
|
|
|
|
|
precision highp float;
|
|
|
|
|
|
|
|
varying vec4 vEndpoints;
|
2017-10-09 17:14:24 -04:00
|
|
|
varying float vWinding;
|
2017-08-18 14:44:17 -04:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
// Unpack.
|
|
|
|
vec2 center = gl_FragCoord.xy;
|
|
|
|
vec2 p0 = vEndpoints.xy, p1 = vEndpoints.zw;
|
|
|
|
|
|
|
|
// Set up Liang-Barsky clipping.
|
|
|
|
vec4 pixelExtents = center.xxyy + vec4(-0.5, 0.5, -0.5, 0.5);
|
2017-10-09 17:14:24 -04:00
|
|
|
vec2 dp = p1 - p0;
|
|
|
|
vec4 q = pixelExtents - p0.xxyy;
|
2017-08-18 14:44:17 -04:00
|
|
|
|
|
|
|
// Use Liang-Barsky to clip to the left and right sides of this pixel.
|
2017-10-09 17:14:24 -04:00
|
|
|
vec2 t = clamp(q.xy / dp.xx, 0.0, 1.0);
|
|
|
|
vec2 spanP0 = p0 + dp * t.x, spanP1 = p0 + dp * t.y;
|
2017-08-18 14:44:17 -04:00
|
|
|
|
2017-08-18 20:12:58 -04:00
|
|
|
// Compute area.
|
2017-10-09 17:14:24 -04:00
|
|
|
gl_FragColor = vec4(computeCoverage(p0, dp, center, vWinding));
|
2017-08-18 14:44:17 -04:00
|
|
|
}
|