xxxxxxxxxx
59
precision mediump float;
varying vec2 vTexCoord;
uniform sampler2D uTexture0;
uniform sampler2D uTexture1;
uniform vec2 uResolution;
uniform vec2 uScale;
void main() {
vec2 uv = vTexCoord;
uv.y = 1.0 - uv.y;
// The size of a single "texel"
vec2 texelSize = 1.0 / uResolution;
// How far from each texel should we check?
vec2 offset = texelSize * uScale;
// This is called a box blur. The gist of it is that we will sum up all of the neighbor pixels and then average them.
vec4 color = vec4(0.0);
float kernel[9];
// This is an emboss kernel
kernel[0] = -2.0; kernel[1] = -1.0; kernel[2] = 0.0;
kernel[3] = -1.0; kernel[4] = 1.0; kernel[5] = 1.0;
kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 2.0;
// Top left, top middle, top right
color += texture2D(uTexture0, uv + vec2(-offset.x, -offset.y)) * kernel[0];
color += texture2D(uTexture0, uv + vec2(0.0, -offset.y)) * kernel[1];
color += texture2D(uTexture0, uv + vec2(offset.x, -offset.y)) * kernel[2];
// Left, Middle, Right
color += texture2D(uTexture0, uv + vec2(-offset.x, 0.0)) * kernel[3];
color += texture2D(uTexture0, uv) * kernel[4];
color += texture2D(uTexture0, uv + vec2(offset.x, 0.0)) * kernel[5];
// Bottom left, bottom middle, bottom right
color += texture2D(uTexture0, uv + vec2(-offset.x, offset.y)) * kernel[6];
color += texture2D(uTexture0, uv + vec2(0.0, offset.y)) * kernel[7];
color += texture2D(uTexture0, uv + vec2(offset.x, offset.y)) * kernel[8];
float kTotal = 0.0;
// Get the total number of values in the kernel
for(int i = 0; i<9; i++){
kTotal += kernel[i];
}
// Divide by the kernel total
color /= kTotal;
// Send the color to the screen
gl_FragColor = color;
}