cleaned up horizontal blur code
This commit is contained in:
parent
00fc6f7c9c
commit
c165897f43
2 changed files with 35 additions and 33 deletions
|
@ -8,40 +8,14 @@ varying vec2 texcoord;
|
|||
uniform sampler2D gcolor;
|
||||
uniform float viewWidth;
|
||||
|
||||
#ifdef hBlur
|
||||
|
||||
vec2 neighbor = vec2(1 / viewWidth, 0);
|
||||
|
||||
float avg(float l, float c, float r) {
|
||||
return (l + c + r) / 3;
|
||||
}
|
||||
#include "/module/horizontal_blur.frag"
|
||||
|
||||
void main() {
|
||||
vec3 color = texture2D(gcolor, texcoord).rgb;
|
||||
|
||||
vec2 left = texcoord - neighbor;
|
||||
vec2 right = texcoord + neighbor;
|
||||
vec3 lColor;
|
||||
if(left.x >= 0)
|
||||
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);
|
||||
#ifdef hblur
|
||||
vec3 blurred = hblur();
|
||||
gl_FragData[0] = vec4(blurred, 1);
|
||||
#else
|
||||
gl_FragData[0] = texture2D(gcolor, texcoord);
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void main() {
|
||||
gl_FragData[0] = texture2D(gcolor, texcoord);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
28
shaders/module/horizontal_blur.frag
Normal file
28
shaders/module/horizontal_blur.frag
Normal 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));
|
||||
}
|
||||
|
Loading…
Reference in a new issue