Skip to content

Instantly share code, notes, and snippets.

@samhains
Created April 30, 2018 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samhains/f02244c33ebff76d34716610ae94bdca to your computer and use it in GitHub Desktop.
Save samhains/f02244c33ebff76d34716610ae94bdca to your computer and use it in GitHub Desktop.
#version 150
#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect tex, mask;
uniform vec2 direction;
in vec2 texCoordVarying;
out vec4 outputColor;
uniform int k;
void main() {
vec2 pos = texCoordVarying;
vec4 sum = texture2DRect(tex, pos);
int i;
for(i = 1; i < k; i++) {
vec2 curOffset = float(i) * direction;
vec4 leftMask = texture2DRect(mask, pos - curOffset);
vec4 rightMask = texture2DRect(mask, pos + curOffset);
bool valid = leftMask.r == 1. && rightMask.r == 1.;
if(valid) {
sum +=
texture2DRect(tex, pos + curOffset) +
texture2DRect(tex, pos - curOffset);
} else {
break;
}
}
int samples = 1 + (i - 1) * 2;
outputColor = sum / float(samples);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment