Add the ECAA cover shader, untested as of yet

This commit is contained in:
Patrick Walton 2017-08-16 19:51:13 -07:00
parent 4b62ec8fa7
commit 0a4d57580a
4 changed files with 92 additions and 2 deletions

View File

@ -47,6 +47,10 @@ const SHADER_URLS: ShaderMap<ShaderProgramURLs> = {
vertex: "/glsl/gles2/ecaa-resolve.vs.glsl",
fragment: "/glsl/gles2/ecaa-resolve.fs.glsl",
},
ecaaCover: {
vertex: "/glsl/gles2/ecaa-cover.vs.glsl",
fragment: "/glsl/gles2/ecaa-cover.fs.glsl",
},
};
interface UnlinkedShaderProgram {
@ -77,6 +81,7 @@ interface ShaderMap<T> {
directInterior: T;
ecaaEdgeDetect: T;
ecaaResolve: T;
ecaaCover: T;
}
interface UniformMap {

View File

@ -30,6 +30,11 @@ float convertPathIndexToDepthValue(int pathIndex) {
return mix(-1.0, 1.0, float(pathIndex) / float(MAX_PATHS));
}
int unpackUInt16(vec2 packedValue) {
ivec2 valueBytes = ivec2(floor(packedValue * 255.0));
return valueBytes.y * 256 + valueBytes.x;
}
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));
@ -39,11 +44,19 @@ vec4 fetchFloat4NormIndexedData(sampler2D dataTexture, float normIndex, ivec2 di
return fetchFloat4Data(dataTexture, int(normIndex * float(dimensions.x)), dimensions);
}
vec2 fetchFloat2Data(sampler2D dataTexture, int index, ivec2 dimensions) {
vec4 float4Data = fetchFloat4Data(dataTexture, index / 2, dimensions);
return index / 2 * 2 == index ? float4Data.xy : float4Data.zw;
}
int fetchUInt16Data(sampler2D dataTexture, int index, ivec2 dimensions) {
return unpackUInt16(fetchFloat2Data(dataTexture, index, dimensions));
}
vec2 packPathID(int pathID) {
return vec2(imod(pathID, 256), pathID / 256) / 255.0;
}
int unpackPathID(vec2 packedPathID) {
ivec2 pathIDBytes = ivec2(floor(packedPathID * 255.0));
return pathIDBytes.y * 256 + pathIDBytes.x;
return unpackUInt16(packedPathID);
}

View File

@ -0,0 +1,13 @@
// pathfinder/shaders/gles2/ecaa-cover.fs.glsl
//
// Copyright (c) 2017 Mozilla Foundation
precision highp float;
varying vec2 vHorizontalExtents;
void main() {
vec2 sides = gl_FragCoord.xx + vec2(-0.5, 0.5);
vec2 clampedSides = clamp(vHorizontalExtents, sides.x, sides.y);
gl_FragColor = vec4(vec3(clampedSides.y - clampedSides.x), 1.0);
}

View File

@ -0,0 +1,59 @@
// pathfinder/shaders/gles2/ecaa-cover.vs.glsl
//
// Copyright (c) 2017 Mozilla Foundation
precision highp float;
uniform mat4 uTransform;
uniform ivec2 uFramebufferSize;
uniform ivec2 uBVertexPositionDimensions;
uniform ivec2 uBVertexInfoDimensions;
uniform sampler2D uBVertexPosition;
uniform sampler2D uBVertexInfo;
attribute vec2 aQuadPosition;
attribute vec3 aUpperPointIndices;
attribute vec3 aLowerPointIndices;
varying vec2 vHorizontalExtents;
void main() {
// Fetch B-vertex positions.
// FIXME(pcwalton): This could be slightly optimized to fetch fewer positions.
ivec4 pointIndices = ivec4(ivec2(aUpperPointIndices.xy), ivec2(aLowerPointIndices.xy));
vec2 upperLeftPosition = fetchFloat2Data(uBVertexPosition,
pointIndices.x,
uBVertexPositionDimensions);
vec2 upperRightPosition = fetchFloat2Data(uBVertexPosition,
pointIndices.y,
uBVertexPositionDimensions);
vec2 lowerLeftPosition = fetchFloat2Data(uBVertexPosition,
pointIndices.z,
uBVertexPositionDimensions);
vec2 lowerRightPosition = fetchFloat2Data(uBVertexPosition,
pointIndices.w,
uBVertexPositionDimensions);
upperLeftPosition = transformVertexPosition(upperLeftPosition, uTransform);
upperRightPosition = transformVertexPosition(upperRightPosition, uTransform);
lowerLeftPosition = transformVertexPosition(lowerLeftPosition, uTransform);
lowerRightPosition = transformVertexPosition(lowerRightPosition, uTransform);
vec4 extents = vec4(min(upperLeftPosition.x, lowerLeftPosition.x),
min(min(upperLeftPosition.y, upperRightPosition.y),
min(lowerLeftPosition.y, lowerRightPosition.y)),
max(upperRightPosition.x, lowerRightPosition.x),
max(max(upperLeftPosition.y, upperRightPosition.y),
max(lowerLeftPosition.y, lowerRightPosition.y)));
vec4 roundedExtents = vec4(floor(extents.xy), ceil(extents.zw));
int pathID = fetchUInt16Data(uBVertexInfo, pointIndices.x, uBVertexInfoDimensions);
vec2 position = mix(roundedExtents.xy, roundedExtents.zw, aQuadPosition);
position = convertScreenToClipSpace(position, uFramebufferSize);
float depth = convertPathIndexToDepthValue(pathID);
gl_Position = vec4(position, depth, 1.0);
vHorizontalExtents = roundedExtents.xz;
}