Clean up `common.inc.glsl` a bit

This commit is contained in:
Patrick Walton 2018-01-05 12:18:50 -08:00
parent f3841ef402
commit d821991c01
1 changed files with 4 additions and 49 deletions

View File

@ -22,6 +22,7 @@
precision highp float; precision highp float;
/// Returns true if the given number is close to zero.
bool isNearZero(float x) { bool isNearZero(float x) {
return abs(x) < EPSILON; return abs(x) < EPSILON;
} }
@ -111,21 +112,11 @@ float convertPathIndexToWindowDepthValue(int pathIndex) {
return float(pathIndex) / float(MAX_PATHS); return float(pathIndex) / float(MAX_PATHS);
} }
int convertWindowDepthValueToPathIndex(float depthValue) { /// Displaces the given point by the given distance in the direction of the normal angle.
float pathIndex = floor(depthValue * float(MAX_PATHS));
return int(pathIndex);
}
vec2 dilatePosition(vec2 position, float normalAngle, vec2 amount) { vec2 dilatePosition(vec2 position, float normalAngle, vec2 amount) {
return position + vec2(cos(normalAngle), -sin(normalAngle)) * amount; return position + vec2(cos(normalAngle), -sin(normalAngle)) * amount;
} }
vec2 computeXCAAClipSpaceQuadPosition(vec4 extents, vec2 quadPosition, ivec2 framebufferSize) {
// FIXME(pcwalton): Could be optimized to do only one floor/ceil per vertex.
vec2 position = mix(floor(extents.xy), ceil(extents.zw), quadPosition);
return convertScreenToClipSpace(position, framebufferSize);
}
vec2 computeMCAAPosition(vec2 position, vec2 computeMCAAPosition(vec2 position,
vec4 hints, vec4 hints,
vec4 localTransformST, vec4 localTransformST,
@ -166,38 +157,6 @@ vec2 computeMCAASnappedPosition(vec2 position,
return position + vec2(xNudge, xNudge * slope); return position + vec2(xNudge, xNudge * slope);
} }
bool computeMCAAQuadPosition(out vec2 outPosition,
inout vec2 leftPosition,
inout vec2 rightPosition,
vec2 quadPosition,
ivec2 framebufferSize,
vec4 localTransformST,
vec4 globalTransformST,
vec4 hints) {
leftPosition = computeMCAAPosition(leftPosition,
hints,
localTransformST,
globalTransformST,
framebufferSize);
rightPosition = computeMCAAPosition(rightPosition,
hints,
localTransformST,
globalTransformST,
framebufferSize);
if (abs(leftPosition.x - rightPosition.x) <= EPSILON) {
outPosition = vec2(0.0);
return false;
}
vec4 extents = vec4(leftPosition.x,
min(leftPosition.y, rightPosition.y),
rightPosition.x,
max(leftPosition.y, rightPosition.y));
outPosition = computeXCAAClipSpaceQuadPosition(extents, quadPosition, framebufferSize);
return true;
}
vec2 transformECAAPosition(vec2 position, vec2 transformECAAPosition(vec2 position,
vec4 localTransformST, vec4 localTransformST,
vec2 localTransformExt, vec2 localTransformExt,
@ -269,7 +228,8 @@ vec2 computeECAAQuadPositionFromTransformedPositions(vec2 leftPosition,
pathBottomY = (pathBottomY + 1.0) * 0.5 * float(framebufferSize.y); pathBottomY = (pathBottomY + 1.0) * 0.5 * float(framebufferSize.y);
vec4 extents = vec4(leftTopRightEdges, pathBottomY); vec4 extents = vec4(leftTopRightEdges, pathBottomY);
return computeXCAAClipSpaceQuadPosition(extents, quadPosition, framebufferSize); vec2 position = mix(floor(extents.xy), ceil(extents.zw), quadPosition);
return convertScreenToClipSpace(position, framebufferSize);
} }
// FIXME(pcwalton): Clean up this signature somehow? // FIXME(pcwalton): Clean up this signature somehow?
@ -494,11 +454,6 @@ vec3 gammaCorrect(vec3 fgColor, vec3 bgColor, sampler2D gammaLUT) {
gammaCorrectChannel(fgColor.b, bgColor.b, gammaLUT)); gammaCorrectChannel(fgColor.b, bgColor.b, gammaLUT));
} }
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) { vec4 fetchFloat4Data(sampler2D dataTexture, int index, ivec2 dimensions) {
ivec2 pixelCoord = ivec2(imod(index, dimensions.x), index / dimensions.x); ivec2 pixelCoord = ivec2(imod(index, dimensions.x), index / dimensions.x);
return texture2D(dataTexture, (vec2(pixelCoord) + 0.5) / vec2(dimensions)); return texture2D(dataTexture, (vec2(pixelCoord) + 0.5) / vec2(dimensions));