diff --git a/shaders/gles2/blit-gamma.fs.glsl b/shaders/gles2/blit-gamma.fs.glsl deleted file mode 100644 index 08ad8705..00000000 --- a/shaders/gles2/blit-gamma.fs.glsl +++ /dev/null @@ -1,28 +0,0 @@ -// pathfinder/shaders/gles2/blit-gamma.fs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Blits a texture, applying gamma correction. - -precision mediump float; - -/// The source texture to blit. -uniform sampler2D uSource; -/// The approximate background color, in linear RGB. -uniform vec3 uBGColor; -/// The gamma LUT. -uniform sampler2D uGammaLUT; - -/// The incoming texture coordinate. -varying vec2 vTexCoord; - -void main() { - vec4 source = texture2D(uSource, vTexCoord); - gl_FragColor = vec4(gammaCorrect(source.rgb, uBGColor, uGammaLUT), source.a); -} diff --git a/shaders/gles2/blit-linear.fs.glsl b/shaders/gles2/blit-linear.fs.glsl deleted file mode 100644 index 69b4aafc..00000000 --- a/shaders/gles2/blit-linear.fs.glsl +++ /dev/null @@ -1,23 +0,0 @@ -// pathfinder/shaders/gles2/blit-linear.fs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A trivial shader that does nothing more than blit a texture. - -precision mediump float; - -/// The source texture to blit. -uniform sampler2D uSource; - -/// The incoming texture coordinate. -varying vec2 vTexCoord; - -void main() { - gl_FragColor = texture2D(uSource, vTexCoord); -} diff --git a/shaders/gles2/blit.vs.glsl b/shaders/gles2/blit.vs.glsl deleted file mode 100644 index c3a7ceb9..00000000 --- a/shaders/gles2/blit.vs.glsl +++ /dev/null @@ -1,31 +0,0 @@ -// pathfinder/shaders/gles2/blit.vs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A trivial shader that does nothing more than blit a texture. - -precision mediump float; - -/// A 3D transform to apply to the scene. -uniform mat4 uTransform; -/// A pair of fixed scale factors to be applied to the texture coordinates. -uniform vec2 uTexScale; - -/// The 2D vertex position. -attribute vec2 aPosition; -/// The texture coordinate. -attribute vec2 aTexCoord; - -/// The outgoing texture coordinate. -varying vec2 vTexCoord; - -void main() { - gl_Position = uTransform * vec4(aPosition, 0.0, 1.0); - vTexCoord = aTexCoord * uTexScale; -} diff --git a/shaders/gles2/common.inc.glsl b/shaders/gles2/common.inc.glsl deleted file mode 100644 index cf0f73e6..00000000 --- a/shaders/gles2/common.inc.glsl +++ /dev/null @@ -1,329 +0,0 @@ -// pathfinder/shaders/gles2/common.inc.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#version 100 - -#extension GL_OES_standard_derivatives : require - -#define FREETYPE_LCD_FILTER_FACTOR_0 0.337254902 -#define FREETYPE_LCD_FILTER_FACTOR_1 0.301960784 -#define FREETYPE_LCD_FILTER_FACTOR_2 0.031372549 - -// These intentionally do not precisely match what Core Graphics does (a Lanczos function), because -// we don't want any ringing artefacts. -#define CG_LCD_FILTER_FACTOR_0 0.286651906 -#define CG_LCD_FILTER_FACTOR_1 0.221434336 -#define CG_LCD_FILTER_FACTOR_2 0.102074051 -#define CG_LCD_FILTER_FACTOR_3 0.033165660 - -#define MAX_PATHS 65536 - -#define EPSILON 0.001 - -precision highp float; - -/// Returns true if the given number is close to zero. -bool isNearZero(float x) { - return abs(x) < EPSILON; -} - -/// Computes `ia % ib`. -/// -/// This function is not in OpenGL ES 2 but can be polyfilled. -/// See: https://stackoverflow.com/a/36078859 -int imod(int ia, int ib) { - float a = float(ia), b = float(ib); - float m = a - floor((a + 0.5) / b) * b; - return int(floor(m + 0.5)); -} - -float fastSign(float x) { - return x > 0.0 ? 1.0 : -1.0; -} - -float det2(mat2 m) { - return m[0][0] * m[1][1] - m[0][1] * m[1][0]; -} - -/// Returns the *2D* result of transforming the given 2D point with the given 4D transformation -/// matrix. -/// -/// The z and w coordinates are treated as 0.0 and 1.0, respectively. -vec2 transformVertexPosition(vec2 position, mat4 transform) { - return (transform * vec4(position, 0.0, 1.0)).xy; -} - -/// Returns the 2D result of transforming the given 2D position by the given ST-transform. -/// -/// An ST-transform is a combined 2D scale and translation, where the (x, y) coordinates specify -/// the scale and and the (z, w) coordinates specify the translation. -vec2 transformVertexPositionST(vec2 position, vec4 transformST) { - return position * transformST.xy + transformST.zw; -} - -vec2 transformVertexPositionAffine(vec2 position, vec4 transformST, vec2 transformExt) { - return position * transformST.xy + position.yx * transformExt + transformST.zw; -} - -vec2 transformVertexPositionInverseLinear(vec2 position, mat2 transform) { - position = vec2(det2(mat2(position, transform[1])), det2(mat2(transform[0], position))); - return position / det2(transform); -} - -/// Interpolates the given 2D position in the vertical direction using the given ultra-slight -/// hints. -/// -/// Similar in spirit to the `IUP[y]` TrueType command, but minimal. -/// -/// pathHints.x: xHeight -/// pathHints.y: hintedXHeight -/// pathHints.z: stemHeight -/// pathHints.w: hintedStemHeight -/// -/// TODO(pcwalton): Do something smarter with overshoots and the blue zone. -/// TODO(pcwalton): Support interpolating relative to arbitrary horizontal stems, not just the -/// baseline, x-height, and stem height. -vec2 hintPosition(vec2 position, vec4 pathHints) { - float y; - if (position.y >= pathHints.z) { - y = position.y - pathHints.z + pathHints.w; - } else if (position.y >= pathHints.x) { - float t = (position.y - pathHints.x) / (pathHints.z - pathHints.x); - y = mix(pathHints.y, pathHints.w, t); - } else if (position.y >= 0.0) { - y = mix(0.0, pathHints.y, position.y / pathHints.x); - } else { - y = position.y; - } - - return vec2(position.x, y); -} - -vec2 quantize(vec2 position) { - return (floor(position * 20000.0 + 0.5) - 0.5) / 20000.0; -} - -/// Converts the given 2D position in clip space to device pixel space (with origin in the lower -/// left). -vec2 convertClipToScreenSpace(vec2 position, ivec2 framebufferSize) { - return (position + 1.0) * 0.5 * vec2(framebufferSize); -} - -/// Converts the given 2D position in device pixel space (with origin in the lower left) to clip -/// space. -vec2 convertScreenToClipSpace(vec2 position, ivec2 framebufferSize) { - return position / vec2(framebufferSize) * 2.0 - 1.0; -} - -/// Packs the given path ID into a floating point value suitable for storage in the depth buffer. -/// This function returns values in clip space (i.e. what `gl_Position` is in). -float convertPathIndexToViewportDepthValue(int pathIndex) { - return float(pathIndex) / float(MAX_PATHS) * 2.0 - 1.0; -} - -/// Displaces the given point by the given distance in the direction of the normal angle. -vec2 dilatePosition(vec2 position, float normalAngle, vec2 amount) { - return position + vec2(cos(normalAngle), -sin(normalAngle)) * amount; -} - -/// Returns true if the slope of the line along the given vector is negative. -bool slopeIsNegative(vec2 dp) { - return dp.y < 0.0; -} - -/// Uses Liang-Barsky to clip the line to the left and right of the pixel square. -/// -/// Returns vec4(P0', dP'). -vec4 clipLineToPixelColumn(vec2 p0, vec2 dP, float pixelCenterX) { - vec2 pixelColumnBounds = vec2(-0.5, 0.5) + pixelCenterX; - vec2 qX = pixelColumnBounds - p0.xx; - vec2 tX = clamp(qX / dP.xx, 0.0, 1.0); - return vec4(p0 + dP * tX.x, dP * (tX.y - tX.x)); -} - -/// Uses Liang-Barsky to clip the line to the top and bottom of the pixel square. -/// -/// Returns vec4(P0'', dP''). In the case of horizontal lines, this can yield -Infinity or -/// Infinity. -vec4 clipLineToPixelRow(vec2 p0, vec2 dP, float pixelCenterY, out float outPixelTop) { - vec2 pixelRowBounds = vec2(-0.5, 0.5) + pixelCenterY; - outPixelTop = pixelRowBounds.y; - vec2 qY = pixelRowBounds - p0.yy; - vec2 tY = clamp((slopeIsNegative(dP) ? qY.yx : qY.xy) / dP.yy, 0.0, 1.0); - return vec4(p0 + dP * tY.x, dP * (tY.y - tY.x)); -} - -/// Computes the area of the polygon covering the pixel with the given boundaries. -/// -/// The line must run left-to-right and must already be clipped to the left and right sides of the -/// pixel, which implies that `dP.x` must be within the range [0.0, 1.0]. -/// -/// * `p0X` is the start point of the line. -/// * `dPX` is the vector from the start point to the endpoint of the line. -/// * `pixelCenterY` is the Y coordinate of the center of the pixel in window coordinates (i.e. -/// `gl_FragCoord.y`). -/// * `winding` is the winding number (1 or -1). -float computeCoverage(vec2 p0X, vec2 dPX, float pixelCenterY, float winding) { - // Clip to the pixel row. - float pixelTop; - vec4 p0DPY = clipLineToPixelRow(p0X, dPX, pixelCenterY, pixelTop); - vec2 p0 = p0DPY.xy, dP = p0DPY.zw; - vec2 p1 = p0 + dP; - - // If the line doesn't pass through this pixel, detect that and bail. - // - // This should be worth a branch because it's very common for fragment blocks to all hit this - // path. - // - // The variable is required to work around a bug in the macOS Nvidia drivers. - // Without moving the condition in a variable, the early return is ignored. See #51. - bool lineDoesNotPassThroughPixel = isNearZero(dP.x) && isNearZero(dP.y); - if (lineDoesNotPassThroughPixel) - return p0X.y < pixelTop ? winding * dPX.x : 0.0; - - // Calculate points A0-A2. - float a2x; - vec2 a0, a1; - if (slopeIsNegative(dP)) { - a2x = p0X.x + dPX.x; - a0 = p0; - a1 = p1; - } else { - a2x = p0X.x; - a0 = p1; - a1 = p0; - } - - // Calculate area with the shoelace formula. - // This is conceptually the sum of 5 determinants for points A0-A5, where A2-A5 are: - // - // A2 = (a2.x, a1.y) - // A3 = (a2.x, top) - // A4 = (a0.x, top) - // - // The formula is optimized. See: http://geomalgorithms.com/a01-_area.html - float area = a0.x * (a0.y + a1.y - 2.0 * pixelTop) + - a1.x * (a1.y - a0.y) + - 2.0 * a2x * (pixelTop - a1.y); - return abs(area) * winding * 0.5; -} - -/// Solves the equation: -/// -/// x = p0x + t^2 * (p0x - 2*p1x + p2x) + t*(2*p1x - 2*p0x) -/// -/// We use the Citardauq Formula to avoid floating point precision issues. -vec2 solveCurveT(float p0x, float p1x, float p2x, vec2 x) { - float a = p0x - 2.0 * p1x + p2x; - float b = 2.0 * p1x - 2.0 * p0x; - vec2 c = p0x - x; - return 2.0 * c / (-b - sqrt(b * b - 4.0 * a * c)); -} - -/// Applies a slight horizontal blur to reduce color fringing on LCD screens -/// when performing subpixel AA. -/// -/// The algorithm should be identical to that of FreeType: -/// https://www.freetype.org/freetype2/docs/reference/ft2-lcd_filtering.html -float freetypeLCDFilter(float shadeL2, float shadeL1, float shade0, float shadeR1, float shadeR2) { - return FREETYPE_LCD_FILTER_FACTOR_2 * shadeL2 + - FREETYPE_LCD_FILTER_FACTOR_1 * shadeL1 + - FREETYPE_LCD_FILTER_FACTOR_0 * shade0 + - FREETYPE_LCD_FILTER_FACTOR_1 * shadeR1 + - FREETYPE_LCD_FILTER_FACTOR_2 * shadeR2; -} - -float sample1Tap(sampler2D source, vec2 center, float offset) { - return texture2D(source, vec2(center.x + offset, center.y)).r; -} - -void sample9Tap(out vec4 outShadesL, - out float outShadeC, - out vec4 outShadesR, - sampler2D source, - vec2 center, - float onePixel, - vec4 kernel) { - outShadesL = vec4(kernel.x > 0.0 ? sample1Tap(source, center, -4.0 * onePixel) : 0.0, - sample1Tap(source, center, -3.0 * onePixel), - sample1Tap(source, center, -2.0 * onePixel), - sample1Tap(source, center, -1.0 * onePixel)); - outShadeC = sample1Tap(source, center, 0.0); - outShadesR = vec4(sample1Tap(source, center, 1.0 * onePixel), - sample1Tap(source, center, 2.0 * onePixel), - sample1Tap(source, center, 3.0 * onePixel), - kernel.x > 0.0 ? sample1Tap(source, center, 4.0 * onePixel) : 0.0); -} - -float convolve7Tap(vec4 shades0, vec3 shades1, vec4 kernel) { - return dot(shades0, kernel) + dot(shades1, kernel.zyx); -} - -float gammaCorrectChannel(float fgColor, float bgColor, sampler2D gammaLUT) { - return texture2D(gammaLUT, vec2(fgColor, 1.0 - bgColor)).r; -} - -// `fgColor` is in linear space. -vec3 gammaCorrect(vec3 fgColor, vec3 bgColor, sampler2D gammaLUT) { - return vec3(gammaCorrectChannel(fgColor.r, bgColor.r, gammaLUT), - gammaCorrectChannel(fgColor.g, bgColor.g, gammaLUT), - gammaCorrectChannel(fgColor.b, bgColor.b, gammaLUT)); -} - -vec4 fetchFloat4Data(sampler2D dataTexture, int index, ivec2 dimensions) { - ivec2 pixelCoord = ivec2(imod(index, dimensions.x), index / dimensions.x); - return texture2D(dataTexture, (vec2(pixelCoord) + 0.5) / vec2(dimensions)); -} - -vec2 fetchFloat2Data(sampler2D dataTexture, int index, ivec2 dimensions) { - int texelIndex = index / 2; - vec4 texel = fetchFloat4Data(dataTexture, texelIndex, dimensions); - return texelIndex * 2 == index ? texel.xy : texel.zw; -} - -vec4 fetchPathAffineTransform(out vec2 outPathTransformExt, - sampler2D pathTransformSTTexture, - ivec2 pathTransformSTDimensions, - sampler2D pathTransformExtTexture, - ivec2 pathTransformExtDimensions, - int pathID) { - outPathTransformExt = fetchFloat2Data(pathTransformExtTexture, - pathID, - pathTransformExtDimensions); - return fetchFloat4Data(pathTransformSTTexture, pathID, pathTransformSTDimensions); -} - -// Are we inside the convex hull of the curve? (This will always be false if this is a line.) -bool insideCurve(vec3 uv) { - return uv.z != 0.0 && uv.x > 0.0 && uv.x < 1.0 && uv.y > 0.0 && uv.y < 1.0; -} - -float signedDistanceToCurve(vec2 uv, vec2 dUVDX, vec2 dUVDY, bool inCurve) { - // u^2 - v for curves inside uv square; u - v otherwise. - float g = uv.x; - vec2 dG = vec2(dUVDX.x, dUVDY.x); - if (inCurve) { - g *= uv.x; - dG *= 2.0 * uv.x; - } - g -= uv.y; - dG -= vec2(dUVDX.y, dUVDY.y); - return g / length(dG); -} - -// Cubic approximation to the square area coverage, accurate to about 4%. -float estimateArea(float dist) { - if (dist >= 0.707107) - return 0.5; - // Catch NaNs here. - if (!(dist > -0.707107)) - return -0.5; - return 1.14191 * dist - 0.83570 * dist * dist * dist; -} diff --git a/shaders/gles2/conservative-interior.vs.glsl b/shaders/gles2/conservative-interior.vs.glsl deleted file mode 100644 index b78b8c1c..00000000 --- a/shaders/gles2/conservative-interior.vs.glsl +++ /dev/null @@ -1,74 +0,0 @@ -// pathfinder/shaders/gles2/conservative-interior.vs.glsl -// -// Copyright (c) 2018 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Renders polygonal portions of a mesh, only filling pixels that are fully -//! covered. -//! -//! Typically, you will run this shader before running XCAA. -//! Remember to enable the depth test with a `GREATER` depth function for optimal -//! performance. - -precision highp float; - -/// An affine transform to be applied to all points. -uniform vec4 uTransformST; -uniform vec2 uTransformExt; -/// Vertical snapping positions. -uniform vec4 uHints; -/// The framebuffer size in pixels. -uniform ivec2 uFramebufferSize; -/// The size of the path colors texture in texels. -uniform ivec2 uPathColorsDimensions; -/// The fill color for each path. -uniform sampler2D uPathColors; -/// The size of the path transform buffer texture in texels. -uniform ivec2 uPathTransformSTDimensions; -/// The path transform buffer texture, one path dilation per texel. -uniform sampler2D uPathTransformST; -/// The size of the extra path transform factors buffer texture in texels. -uniform ivec2 uPathTransformExtDimensions; -/// The extra path transform factors buffer texture, packed two path transforms per texel. -uniform sampler2D uPathTransformExt; -/// The amount of faux-bold to apply, in local path units. -uniform vec2 uEmboldenAmount; - -/// The 2D position of this point. -attribute vec2 aPosition; -/// The path ID, starting from 1. -attribute float aPathID; -/// The vertex ID. In OpenGL 3.0+, this can be omitted in favor of `gl_VertexID`. -attribute float aVertexID; - -/// The color of this path. -varying vec4 vColor; - -void main() { - int pathID = int(aPathID); - int vertexID = int(aVertexID); - - vec4 transformST = fetchFloat4Data(uPathTransformST, pathID, uPathTransformSTDimensions); - - mat2 globalTransformLinear = mat2(uTransformST.x, uTransformExt, uTransformST.y); - mat2 localTransformLinear = mat2(transformST.x, 0.0, 0.0, transformST.y); - mat2 transformLinear = globalTransformLinear * localTransformLinear; - - vec2 translation = uTransformST.zw + globalTransformLinear * transformST.zw; - - float onePixel = 2.0 / float(uFramebufferSize.y); - float dilation = length(transformVertexPositionInverseLinear(vec2(0.0, onePixel), - transformLinear)); - - vec2 position = aPosition + vec2(0.0, imod(vertexID, 6) < 3 ? dilation : -dilation); - position = transformLinear * position + translation; - float depth = convertPathIndexToViewportDepthValue(pathID); - - gl_Position = vec4(position, depth, 1.0); - vColor = fetchFloat4Data(uPathColors, pathID, uPathColorsDimensions); -} diff --git a/shaders/gles2/demo-3d-distant-glyph.fs.glsl b/shaders/gles2/demo-3d-distant-glyph.fs.glsl deleted file mode 100644 index 5db91101..00000000 --- a/shaders/gles2/demo-3d-distant-glyph.fs.glsl +++ /dev/null @@ -1,25 +0,0 @@ -// pathfinder/shaders/gles2/demo-3d-distant-glyph.fs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Renders cached textures of distant glyphs in the 3D demo. - -precision highp float; - -/// The color of the font. -uniform vec4 uColor; -/// The cached glyph atlas. -uniform sampler2D uAtlas; - -/// The texture coordinate. -varying vec2 vTexCoord; - -void main() { - gl_FragColor = uColor * texture2D(uAtlas, vTexCoord).rrrr; -} diff --git a/shaders/gles2/demo-3d-distant-glyph.vs.glsl b/shaders/gles2/demo-3d-distant-glyph.vs.glsl deleted file mode 100644 index 4dc66282..00000000 --- a/shaders/gles2/demo-3d-distant-glyph.vs.glsl +++ /dev/null @@ -1,34 +0,0 @@ -// pathfinder/shaders/gles2/demo-3d-distant-glyph.vs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Renders cached textures of distant glyphs in the 3D demo. - -precision highp float; - -/// A concatenated transform to be applied to each point. -uniform mat4 uTransform; -/// The texture coordinates for this glyph. -uniform vec4 uGlyphTexCoords; -/// The size of the glyph in local coordinates. -uniform vec2 uGlyphSize; - -/// The abstract quad position: (0.0, 0.0) to (1.0, 1.0). -attribute vec2 aQuadPosition; -// The world-space 2D position of this vertex. -attribute vec2 aPosition; - -/// The texture coordinate. -varying vec2 vTexCoord; - -void main() { - vec2 positionBL = aPosition, positionTR = aPosition + uGlyphSize; - gl_Position = uTransform * vec4(mix(positionBL, positionTR, aQuadPosition), 0.0, 1.0); - vTexCoord = mix(uGlyphTexCoords.xy, uGlyphTexCoords.zw, aQuadPosition); -} diff --git a/shaders/gles2/demo-3d-monument.fs.glsl b/shaders/gles2/demo-3d-monument.fs.glsl deleted file mode 100644 index 4e26f4df..00000000 --- a/shaders/gles2/demo-3d-monument.fs.glsl +++ /dev/null @@ -1,52 +0,0 @@ -// pathfinder/shaders/gles2/demo-3d-monument.fs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Renders the monument surface in the 3D demo. - -precision mediump float; - -/// The 3D position of the light. -uniform vec3 uLightPosition; -/// The ambient color of the light. -uniform vec3 uAmbientColor; -/// The diffuse color of the light. -uniform vec3 uDiffuseColor; -/// The Phong specular color of the light. -uniform vec3 uSpecularColor; -/// The Phong albedo exponent. -uniform float uShininess; -/// The normal of these vertices. -uniform vec3 uNormal; - -uniform bool uEnableLighting; - -varying vec3 vPosition; - -void main() { - vec3 normal = normalize(uNormal); - vec3 lightDirection = normalize(uLightPosition - vPosition); - - vec3 color = uAmbientColor; - - if (uEnableLighting) { - float lambertian = max(dot(lightDirection, normal), 0.0); - float specular = 0.0; - - if (lambertian > 0.0) { - vec3 viewDirection = normalize(-vPosition); - vec3 halfDirection = normalize(lightDirection + viewDirection); - float specularAngle = max(dot(halfDirection, normal), 0.0); - specular = pow(specularAngle, uShininess); - } - - color = color + uAmbientColor + lambertian * uDiffuseColor + specular * uSpecularColor; - } - gl_FragColor = vec4(color, 1.0); -} diff --git a/shaders/gles2/demo-3d-monument.vs.glsl b/shaders/gles2/demo-3d-monument.vs.glsl deleted file mode 100644 index 54312ac9..00000000 --- a/shaders/gles2/demo-3d-monument.vs.glsl +++ /dev/null @@ -1,30 +0,0 @@ -// pathfinder/shaders/gles2/demo-3d-monument.vs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Renders the monument surface in the 3D demo. - -precision mediump float; - -/// The 3D projection matrix. -uniform mat4 uProjection; -/// The 3D modelview matrix. -uniform mat4 uModelview; - -/// The 3D vertex position. -attribute vec3 aPosition; - -/// The 3D vertex position. -varying vec3 vPosition; - -void main() { - vec4 position = uModelview * vec4(aPosition, 1.0); - vPosition = position.xyz / position.w; - gl_Position = uProjection * position; -} diff --git a/shaders/gles2/direct-3d-curve.vs.glsl b/shaders/gles2/direct-3d-curve.vs.glsl deleted file mode 100644 index 8ff41fd7..00000000 --- a/shaders/gles2/direct-3d-curve.vs.glsl +++ /dev/null @@ -1,72 +0,0 @@ -// pathfinder/shaders/gles2/direct-3d-curve.vs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A version of `direct-curve` that takes each vertex's Z value from the -//! transform instead of the path ID. -//! -//! FIXME(pcwalton): For CSS 3D transforms, I think `direct-curve` will need -//! to do what this shader does. Perhaps these two shaders should be unified… - -precision highp float; - -/// A 3D transform to be applied to all points. -uniform mat4 uTransform; -/// The size of the path transform buffer texture in texels. -uniform ivec2 uPathTransformSTDimensions; -/// The path transform buffer texture, one dilation per path ID. -uniform sampler2D uPathTransformST; -/// The size of the extra path transform factors buffer texture in texels. -uniform ivec2 uPathTransformExtDimensions; -/// The extra path transform factors buffer texture, packed two path transforms per texel. -uniform sampler2D uPathTransformExt; -/// The size of the path colors buffer texture in texels. -uniform ivec2 uPathColorsDimensions; -/// The path colors buffer texture, one color per path ID. -uniform sampler2D uPathColors; -/// The amount of faux-bold to apply, in local path units. -uniform vec2 uEmboldenAmount; - -/// The 2D position of this point. -attribute vec2 aPosition; -/// The angle of the 2D normal for this point. -attribute float aNormalAngle; -/// The vertex ID. In OpenGL 3.0+, this can be omitted in favor of `gl_VertexID`. -attribute float aVertexID; -/// The path ID, starting from 1. -attribute float aPathID; - -/// The fill color of this path. -varying vec4 vColor; -/// The outgoing abstract Loop-Blinn texture coordinate. -varying vec2 vTexCoord; - -void main() { - int pathID = int(aPathID); - int vertexID = int(aVertexID); - - vec2 pathTransformExt; - vec4 pathTransformST = fetchPathAffineTransform(pathTransformExt, - uPathTransformST, - uPathTransformSTDimensions, - uPathTransformExt, - uPathTransformExtDimensions, - pathID); - - vec2 position = dilatePosition(aPosition, aNormalAngle, uEmboldenAmount); - position = transformVertexPositionAffine(position, pathTransformST, pathTransformExt); - - gl_Position = uTransform * vec4(position, 0.0, 1.0); - - int vertexIndex = imod(vertexID, 3); - vec2 texCoord = vec2(float(vertexIndex) * 0.5, float(vertexIndex == 2)); - - vColor = fetchFloat4Data(uPathColors, pathID, uPathColorsDimensions); - vTexCoord = texCoord; -} diff --git a/shaders/gles2/direct-3d-interior.vs.glsl b/shaders/gles2/direct-3d-interior.vs.glsl deleted file mode 100644 index cf925675..00000000 --- a/shaders/gles2/direct-3d-interior.vs.glsl +++ /dev/null @@ -1,51 +0,0 @@ -// pathfinder/shaders/gles2/direct-3d-interior.vs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! A version of `direct-interior` that takes each vertex's Z value from the -//! transform instead of the path ID. -//! -//! FIXME(pcwalton): For CSS 3D transforms, I think `direct-interior` will need -//! to do what this shader does. Perhaps these two shaders should be unified… - -precision highp float; - -uniform mat4 uTransform; -uniform vec2 uEmboldenAmount; -uniform ivec2 uPathColorsDimensions; -uniform sampler2D uPathColors; -uniform ivec2 uPathTransformSTDimensions; -uniform sampler2D uPathTransformST; -uniform ivec2 uPathTransformExtDimensions; -uniform sampler2D uPathTransformExt; - -attribute vec2 aPosition; -attribute float aPathID; -attribute float aNormalAngle; - -varying vec4 vColor; - -void main() { - int pathID = int(aPathID); - - vec2 pathTransformExt; - vec4 pathTransformST = fetchPathAffineTransform(pathTransformExt, - uPathTransformST, - uPathTransformSTDimensions, - uPathTransformExt, - uPathTransformExtDimensions, - pathID); - - vec2 position = dilatePosition(aPosition, aNormalAngle, uEmboldenAmount); - position = transformVertexPositionAffine(position, pathTransformST, pathTransformExt); - - gl_Position = uTransform * vec4(position, 0.0, 1.0); - - vColor = fetchFloat4Data(uPathColors, pathID, uPathColorsDimensions); -} diff --git a/shaders/gles2/direct-curve.fs.glsl b/shaders/gles2/direct-curve.fs.glsl deleted file mode 100644 index e1d9ed85..00000000 --- a/shaders/gles2/direct-curve.fs.glsl +++ /dev/null @@ -1,34 +0,0 @@ -// pathfinder/shaders/gles2/direct-curve.fs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implements the quadratic Loop-Blinn formulation to render curved parts of -//! the mesh. -//! -//! This shader performs no antialiasing; if you want antialiased output from -//! this shader, use MSAA with sample-level shading (GL 4.x) or else perform -//! SSAA by rendering to a higher-resolution framebuffer and downsampling (GL -//! 3.x and below). -//! -//! If you know your mesh has no curves (i.e. it consists solely of polygons), -//! then you don't need to run this shader. - -precision highp float; - -/// The fill color of this path. -varying vec4 vColor; -/// The abstract Loop-Blinn texture coordinate. -varying vec2 vTexCoord; - -void main() { - float side = sign(vTexCoord.x * vTexCoord.x - vTexCoord.y); - float winding = gl_FrontFacing ? -1.0 : 1.0; - float alpha = float(side == winding); - gl_FragColor = alpha * vColor; -} diff --git a/shaders/gles2/direct-curve.vs.glsl b/shaders/gles2/direct-curve.vs.glsl deleted file mode 100644 index bf9deb96..00000000 --- a/shaders/gles2/direct-curve.vs.glsl +++ /dev/null @@ -1,77 +0,0 @@ -// pathfinder/shaders/gles2/direct-curve.vs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Implements the quadratic Loop-Blinn formulation to render curved parts of -//! the mesh. -//! -//! This shader performs no antialiasing; if you want antialiased output from -//! this shader, use MSAA with sample-level shading (GL 4.x) or else perform -//! SSAA by rendering to a higher-resolution framebuffer and downsampling (GL -//! 3.x and below). -//! -//! If you know your mesh has no curves (i.e. it consists solely of polygons), -//! then you don't need to run this shader. - -precision highp float; - -/// A 3D transform to be applied to all points. -uniform mat4 uTransform; -/// Vertical snapping positions. -uniform vec4 uHints; -/// The size of the path colors texture in texels. -uniform ivec2 uPathColorsDimensions; -/// The fill color for each path. -uniform sampler2D uPathColors; -/// The size of the path transform buffer texture in texels. -uniform ivec2 uPathTransformSTDimensions; -/// The path transform buffer texture, one path dilation per texel. -uniform sampler2D uPathTransformST; -/// The size of the extra path transform factors buffer texture in texels. -uniform ivec2 uPathTransformExtDimensions; -/// The extra path transform factors buffer texture, packed two path transforms per texel. -uniform sampler2D uPathTransformExt; - -/// The 2D position of this point. -attribute vec2 aPosition; -/// The vertex ID. In OpenGL 3.0+, this can be omitted in favor of `gl_VertexID`. -attribute float aVertexID; -/// The path ID, starting from 1. -attribute float aPathID; - -/// The fill color of this path. -varying vec4 vColor; -/// The outgoing abstract Loop-Blinn texture coordinate. -varying vec2 vTexCoord; - -void main() { - int pathID = int(aPathID); - int vertexID = int(aVertexID); - - vec2 pathTransformExt; - vec4 pathTransformST = fetchPathAffineTransform(pathTransformExt, - uPathTransformST, - uPathTransformSTDimensions, - uPathTransformExt, - uPathTransformExtDimensions, - pathID); - - vec2 position = hintPosition(aPosition, uHints); - position = transformVertexPositionAffine(position, pathTransformST, pathTransformExt); - position = transformVertexPosition(position, uTransform); - - float depth = convertPathIndexToViewportDepthValue(pathID); - gl_Position = vec4(position, depth, 1.0); - - int vertexIndex = imod(vertexID, 3); - vec2 texCoord = vec2(float(vertexIndex) * 0.5, float(vertexIndex == 2)); - - vColor = fetchFloat4Data(uPathColors, pathID, uPathColorsDimensions); - vTexCoord = texCoord; -} diff --git a/shaders/gles2/direct-interior.fs.glsl b/shaders/gles2/direct-interior.fs.glsl deleted file mode 100644 index 99b08018..00000000 --- a/shaders/gles2/direct-interior.fs.glsl +++ /dev/null @@ -1,24 +0,0 @@ -// pathfinder/shaders/gles2/direct-interior.fs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Renders polygonal portions of a mesh. -//! -//! Typically, you will run this shader before running `direct-curve`. -//! Remember to enable the depth test with a `GREATER` depth function for optimal -//! performance. - -precision highp float; - -/// The color of this path. -varying vec4 vColor; - -void main() { - gl_FragColor = vColor; -} diff --git a/shaders/gles2/direct-interior.vs.glsl b/shaders/gles2/direct-interior.vs.glsl deleted file mode 100644 index d62c73d3..00000000 --- a/shaders/gles2/direct-interior.vs.glsl +++ /dev/null @@ -1,63 +0,0 @@ -// pathfinder/shaders/gles2/direct-interior.vs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Renders polygonal portions of a mesh. -//! -//! Typically, you will run this shader before running `direct-curve`. -//! Remember to enable the depth test with a `GREATER` depth function for optimal -//! performance. - -precision highp float; - -/// A 3D transform to be applied to all points. -uniform mat4 uTransform; -/// Vertical snapping positions. -uniform vec4 uHints; -/// The size of the path colors texture in texels. -uniform ivec2 uPathColorsDimensions; -/// The fill color for each path. -uniform sampler2D uPathColors; -/// The size of the path transform buffer texture in texels. -uniform ivec2 uPathTransformSTDimensions; -/// The path transform buffer texture, one path dilation per texel. -uniform sampler2D uPathTransformST; -/// The size of the extra path transform factors buffer texture in texels. -uniform ivec2 uPathTransformExtDimensions; -/// The extra path transform factors buffer texture, packed two path transforms per texel. -uniform sampler2D uPathTransformExt; - -/// The 2D position of this point. -attribute vec2 aPosition; -/// The path ID, starting from 1. -attribute float aPathID; - -/// The color of this path. -varying vec4 vColor; - -void main() { - int pathID = int(aPathID); - - vec2 pathTransformExt; - vec4 pathTransformST = fetchPathAffineTransform(pathTransformExt, - uPathTransformST, - uPathTransformSTDimensions, - uPathTransformExt, - uPathTransformExtDimensions, - pathID); - - vec2 position = hintPosition(aPosition, uHints); - position = transformVertexPositionAffine(position, pathTransformST, pathTransformExt); - position = transformVertexPosition(position, uTransform); - - float depth = convertPathIndexToViewportDepthValue(pathID); - gl_Position = vec4(position, depth, 1.0); - - vColor = fetchFloat4Data(uPathColors, pathID, uPathColorsDimensions); -} diff --git a/shaders/gles2/mcaa.fs.glsl b/shaders/gles2/mcaa.fs.glsl deleted file mode 100644 index 380c4c40..00000000 --- a/shaders/gles2/mcaa.fs.glsl +++ /dev/null @@ -1,31 +0,0 @@ -// pathfinder/shaders/gles2/mcaa.fs.glsl -// -// Copyright (c) 2018 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! 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. - -precision highp float; - -varying vec4 vColor; -varying vec4 vUV; -varying vec4 vSignMode; - -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)); - - float upperDist = signedDistanceToCurve(vUV.xy, dFdx(vUV.xy), dFdy(vUV.xy), inUpperCurve); - float lowerDist = signedDistanceToCurve(vUV.zw, dFdx(vUV.zw), dFdy(vUV.zw), inLowerCurve); - - float alpha = -estimateArea(upperDist * vSignMode.x) - estimateArea(lowerDist * vSignMode.y); - gl_FragColor = alpha * vColor; -} diff --git a/shaders/gles2/mcaa.vs.glsl b/shaders/gles2/mcaa.vs.glsl deleted file mode 100644 index 5e0cc1c7..00000000 --- a/shaders/gles2/mcaa.vs.glsl +++ /dev/null @@ -1,109 +0,0 @@ -// pathfinder/shaders/gles2/mcaa.vs.glsl -// -// Copyright (c) 2018 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Renders paths when performing *mesh coverage antialiasing* (MCAA). This -//! one shader handles both lines and curves. -//! -//! This shader expects to render to a standard RGB color buffer in the -//! multicolor case or a single-channel floating-point color buffer in the -//! monochrome case. -//! -//! Set state as follows depending on whether multiple overlapping multicolor -//! paths are present: -//! -//! * When paths of multiple colors are present, use -//! `glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE)` and -//! set `uMulticolor` to 1. -//! -//! * Otherwise, if only one color of path is present, use -//! `glBlendFunc(GL_ONE, GL_ONE)` and set `uMulticolor` to 0. -//! -//! Use this shader only when your transform is only a scale and/or -//! translation, not a perspective, rotation, or skew. (Otherwise, consider -//! repartitioning the path to generate a new mesh, or, alternatively, use the -//! direct Loop-Blinn shaders.) - -#define MAX_SLOPE 10.0 - -precision highp float; - -/// A scale and transform to be applied to the object. -uniform vec4 uTransformST; -uniform vec2 uTransformExt; -/// The framebuffer size in pixels. -uniform ivec2 uFramebufferSize; -/// The size of the path transform buffer texture in texels. -uniform ivec2 uPathTransformSTDimensions; -/// The path transform buffer texture, one dilation per path ID. -uniform sampler2D uPathTransformST; -uniform ivec2 uPathTransformExtDimensions; -uniform sampler2D uPathTransformExt; -/// The size of the path colors buffer texture in texels. -uniform ivec2 uPathColorsDimensions; -/// The path colors buffer texture, one color per path ID. -uniform sampler2D uPathColors; -/// True if multiple colors are being rendered; false otherwise. -/// -/// If this is true, then points will be snapped to the nearest pixel. -uniform bool uMulticolor; - -attribute vec2 aTessCoord; -attribute vec4 aRect; -attribute vec4 aUV; -attribute vec4 aDUVDX; -attribute vec4 aDUVDY; -// TODO(pcwalton): This is redundant; sign 0 can be used to indicate lines. -attribute vec4 aSignMode; -attribute float aPathID; - -varying vec4 vColor; -varying vec4 vUV; -varying vec4 vSignMode; - -void main() { - vec2 tessCoord = aTessCoord; - int pathID = int(floor(aPathID)); - - vec4 color; - if (uMulticolor) - color = fetchFloat4Data(uPathColors, pathID, uPathColorsDimensions); - else - color = vec4(1.0); - - vec2 transformExt; - vec4 transformST = fetchPathAffineTransform(transformExt, - uPathTransformST, - uPathTransformSTDimensions, - uPathTransformExt, - uPathTransformExtDimensions, - pathID); - - mat2 globalTransformLinear = mat2(uTransformST.x, uTransformExt, uTransformST.y); - mat2 localTransformLinear = mat2(transformST.x, -transformExt, transformST.y); - mat2 rectTransformLinear = mat2(aRect.z - aRect.x, 0.0, 0.0, aRect.w - aRect.y); - mat2 transformLinear = globalTransformLinear * localTransformLinear * rectTransformLinear; - - vec2 translation = transformST.zw + localTransformLinear * aRect.xy; - translation = uTransformST.zw + globalTransformLinear * translation; - - float onePixel = 2.0 / float(uFramebufferSize.y); - float dilation = length(transformVertexPositionInverseLinear(vec2(0.0, onePixel), - transformLinear)); - tessCoord.y += tessCoord.y < 0.5 ? -dilation : dilation; - - vec2 position = transformLinear * tessCoord + translation; - vec4 uv = aUV + tessCoord.x * aDUVDX + tessCoord.y * aDUVDY; - float depth = convertPathIndexToViewportDepthValue(pathID); - - gl_Position = vec4(position, depth, 1.0); - vColor = color; - vUV = uv; - vSignMode = aSignMode; -} diff --git a/shaders/gles2/ssaa-subpixel-resolve.fs.glsl b/shaders/gles2/ssaa-subpixel-resolve.fs.glsl deleted file mode 100644 index e0e31bf4..00000000 --- a/shaders/gles2/ssaa-subpixel-resolve.fs.glsl +++ /dev/null @@ -1,36 +0,0 @@ -// pathfinder/shaders/gles2/ssaa-subpixel-resolve.fs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Performs subpixel antialiasing for LCD screens by converting a -//! 3x-oversampled RGBA color buffer to an RGB framebuffer, applying the -//! FreeType color defringing filter as necessary. - -precision mediump float; - -/// The alpha coverage texture. -uniform sampler2D uSource; -/// The dimensions of the alpha coverage texture, in texels. -uniform ivec2 uSourceDimensions; -uniform vec4 uKernel; - -varying vec2 vTexCoord; - -void main() { - float onePixel = 1.0 / float(uSourceDimensions.x); - vec4 shadesL, shadesR; - float shadeC; - sample9Tap(shadesL, shadeC, shadesR, uSource, vTexCoord, onePixel, uKernel); - - vec3 shades = vec3(convolve7Tap(shadesL, vec3(shadeC, shadesR.xy), uKernel), - convolve7Tap(vec4(shadesL.yzw, shadeC), shadesR.xyz, uKernel), - convolve7Tap(vec4(shadesL.zw, shadeC, shadesR.x), shadesR.yzw, uKernel)); - - gl_FragColor = vec4(shades, 1.0); -} diff --git a/shaders/gles2/stencil-aaa.fs.glsl b/shaders/gles2/stencil-aaa.fs.glsl deleted file mode 100644 index e79e7162..00000000 --- a/shaders/gles2/stencil-aaa.fs.glsl +++ /dev/null @@ -1,46 +0,0 @@ -// pathfinder/shaders/gles2/stencil-aaa.fs.glsl -// -// Copyright (c) 2018 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -precision mediump float; - -uniform sampler2D uAreaLUT; - -varying vec2 vFrom; -varying vec2 vCtrl; -varying vec2 vTo; - -void main() { - // Unpack. - vec2 from = vFrom, ctrl = vCtrl, to = vTo; - - // Determine winding, and sort into a consistent order so we only need to find one root below. - vec2 v0 = ctrl - from, v1 = to - ctrl; - - // Shoot a vertical ray toward the curve. - vec2 window = clamp(vec2(from.x, to.x), -0.5, 0.5); - //float offset = mix(window.x, window.y, 0.5) - left.x; - //float t = offset / (v0.x + sqrt(v1.x * offset - v0.x * (offset - v0.x))); - float t = 0.5; - float x = mix(mix(from.x, ctrl.x, t), mix(ctrl.x, to.x, t), t); - float dX = 2.0 * mix(v0.x, v1.x, t); - t -= x / dX; - x = mix(mix(from.x, ctrl.x, t), mix(ctrl.x, to.x, t), t); - dX = 2.0 * mix(v0.x, v1.x, t); - t -= x / dX; - - // Compute position and derivative to form a line approximation. - float y = mix(mix(from.y, ctrl.y, t), mix(ctrl.y, to.y, t), t); - //float dYDX = mix(v0.y, v1.y, t) / mix(v0.x, v1.x, t); - float dYDX = dFdx(y); - - // Look up area under that line, and scale horizontally to the window size. - dX = (gl_FrontFacing ? 1.0 : -1.0) * (window.x - window.y); - gl_FragColor = vec4(texture2D(uAreaLUT, vec2(y + 8.0, abs(dYDX * dX)) / 16.0).r * dX); -} diff --git a/shaders/gles2/stencil-aaa.vs.glsl b/shaders/gles2/stencil-aaa.vs.glsl deleted file mode 100644 index 1cd43e34..00000000 --- a/shaders/gles2/stencil-aaa.vs.glsl +++ /dev/null @@ -1,127 +0,0 @@ -// pathfinder/shaders/gles2/stencil-aaa.vs.glsl -// -// Copyright (c) 2018 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -uniform vec4 uTransformST; -uniform vec2 uTransformExt; -uniform ivec2 uFramebufferSize; -/// Vertical snapping positions. -uniform vec4 uHints; -uniform vec2 uEmboldenAmount; -uniform ivec2 uPathBoundsDimensions; -uniform sampler2D uPathBounds; -uniform ivec2 uPathTransformSTDimensions; -uniform sampler2D uPathTransformST; -uniform ivec2 uPathTransformExtDimensions; -uniform sampler2D uPathTransformExt; -uniform int uSide; - -attribute vec2 aTessCoord; -attribute vec2 aFromPosition; -attribute vec2 aCtrlPosition; -attribute vec2 aToPosition; -attribute vec2 aFromNormal; -attribute vec2 aCtrlNormal; -attribute vec2 aToNormal; -attribute float aPathID; - -varying vec2 vFrom; -varying vec2 vCtrl; -varying vec2 vTo; - -void main() { - // Unpack. - vec2 emboldenAmount = uEmboldenAmount * 0.5; - int pathID = int(aPathID); - - // Hint positions. - vec2 from = hintPosition(aFromPosition, uHints); - vec2 ctrl = hintPosition(aCtrlPosition, uHints); - vec2 to = hintPosition(aToPosition, uHints); - - // Embolden as necessary. - from -= aFromNormal * emboldenAmount; - ctrl -= aCtrlNormal * emboldenAmount; - to -= aToNormal * emboldenAmount; - - // Fetch transform. - vec2 transformExt; - vec4 transformST = fetchPathAffineTransform(transformExt, - uPathTransformST, - uPathTransformSTDimensions, - uPathTransformExt, - uPathTransformExtDimensions, - pathID); - - // Concatenate transforms. - mat2 globalTransformLinear = mat2(uTransformST.x, uTransformExt, uTransformST.y); - mat2 localTransformLinear = mat2(transformST.x, -transformExt, transformST.y); - mat2 transformLinear = globalTransformLinear * localTransformLinear; - - // Perform the linear component of the transform (everything but translation). - from = transformLinear * from; - ctrl = transformLinear * ctrl; - to = transformLinear * to; - - // Choose correct quadrant for rotation. - vec4 bounds = fetchFloat4Data(uPathBounds, pathID, uPathBoundsDimensions); - vec2 fillVector = transformLinear * vec2(0.0, 1.0); - vec2 corner = transformLinear * vec2(fillVector.x < 0.0 ? bounds.z : bounds.x, - fillVector.y < 0.0 ? bounds.y : bounds.w); - - // Compute edge vectors. De Casteljau subdivide if necessary. - vec2 v01 = ctrl - from, v12 = to - ctrl; - float t = clamp(v01.x / (v01.x - v12.x), 0.0, 1.0); - vec2 ctrl0 = mix(from, ctrl, t), ctrl1 = mix(ctrl, to, t); - vec2 mid = mix(ctrl0, ctrl1, t); - if (uSide == 0) { - from = mid; - ctrl = ctrl1; - } else { - ctrl = ctrl0; - to = mid; - } - - // Compute position and dilate. If too thin, discard to avoid artefacts. - vec2 dilation, position; - bool zeroArea = abs(from.x - to.x) < 0.00001; - if (aTessCoord.x < 0.5) { - position.x = from.x; - dilation.x = zeroArea ? 0.0 : (from.x < to.x ? -1.0 : 1.0); - } else { - position.x = to.x; - dilation.x = zeroArea ? 0.0 : (from.x < to.x ? 1.0 : -1.0); - } - if (aTessCoord.y < 0.5) { - position.y = min(min(from.y, to.y), ctrl.y); - dilation.y = zeroArea ? 0.0 : -1.0; - } else { - position.y = corner.y; - dilation.y = 0.0; - } - position += dilation * 2.0 / vec2(uFramebufferSize); - - // Compute final position and depth. - vec2 offsetPosition = position + uTransformST.zw + globalTransformLinear * transformST.zw; - float depth = convertPathIndexToViewportDepthValue(pathID); - - // Compute transformed framebuffer size. - vec2 framebufferSizeVector = 0.5 * vec2(uFramebufferSize); - - // Finish up. - gl_Position = vec4(offsetPosition, depth, 1.0); - vCtrl = (ctrl - position) * framebufferSizeVector; - if (from.x < to.x) { - vFrom = (from - position) * framebufferSizeVector; - vTo = (to - position) * framebufferSizeVector; - } else { - vFrom = (to - position) * framebufferSizeVector; - vTo = (from - position) * framebufferSizeVector; - } -} diff --git a/shaders/gles2/xcaa-mono-resolve.fs.glsl b/shaders/gles2/xcaa-mono-resolve.fs.glsl deleted file mode 100644 index 41fe70c3..00000000 --- a/shaders/gles2/xcaa-mono-resolve.fs.glsl +++ /dev/null @@ -1,27 +0,0 @@ -// pathfinder/shaders/gles2/xcaa-mono-resolve.fs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Renders a single-channel alpha coverage buffer to an RGB framebuffer. - -precision mediump float; - -/// The background color of the monochrome path. -uniform vec4 uBGColor; -/// The foreground color of the monochrome path. -uniform vec4 uFGColor; -/// The alpha coverage texture. -uniform sampler2D uAAAlpha; - -varying vec2 vTexCoord; - -void main() { - float alpha = abs(texture2D(uAAAlpha, vTexCoord).r); - gl_FragColor = mix(uBGColor, uFGColor, alpha); -} diff --git a/shaders/gles2/xcaa-mono-resolve.vs.glsl b/shaders/gles2/xcaa-mono-resolve.vs.glsl deleted file mode 100644 index ae9e827e..00000000 --- a/shaders/gles2/xcaa-mono-resolve.vs.glsl +++ /dev/null @@ -1,30 +0,0 @@ -// pathfinder/shaders/gles2/xcaa-mono-resolve.vs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Renders a single-channel alpha coverage buffer to an RGB framebuffer. - -precision highp float; - -/// A dilation (scale and transform) to be applied to the quad. -uniform vec4 uTransformST; -/// A fixed pair of factors to be applied to the texture coordinates. -uniform vec2 uTexScale; - -/// The abstract quad position: (0.0, 0.0) to (1.0, 1.0). -attribute vec2 aPosition; -/// The texture coordinates: (0.0, 0.0) to (1.0, 1.0). -attribute vec2 aTexCoord; - -varying vec2 vTexCoord; - -void main() { - gl_Position = vec4(transformVertexPositionST(aPosition, uTransformST), -1.0, 1.0); - vTexCoord = aTexCoord * uTexScale; -} diff --git a/shaders/gles2/xcaa-mono-subpixel-resolve.fs.glsl b/shaders/gles2/xcaa-mono-subpixel-resolve.fs.glsl deleted file mode 100644 index 8eed946f..00000000 --- a/shaders/gles2/xcaa-mono-subpixel-resolve.fs.glsl +++ /dev/null @@ -1,42 +0,0 @@ -// pathfinder/shaders/gles2/xcaa-mono-subpixel-resolve.fs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Performs subpixel antialiasing for LCD screens by converting a -//! 3x-oversampled single-channel color buffer to an RGB framebuffer, applying -//! the FreeType color defringing filter as necessary. - -precision mediump float; - -/// The background color of the monochrome path. -uniform vec4 uBGColor; -/// The foreground color of the monochrome path. -uniform vec4 uFGColor; -/// The alpha coverage texture. -uniform sampler2D uAAAlpha; -/// The dimensions of the alpha coverage texture, in texels. -uniform ivec2 uAAAlphaDimensions; -uniform vec4 uKernel; - -varying vec2 vTexCoord; - -void main() { - float onePixel = 1.0 / float(uAAAlphaDimensions.x); - vec4 shadesL, shadesR; - float shadeC; - sample9Tap(shadesL, shadeC, shadesR, uAAAlpha, vTexCoord, onePixel, uKernel); - - vec3 shades = vec3(convolve7Tap(shadesL, vec3(shadeC, shadesR.xy), uKernel), - convolve7Tap(vec4(shadesL.yzw, shadeC), shadesR.xyz, uKernel), - convolve7Tap(vec4(shadesL.zw, shadeC, shadesR.x), shadesR.yzw, uKernel)); - - vec3 color = mix(uBGColor.rgb, uFGColor.rgb, shades); - float alpha = any(greaterThan(shades, vec3(0.0))) ? uFGColor.a : uBGColor.a; - gl_FragColor = alpha * vec4(color, 1.0); -} diff --git a/shaders/gles2/xcaa-mono-subpixel-resolve.vs.glsl b/shaders/gles2/xcaa-mono-subpixel-resolve.vs.glsl deleted file mode 100644 index 1f37054f..00000000 --- a/shaders/gles2/xcaa-mono-subpixel-resolve.vs.glsl +++ /dev/null @@ -1,32 +0,0 @@ -// pathfinder/shaders/gles2/xcaa-mono-subpixel-resolve.vs.glsl -// -// Copyright (c) 2017 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Performs subpixel antialiasing for LCD screens by converting a -//! 3x-oversampled single-channel color buffer to an RGB framebuffer, applying -//! the FreeType color defringing filter as necessary. - -precision highp float; - -/// A dilation (scale and transform) to be applied to the quad. -uniform vec4 uTransformST; -/// A fixed pair of factors to be applied to the texture coordinates. -uniform vec2 uTexScale; - -/// The abstract quad position: (0.0, 0.0) to (1.0, 1.0). -attribute vec2 aPosition; -/// The texture coordinates: (0.0, 0.0) to (1.0, 1.0). -attribute vec2 aTexCoord; - -varying vec2 vTexCoord; - -void main() { - gl_Position = vec4(transformVertexPositionST(aPosition, uTransformST), -1.0, 1.0); - vTexCoord = aTexCoord * uTexScale; -}