2017-10-09 17:14:24 -04:00
|
|
|
// pathfinder/shaders/gles2/xcaa-edge-detect.fs.glsl
|
2017-08-15 20:28:07 -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-15 20:28:07 -04:00
|
|
|
|
|
|
|
precision highp float;
|
|
|
|
|
|
|
|
uniform ivec2 uFramebufferSize;
|
|
|
|
uniform sampler2D uColor;
|
2017-08-16 19:37:39 -04:00
|
|
|
uniform sampler2D uPathID;
|
2017-08-15 20:28:07 -04:00
|
|
|
|
|
|
|
varying vec2 vTexCoord;
|
|
|
|
|
2017-08-16 19:37:39 -04:00
|
|
|
void checkFG(out vec2 fgPosition, out int fgPathID, vec2 queryPosition, int queryPathID) {
|
|
|
|
if (queryPathID > fgPathID) {
|
|
|
|
fgPosition = queryPosition;
|
|
|
|
fgPathID = queryPathID;
|
|
|
|
}
|
2017-08-15 20:28:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
// Unpack.
|
|
|
|
vec2 position = vTexCoord;
|
|
|
|
|
|
|
|
// Compute positions.
|
|
|
|
vec2 onePixel = 1.0 / vec2(uFramebufferSize);
|
|
|
|
vec2 positionL = position + vec2(-onePixel.x, 0.0);
|
|
|
|
vec2 positionR = position + vec2( onePixel.x, 0.0);
|
2017-08-16 19:37:39 -04:00
|
|
|
vec2 positionB = position + vec2(0.0, -onePixel.y);
|
|
|
|
vec2 positionT = position + vec2(0.0, onePixel.y);
|
2017-08-15 20:28:07 -04:00
|
|
|
|
|
|
|
// Determine the topmost path.
|
2017-08-16 19:37:39 -04:00
|
|
|
int centerPathID = unpackPathID(texture2D(uPathID, position).rg);
|
|
|
|
ivec4 neighborPathIDs = ivec4(unpackPathID(texture2D(uPathID, positionL).rg),
|
|
|
|
unpackPathID(texture2D(uPathID, positionR).rg),
|
|
|
|
unpackPathID(texture2D(uPathID, positionB).rg),
|
|
|
|
unpackPathID(texture2D(uPathID, positionT).rg));
|
2017-08-15 20:28:07 -04:00
|
|
|
|
|
|
|
// Determine the position of the foreground color.
|
2017-08-16 19:37:39 -04:00
|
|
|
vec2 fgPosition = position;
|
|
|
|
int fgPathID = centerPathID;
|
|
|
|
checkFG(fgPosition, fgPathID, positionL, neighborPathIDs.x);
|
|
|
|
checkFG(fgPosition, fgPathID, positionR, neighborPathIDs.y);
|
|
|
|
checkFG(fgPosition, fgPathID, positionB, neighborPathIDs.z);
|
|
|
|
checkFG(fgPosition, fgPathID, positionT, neighborPathIDs.w);
|
2017-08-15 20:28:07 -04:00
|
|
|
|
|
|
|
// Determine the position of the background color.
|
|
|
|
vec2 bgPosition;
|
2017-08-16 19:37:39 -04:00
|
|
|
if (fgPathID != centerPathID)
|
|
|
|
bgPosition = position;
|
|
|
|
else if (fgPathID != neighborPathIDs.x)
|
2017-08-15 20:28:07 -04:00
|
|
|
bgPosition = positionL;
|
2017-08-16 19:37:39 -04:00
|
|
|
else if (fgPathID != neighborPathIDs.y)
|
2017-08-15 20:28:07 -04:00
|
|
|
bgPosition = positionR;
|
2017-08-16 19:37:39 -04:00
|
|
|
else if (fgPathID != neighborPathIDs.z)
|
2017-08-15 20:28:07 -04:00
|
|
|
bgPosition = positionB;
|
2017-08-16 19:37:39 -04:00
|
|
|
else
|
|
|
|
bgPosition = positionT;
|
2017-08-15 20:28:07 -04:00
|
|
|
|
|
|
|
// Determine the foreground and background colors.
|
2017-08-16 19:37:39 -04:00
|
|
|
vec4 fgColor = texture2D(uColor, fgPosition);
|
2017-08-15 20:28:07 -04:00
|
|
|
vec4 bgColor = texture2D(uColor, bgPosition);
|
|
|
|
|
|
|
|
// Determine the depth.
|
|
|
|
//
|
|
|
|
// If all colors are the same, avoid touching this pixel in any further passes.
|
2017-08-23 22:18:24 -04:00
|
|
|
float outDepth = fgColor == bgColor ? -1.0 : convertPathIndexToWindowDepthValue(fgPathID);
|
2017-08-15 20:28:07 -04:00
|
|
|
|
|
|
|
// Output results.
|
2017-08-16 19:37:39 -04:00
|
|
|
gl_FragData[0] = bgColor;
|
|
|
|
gl_FragData[1] = fgColor;
|
2017-08-15 20:28:07 -04:00
|
|
|
gl_FragDepthEXT = outDepth;
|
|
|
|
}
|