Add some OpenGL ES 2.0 shaders for direct rendering, untested

This commit is contained in:
Patrick Walton 2017-08-11 18:11:57 -07:00
parent 57ebbf8281
commit ebeaf119ba
5 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,21 @@
// pathfinder/shaders/gles2/common.inc.glsl
//
// Copyright (c) 2017 Mozilla Foundation
#define MAX_PATHS 65536
vec2 transformVertexPosition(vec2 position, mat4 transform) {
return (transform * vec4(position, 0.0, 1.0)).xy;
}
vec2 convertScreenToClipSpace(vec2 position, ivec2 framebufferSize) {
return position / vec2(framebufferSize) * 2.0 - 1.0;
}
float convertPathIndexToDepthValue(int pathIndex) {
return float(pathIndex + 1) / float(MAX_PATHS);
}
vec4 fetchFloat4Data(sampler2D dataTexture, int index, ivec2 dimensions) {
return texture2D(dataTexture, (float(index) + 0.5) / vec2(dimensions));
}

View File

@ -0,0 +1,21 @@
// pathfinder/shaders/gles2/direct-curve.fs.glsl
//
// Copyright (c) 2017 Mozilla Foundation
// This shader implements the quadratic Loop-Blinn formulation without writing precise depth.
// It is therefore unsuitable for ECAA, but it's fast (specifically, preserving early Z) and
// compatible with OpenGL ES 2.0.
#version 100
precision highp float;
varying vec4 vColor;
varying vec2 vTexCoord;
varying float vSign;
void main() {
float side = vTexCoord.x * vTexCoord.x - vTexCoord.y;
float alpha = float(sign(side) == sign(vSign));
gl_FragColor = vec4(vColor.rgb, vColor.a * alpha);
}

View File

@ -0,0 +1,41 @@
// pathfinder/shaders/gles2/direct-curve.vs.glsl
//
// Copyright (c) 2017 Mozilla Foundation
#version 100
precision highp float;
uniform mat4 uTransform;
uniform ivec2 uFramebufferSize;
uniform ivec2 uPathColorsDimensions;
uniform sampler2D uPathColors;
attribute vec2 aPosition;
attribute ivec2 aTexCoord;
attribute int aKind;
varying vec4 vColor;
varying vec2 vTexCoord;
varying float vSign;
void main() {
vec2 position = transformVertexPosition(aPosition, uTransform);
position = convertScreenToClipSpace(position, uFramebufferSize);
float depth = convertPathIndexToDepthValue(aPathIndex);
gl_Position = vec4(position, depth, 1.0);
vColor = fetchFloat4Data(uPathColors, aPathIndex, uPathColorsDimensions);
vTexCoord = vec2(aTexCoord) / 2.0;
switch (aKind) {
case PF_B_VERTEX_KIND_CONVEX_CONTROL_POINT:
vSign = -1.0;
break;
case PF_B_VERTEX_KIND_CONCAVE_CONTROL_POINT:
vSign = 1.0;
break;
default:
vSign = 0.0;
}
}

View File

@ -0,0 +1,13 @@
// pathfinder/shaders/gles2/direct-interior.fs.glsl
//
// Copyright (c) 2017 Mozilla Foundation
#version 100
precision highp float;
varying vec4 vColor;
void main() {
gl_FragColor = vColor;
}

View File

@ -0,0 +1,27 @@
// pathfinder/shaders/gles2/direct-interior.vs.glsl
//
// Copyright (c) 2017 Mozilla Foundation
#version 100
precision highp float;
uniform mat4 uTransform;
uniform ivec2 uFramebufferSize;
uniform int uMaxTextureSize;
uniform ivec2 uPathColorsDimensions;
uniform sampler2D uPathColors;
attribute vec2 aPosition;
attribute int aPathIndex;
varying vec4 vColor;
void main() {
vec2 position = transformVertexPosition(aPosition, uTransform);
position = convertScreenToClipSpace(position, uFramebufferSize);
float depth = convertPathIndexToDepthValue(aPathIndex);
gl_Position = vec4(position, depth, 1.0);
vColor = fetchFloat4Data(uPathColors, aPathIndex, uPathColorsDimensions);
}