2018-01-02 22:15:19 -05:00
|
|
|
// pathfinder/shaders/gles2/ecaa-curve.fs.glsl
|
2017-10-03 18:32:03 -04:00
|
|
|
//
|
|
|
|
// Copyright (c) 2017 The Pathfinder Project Developers.
|
2017-08-18 20:12:58 -04:00
|
|
|
//
|
2017-10-03 18:32:03 -04:00
|
|
|
// 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 20:12:58 -04:00
|
|
|
|
2017-12-30 20:32:51 -05:00
|
|
|
//! Performs analytic *coverage antialiasing* (XCAA) in order to render curves.
|
|
|
|
//!
|
|
|
|
//! Given endpoints P0 and P2 and control point P1, this shader expects that
|
|
|
|
//! P0.x <= P1.x <= P2.x.
|
|
|
|
|
2017-08-18 20:12:58 -04:00
|
|
|
precision highp float;
|
|
|
|
|
|
|
|
varying vec4 vEndpoints;
|
|
|
|
varying vec2 vControlPoint;
|
2017-10-09 17:14:24 -04:00
|
|
|
varying float vWinding;
|
2017-08-18 20:12:58 -04:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
// Unpack.
|
2017-11-21 18:51:27 -05:00
|
|
|
vec2 pixelCenter = gl_FragCoord.xy;
|
2017-08-18 20:12:58 -04:00
|
|
|
vec2 p0 = vEndpoints.xy, p1 = vEndpoints.zw;
|
|
|
|
vec2 cp = vControlPoint;
|
|
|
|
|
|
|
|
// Compute pixel extents.
|
2017-11-21 18:51:27 -05:00
|
|
|
vec2 pixelColumnBounds = pixelCenter.xx + vec2(-0.5, 0.5);
|
2017-08-18 20:12:58 -04:00
|
|
|
|
|
|
|
// Clip the curve to the left and right edges to create a line.
|
2017-11-21 18:51:27 -05:00
|
|
|
vec2 t = solveCurveT(p0.x, cp.x, p1.x, pixelColumnBounds);
|
2017-11-11 12:38:06 -05:00
|
|
|
|
|
|
|
// Handle endpoints properly. These tests are negated to handle NaNs.
|
2017-11-21 18:51:27 -05:00
|
|
|
if (!(p0.x < pixelColumnBounds.x))
|
2017-11-10 22:25:47 -05:00
|
|
|
t.x = 0.0;
|
2017-11-21 18:51:27 -05:00
|
|
|
if (!(p1.x > pixelColumnBounds.y))
|
2017-11-10 22:25:47 -05:00
|
|
|
t.y = 1.0;
|
2017-08-18 20:12:58 -04:00
|
|
|
|
2017-10-09 17:14:24 -04:00
|
|
|
vec2 clippedP0 = mix(mix(p0, cp, t.x), mix(cp, p1, t.x), t.x);
|
2017-11-21 18:51:27 -05:00
|
|
|
vec2 clippedDP = mix(mix(p0, cp, t.y), mix(cp, p1, t.y), t.y) - clippedP0;
|
2017-08-18 20:12:58 -04:00
|
|
|
|
|
|
|
// Compute area.
|
2017-11-21 18:51:27 -05:00
|
|
|
gl_FragColor = vec4(computeCoverage(clippedP0, clippedDP, pixelCenter.y, vWinding));
|
2017-08-18 20:12:58 -04:00
|
|
|
}
|