2018-01-02 22:15:19 -05:00
|
|
|
// pathfinder/shaders/gles2/mcaa.fs.glsl
|
2017-12-15 16:41:27 -05:00
|
|
|
//
|
2018-01-30 12:34:34 -05:00
|
|
|
// Copyright (c) 2018 The Pathfinder Project Developers.
|
2017-12-15 16:41:27 -05: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-12-30 20:32:51 -05:00
|
|
|
//! Renders paths when performing multicolor *mesh coverage antialiasing*
|
|
|
|
//! (MCAA). This one shader handles both lines and curves.
|
|
|
|
//!
|
|
|
|
//! This shader expects to render to a standard RGB color buffer.
|
|
|
|
|
2017-12-15 16:41:27 -05:00
|
|
|
precision highp float;
|
|
|
|
|
|
|
|
varying vec4 vColor;
|
2018-01-30 12:34:34 -05:00
|
|
|
varying vec4 vUV;
|
|
|
|
varying vec4 vSignMode;
|
|
|
|
|
2018-02-05 18:10:52 -05:00
|
|
|
void main() {
|
|
|
|
bool inUpperCurve = insideCurve(vec3(vUV.xy, vSignMode.z > 0.0 ? 1.0 : 0.0));
|
|
|
|
bool inLowerCurve = insideCurve(vec3(vUV.zw, vSignMode.w > 0.0 ? 1.0 : 0.0));
|
2017-12-15 16:41:27 -05:00
|
|
|
|
2018-02-05 18:10:52 -05:00
|
|
|
float upperDist = signedDistanceToCurve(vUV.xy, dFdx(vUV.xy), dFdy(vUV.xy), inUpperCurve);
|
|
|
|
float lowerDist = signedDistanceToCurve(vUV.zw, dFdx(vUV.zw), dFdy(vUV.zw), inLowerCurve);
|
2017-12-15 16:41:27 -05:00
|
|
|
|
2018-02-05 18:10:52 -05:00
|
|
|
float alpha = -estimateArea(upperDist * vSignMode.x) - estimateArea(lowerDist * vSignMode.y);
|
2018-01-30 12:34:34 -05:00
|
|
|
gl_FragColor = alpha * vColor;
|
2017-12-15 16:41:27 -05:00
|
|
|
}
|