#version 150
// glow.fs
// outputs the color negative of a texture
//
in vec2 vTexCoord;
uniform int screenWidth;
uniform int screenHeight;
uniform sampler2D textureUnit0;
vec4 getTexOffset(const sampler2D texUnit, const vec2 texCoord, const float dx, const float dy){
vec2 offset = texCoord + vec2(dx, dy);
return texture(textureUnit0, offset);
}
void main(void)
{
float dx = 1.0 / float(screenWidth);
float dy = 1.0 / float (screenHeight);
float x;
float y;
vec4 blurSum = vec4(0, 0, 0, 0);
float patchSize = 4.0;
float xmin = -patchSize*dx;
float xmax = patchSize*dx+dx*0.5;
float ymin = -patchSize*dy;
float ymax = patchSize*dy+dx*0.5;
float count = 0;
for(x = xmin; x < xmax; x += dx){
for(y = ymin; y < ymax; y += dy){
blurSum += getTexOffset(textureUnit1, vTexCoord, x, y);
if(count > 1000){
discard;
}
count += 1.0;
}
}
float weight = 1.0/count;
vec4 blured = vec4(blurSum.r*weight, blurSum.g*weight, blurSum.b*weight, 1.0);
vec4 sharp = texture(textureUnit0, vTexCoord);
float luminance = blured.r + blured.g + blured.b;
if(luminance > 1.0){
gl_FragColor = blured;
}else{
gl_FragColor = sharp;
}
}
#version 150
// glow.fs
// outputs the color negative of a texture
//
in vec2 vTexCoord;
uniform int screenWidth;
uniform int screenHeight;
uniform sampler2D textureUnit0;
void luminanceTest(const sampler2D texUnit, const vec2 texCoord, const float xmin, const float xmax, const float ymin, const float ymax, const float luminance){
vec2 ll = clamp(texCoord + vec2(xmin, ymin), 0.0, 1.0);
vec2 lr = clamp(texCoord + vec2(xmax, ymin), 0.0, 1.0);
vec2 ur = clamp(texCoord + vec2(xmax, ymax), 0.0, 1.0);
vec2 ul = clamp(texCoord + vec2(xmin, ymax), 0.0, 1.0);
vec4 total = texture(texUnit, ll);
total += texture(texUnit, lr);
total += texture(texUnit, ur);
total += texture(texUnit, ul);
float weight = 1.0/4.0;
float val = (total.r + total.g + total.b)*weight;
if(val < luminance){
discard;
}
}
vec4 getTexOffset(const sampler2D texUnit, const vec2 texCoord, const float dx, const float dy){
vec2 offset = texCoord + vec2(dx, dy);
clamp(offset, 0.0, 1.0);
return texture(texUnit, offset);
}
void main(void)
{
float dx = 1.0 / float(screenWidth);
float dy = 1.0 / float (screenHeight);
float x;
float y;
vec4 blurSum = vec4(0, 0, 0, 0);
float patchSize = 4.0;
float xmin = -patchSize*dx;
float xmax = patchSize*dx+dx*0.5;
float ymin = -patchSize*dy;
float ymax = patchSize*dy+dx*0.5;
float count = 0;
luminanceTest(textureUnit0, vTexCoord, xmin, xmax, ymin, ymax, 1.0);
for(x = xmin; x < xmax; x += dx){
for(y = ymin; y < ymax; y += dy){
blurSum += getTexOffset(textureUnit0, vTexCoord, x, y);
if(count > 1000){
discard;
}
count += 1.0;
}
}
vec4 sharp = texture(textureUnit0, vTexCoord);
float weight = 1.0/count;
vec4 blured = vec4(blurSum.r*weight, blurSum.g*weight, blurSum.b*weight, sharp.a);
float luminance = blured.r + blured.g + blured.b;
if(luminance > 1.0){
gl_FragColor = blured;
}else{
gl_FragColor = sharp;
}
}
You must be logged in to post a comment.