cleaned up horizontal blur code

This commit is contained in:
Valerie Wolfe 2024-04-17 10:54:58 -04:00
parent a6b1694464
commit e95c476ba4
2 changed files with 35 additions and 33 deletions

View file

@ -8,40 +8,14 @@ varying vec2 texcoord;
uniform sampler2D gcolor; uniform sampler2D gcolor;
uniform float viewWidth; uniform float viewWidth;
#ifdef hBlur #include "/module/horizontal_blur.frag"
vec2 neighbor = vec2(1 / viewWidth, 0);
float avg(float l, float c, float r) {
return (l + c + r) / 3;
}
void main() { void main() {
vec3 color = texture2D(gcolor, texcoord).rgb; #ifdef hblur
vec3 blurred = hblur();
vec2 left = texcoord - neighbor; gl_FragData[0] = vec4(blurred, 1);
vec2 right = texcoord + neighbor; #else
vec3 lColor; gl_FragData[0] = texture2D(gcolor, texcoord);
if(left.x >= 0) #endif
lColor = texture2D(gcolor, left).rgb;
else
lColor = color;
vec3 rColor;
if(right.x <= viewWidth)
rColor = texture2D(gcolor, right).rgb;
else
rColor = color;
vec3 blurred = vec3(avg(lColor.r, color.r, rColor.r), avg(lColor.g, color.g, rColor.g), avg(lColor.b, color.b, rColor.b));
gl_FragData[0] = vec4(blurred, 1);
} }
#else
void main() {
gl_FragData[0] = texture2D(gcolor, texcoord);
}
#endif

View file

@ -0,0 +1,28 @@
vec2 neighborOffset = vec2(1 / viewWidth, 0);
float avg(float l, float c, float r) {
return (l + c + r) / 3;
}
vec3 hblur() {
vec3 center = texture2D(gcolor, texcoord).rgb;
vec2 leftPos = texcoord - neigborOffset;
vec2 rightPos = texcoord + neighborOffset;
vec3 left;
if(leftPos.x >= 0)
left = texture2D(gcolor, leftPos).rgb;
else
left = center;
vec3 right;
if(rightPos.x >= 0)
right = texture2D(gcolor, rightPos).rgb;
else
right = center;
return vec3(avg(left.r, center.r, right.r), avg(left.g, center.g, right.g), avg(left.b, center.b, right.b));
}