pathfinder/resources/shaders/post.fs.glsl

54 lines
1.6 KiB
Plaintext
Raw Normal View History

2019-03-08 19:52:47 -05:00
#version {{version}}
// pathfinder/resources/shaders/post.fs.glsl
//
// Copyright © 2019 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.
// TODO(pcwalton): This could be significantly optimized by operating on a
// sparse per-tile basis.
precision highp float;
uniform sampler2D uSource;
uniform vec2 uFramebufferSize;
in vec2 vTexCoord;
out vec4 oFragColor;
{{{include_post_gamma_correct}}}
{{{include_post_convolve}}}
2019-02-05 23:10:20 -05:00
// Convolve horizontally in this pass.
float sample1Tap(float offset) {
return texture(uSource, vec2(vTexCoord.x + offset, vTexCoord.y)).r;
}
void main() {
2019-02-05 23:10:20 -05:00
// Apply defringing if necessary.
2019-02-08 17:37:30 -05:00
vec4 fgColor = texture(uSource, vTexCoord);
if (uKernel.w != 0.0) {
2019-02-05 23:10:20 -05:00
vec4 alphaLeft, alphaRight;
float alphaCenter;
sample9Tap(alphaLeft, alphaCenter, alphaRight, 1.0 / uFramebufferSize.x);
2019-02-08 17:37:30 -05:00
fgColor.rgb =
2019-02-05 23:10:20 -05:00
vec3(convolve7Tap(alphaLeft, vec3(alphaCenter, alphaRight.xy)),
convolve7Tap(vec4(alphaLeft.yzw, alphaCenter), alphaRight.xyz),
convolve7Tap(vec4(alphaLeft.zw, alphaCenter, alphaRight.x), alphaRight.yzw));
}
2019-02-05 23:10:20 -05:00
// Apply gamma correction if necessary.
2019-02-08 16:55:31 -05:00
if (uGammaCorrectionBGColor.a > 0.0)
2019-02-08 17:37:30 -05:00
fgColor.rgb = gammaCorrect(fgColor.rgb);
2019-02-05 23:10:20 -05:00
// Finish.
2019-02-08 17:37:30 -05:00
oFragColor = fgColor;
}