diff --git a/demo/client/src/shader-loader.ts b/demo/client/src/shader-loader.ts index 61375704..2014c06e 100644 --- a/demo/client/src/shader-loader.ts +++ b/demo/client/src/shader-loader.ts @@ -147,11 +147,11 @@ const SHADER_URLS: ShaderMap = { }, xcaaMultiEdgeMaskCurve: { fragment: "/glsl/gles2/xcaa-multi-edge-mask-curve.fs.glsl", - vertex: "/glsl/gles2/ecaa-curve.vs.glsl", + vertex: "/glsl/gles2/ecaa-multi-edge-mask-curve.vs.glsl", }, xcaaMultiEdgeMaskLine: { fragment: "/glsl/gles2/xcaa-multi-edge-mask-line.fs.glsl", - vertex: "/glsl/gles2/ecaa-line.vs.glsl", + vertex: "/glsl/gles2/ecaa-multi-edge-mask-line.vs.glsl", }, xcaaMultiResolve: { fragment: "/glsl/gles2/xcaa-multi-resolve.fs.glsl", diff --git a/shaders/gles2/common.inc.glsl b/shaders/gles2/common.inc.glsl index a5004a12..cde9b9bb 100644 --- a/shaders/gles2/common.inc.glsl +++ b/shaders/gles2/common.inc.glsl @@ -220,6 +220,45 @@ bool computeECAAQuadPosition(out vec2 outPosition, return true; } +bool computeECAAMultiEdgeMaskQuadPosition(out vec2 outPosition, + inout vec2 leftPosition, + inout vec2 rightPosition, + vec2 quadPosition, + ivec2 framebufferSize, + vec4 localTransformST, + mat4 globalTransform) { + leftPosition = transformVertexPositionST(leftPosition, localTransformST); + rightPosition = transformVertexPositionST(rightPosition, localTransformST); + + leftPosition = transformVertexPosition(leftPosition, globalTransform); + rightPosition = transformVertexPosition(rightPosition, globalTransform); + + leftPosition = convertClipToScreenSpace(leftPosition, framebufferSize); + rightPosition = convertClipToScreenSpace(rightPosition, framebufferSize); + + float winding = sign(leftPosition.x - rightPosition.x); + if (winding > 0.0) { + vec2 tmp = leftPosition; + leftPosition = rightPosition; + rightPosition = tmp; + } + + if (rightPosition.x - leftPosition.x <= EPSILON) { + outPosition = vec2(0.0); + return false; + } + + vec2 verticalExtents = vec2(min(leftPosition.y, rightPosition.y), + max(leftPosition.y, rightPosition.y)); + + vec4 roundedExtents = vec4(floor(vec2(leftPosition.x, verticalExtents.x)), + ceil(vec2(rightPosition.x, verticalExtents.y))); + + vec2 position = mix(roundedExtents.xy, roundedExtents.zw, quadPosition); + outPosition = convertScreenToClipSpace(position, framebufferSize); + return true; +} + bool slopeIsNegative(vec2 dp) { return dp.y < 0.0; } diff --git a/shaders/gles2/ecaa-multi-edge-mask-curve.vs.glsl b/shaders/gles2/ecaa-multi-edge-mask-curve.vs.glsl new file mode 100644 index 00000000..9ca5ba40 --- /dev/null +++ b/shaders/gles2/ecaa-multi-edge-mask-curve.vs.glsl @@ -0,0 +1,54 @@ +// pathfinder/shaders/gles2/ecaa-multi-edge-mask-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. + +precision highp float; + +uniform mat4 uTransform; +uniform ivec2 uFramebufferSize; +uniform ivec2 uPathTransformDimensions; +uniform sampler2D uPathTransform; + +attribute vec2 aQuadPosition; +attribute vec2 aLeftPosition; +attribute vec2 aControlPointPosition; +attribute vec2 aRightPosition; +attribute float aPathID; + +varying vec4 vEndpoints; +varying vec2 vControlPoint; + +void main() { + vec2 leftPosition = aLeftPosition; + vec2 controlPointPosition = aControlPointPosition; + vec2 rightPosition = aRightPosition; + int pathID = int(aPathID); + + vec4 transform = fetchFloat4Data(uPathTransform, pathID, uPathTransformDimensions); + + // Transform the points, and compute the position of this vertex. + vec2 position; + if (computeECAAMultiEdgeMaskQuadPosition(position, + leftPosition, + rightPosition, + aQuadPosition, + uFramebufferSize, + transform, + uTransform)) { + controlPointPosition = transformVertexPositionST(controlPointPosition, transform); + controlPointPosition = transformVertexPosition(controlPointPosition, uTransform); + controlPointPosition = convertClipToScreenSpace(controlPointPosition, uFramebufferSize); + } + + float depth = convertPathIndexToViewportDepthValue(pathID); + + gl_Position = vec4(position, depth, 1.0); + vEndpoints = vec4(leftPosition, rightPosition); + vControlPoint = controlPointPosition; +} diff --git a/shaders/gles2/ecaa-multi-edge-mask-line.vs.glsl b/shaders/gles2/ecaa-multi-edge-mask-line.vs.glsl new file mode 100644 index 00000000..ca129bd1 --- /dev/null +++ b/shaders/gles2/ecaa-multi-edge-mask-line.vs.glsl @@ -0,0 +1,47 @@ +// pathfinder/shaders/gles2/ecaa-multi-edge-mask-line.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. + +precision highp float; + +uniform mat4 uTransform; +uniform vec4 uHints; +uniform ivec2 uFramebufferSize; +uniform ivec2 uPathTransformDimensions; +uniform sampler2D uPathTransform; + +attribute vec2 aQuadPosition; +attribute vec2 aLeftPosition; +attribute vec2 aRightPosition; +attribute float aPathID; + +varying vec4 vEndpoints; + +void main() { + vec2 leftPosition = aLeftPosition; + vec2 rightPosition = aRightPosition; + int pathID = int(aPathID); + + vec4 transform = fetchFloat4Data(uPathTransform, pathID, uPathTransformDimensions); + + // Transform the points, and compute the position of this vertex. + vec2 position; + computeECAAMultiEdgeMaskQuadPosition(position, + leftPosition, + rightPosition, + aQuadPosition, + uFramebufferSize, + transform, + uTransform); + + float depth = convertPathIndexToViewportDepthValue(pathID); + + gl_Position = vec4(position, depth, 1.0); + vEndpoints = vec4(leftPosition, rightPosition); +} diff --git a/shaders/gles2/xcaa-multi-edge-mask-curve.fs.glsl b/shaders/gles2/xcaa-multi-edge-mask-curve.fs.glsl index e5a1bee7..98a991dd 100644 --- a/shaders/gles2/xcaa-multi-edge-mask-curve.fs.glsl +++ b/shaders/gles2/xcaa-multi-edge-mask-curve.fs.glsl @@ -12,7 +12,6 @@ precision highp float; varying vec4 vEndpoints; varying vec2 vControlPoint; -varying float vWinding; void main() { // Unpack. diff --git a/shaders/gles2/xcaa-multi-edge-mask-line.fs.glsl b/shaders/gles2/xcaa-multi-edge-mask-line.fs.glsl index cf8cfc25..6b97fb43 100644 --- a/shaders/gles2/xcaa-multi-edge-mask-line.fs.glsl +++ b/shaders/gles2/xcaa-multi-edge-mask-line.fs.glsl @@ -11,7 +11,6 @@ precision highp float; varying vec4 vEndpoints; -varying float vWinding; void main() { // Unpack.