diff options
author | M. Stoeckl <manuel.stoeckl93@gmail.com> | 2019-02-04 19:03:25 +0000 |
---|---|---|
committer | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-02-04 19:03:25 +0000 |
commit | 40237b213a847cb3fabaa4da0ef2f295e9bf56a9 (patch) | |
tree | 37172e7a5d0a6de572927a8a0c57e7b34c939f3a /res | |
parent | 97e801a73e8070cfdbe317831c7264bdc149f212 (diff) | |
download | alacritty-40237b213a847cb3fabaa4da0ef2f295e9bf56a9.tar.gz alacritty-40237b213a847cb3fabaa4da0ef2f295e9bf56a9.zip |
Simplify text shader
Diffstat (limited to 'res')
-rw-r--r-- | res/text.f.glsl | 9 | ||||
-rw-r--r-- | res/text.v.glsl | 58 |
2 files changed, 31 insertions, 36 deletions
diff --git a/res/text.f.glsl b/res/text.f.glsl index 532cf929..70ad3d19 100644 --- a/res/text.f.glsl +++ b/res/text.f.glsl @@ -13,19 +13,18 @@ // limitations under the License. #version 330 core in vec2 TexCoords; -in vec3 fg; -in vec4 bg; -flat in int background; +flat in vec3 fg; +flat in vec4 bg; +uniform int backgroundPass; layout(location = 0, index = 0) out vec4 color; layout(location = 0, index = 1) out vec4 alphaMask; -uniform float bgOpacity; uniform sampler2D mask; void main() { - if (background != 0) { + if (backgroundPass != 0) { if (bg.a == 0.0) discard; diff --git a/res/text.v.glsl b/res/text.v.glsl index 32aee5ac..369e7c7e 100644 --- a/res/text.v.glsl +++ b/res/text.v.glsl @@ -12,67 +12,63 @@ // See the License for the specific language governing permissions and // limitations under the License. #version 330 core -layout (location = 0) in vec2 position; - // Cell properties -layout (location = 1) in vec2 gridCoords; +layout (location = 0) in vec2 gridCoords; // glyph properties -layout (location = 2) in vec4 glyph; +layout (location = 1) in vec4 glyph; // uv mapping -layout (location = 3) in vec4 uv; +layout (location = 2) in vec4 uv; // text fg color -layout (location = 4) in vec3 textColor; +layout (location = 3) in vec3 textColor; // Background color -layout (location = 5) in vec4 backgroundColor; +layout (location = 4) in vec4 backgroundColor; out vec2 TexCoords; -out vec3 fg; -out vec4 bg; +flat out vec3 fg; +flat out vec4 bg; // Terminal properties -uniform vec2 termDim; uniform vec2 cellDim; +uniform vec4 projection; uniform int backgroundPass; -// Orthographic projection -uniform mat4 projection; -flat out int background; void main() { - vec2 glyphOffset = glyph.xy; - vec2 glyphSize = glyph.zw; - vec2 uvOffset = uv.xy; - vec2 uvSize = uv.zw; + vec2 projectionOffset = projection.xy; + vec2 projectionScale = projection.zw; - // Position of cell from top-left - vec2 cellPosition = (cellDim) * gridCoords; + // Compute vertex corner position + vec2 position; + position.x = (gl_VertexID == 0 || gl_VertexID == 1) ? 1. : 0; + position.y = (gl_VertexID == 0 || gl_VertexID == 3) ? 0. : 1; - // Invert Y since framebuffer origin is bottom-left - cellPosition.y = termDim.y - cellPosition.y - cellDim.y; + // Position of cell from top-left + vec2 cellPosition = cellDim * gridCoords; if (backgroundPass != 0) { - cellPosition.y = cellPosition.y; - vec2 finalPosition = cellDim * position + cellPosition; - gl_Position = projection * vec4(finalPosition.xy, 0.0, 1.0); + vec2 finalPosition = cellPosition + cellDim * position; + gl_Position = vec4(projectionOffset + projectionScale * finalPosition, 0.0, 1.0); + TexCoords = vec2(0, 0); } else { - // Glyphs are offset within their cell; account for y-flip - vec2 cellOffset = vec2(glyphOffset.x, glyphOffset.y - glyphSize.y); + vec2 glyphSize = glyph.zw; + vec2 glyphOffset = glyph.xy; + glyphOffset.y = cellDim.y - glyphOffset.y; - // position coordinates are normalized on [0, 1] - vec2 finalPosition = glyphSize * position + cellPosition + cellOffset; + vec2 finalPosition = cellPosition + glyphSize * position + glyphOffset; + gl_Position = vec4(projectionOffset + projectionScale * finalPosition, 0.0, 1.0); - gl_Position = projection * vec4(finalPosition.xy, 0.0, 1.0); - TexCoords = uvOffset + vec2(position.x, 1 - position.y) * uvSize; + vec2 uvOffset = uv.xy; + vec2 uvSize = uv.zw; + TexCoords = uvOffset + position * uvSize; } - background = backgroundPass; bg = vec4(backgroundColor.rgb / 255.0, backgroundColor.a); fg = textColor / vec3(255.0, 255.0, 255.0); } |