|
shun_iwasawa |
36e06f |
#ifdef GL_ES
|
|
shun_iwasawa |
36e06f |
precision mediump float;
|
|
shun_iwasawa |
36e06f |
#endif
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
uniform vec4 infiniteRect;
|
|
shun_iwasawa |
36e06f |
uniform vec4 inputBBox[1];
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
varying vec4 outputBBox;
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
uniform vec2 center;
|
|
shun_iwasawa |
36e06f |
uniform float radius;
|
|
shun_iwasawa |
36e06f |
uniform float blur;
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
const float pi = 3.141592653;
|
|
shun_iwasawa |
36e06f |
const float pi_twice = 2.0 * pi;
|
|
shun_iwasawa |
36e06f |
const float pi_half = pi / 2.0;
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
void addPoint(inout vec4 rect, vec2 p) {
|
|
shun_iwasawa |
36e06f |
rect.xy = min(rect.xy, p.xy);
|
|
shun_iwasawa |
36e06f |
rect.zw = max(rect.zw, p.xy);
|
|
shun_iwasawa |
36e06f |
}
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
void addBlurredPointBox(inout vec4 rect, vec2 p)
|
|
shun_iwasawa |
36e06f |
{
|
|
shun_iwasawa |
36e06f |
// Remember the *definition* of angle: angle = arc length / radius
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
// Build p's blurred angular range
|
|
shun_iwasawa |
36e06f |
float distance = length(p - center);
|
|
shun_iwasawa |
36e06f |
float angle = atan(p.y - center.y, p.x - center.x);
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
// If radius > 0, we assume that the blurred length is proportional to (distance - radius);
|
|
shun_iwasawa |
36e06f |
float dist_ = max(distance - radius, 0.0);
|
|
shun_iwasawa |
36e06f |
float blurLen = radians(max(blur, 0.0)) * dist_;
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
// The actual blurring angle is then found as (blurLen_ / distance)
|
|
shun_iwasawa |
36e06f |
float blur_ = blurLen / max(distance, 0.01); // Jump the singularity
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
vec2 angleRange = vec2(angle - blur_, angle + blur_); // Couldn't make it an array with
|
|
shun_iwasawa |
36e06f |
// explicit initialization... GLSL complained -.-
|
|
shun_iwasawa |
36e06f |
// Include the points at angleRange's extremes
|
|
shun_iwasawa |
36e06f |
addPoint(rect, center + distance * vec2(cos(angleRange.x), sin(angleRange.x)));
|
|
shun_iwasawa |
36e06f |
addPoint(rect, center + distance * vec2(cos(angleRange.y), sin(angleRange.y)));
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
// At pi/2 multiples we get a box extreme. Include them if present.
|
|
shun_iwasawa |
36e06f |
float blur_twice = 2.0 * blur_;
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
if(mod( - angleRange.x, pi_twice) < blur_twice)
|
|
shun_iwasawa |
36e06f |
addPoint(rect, center + vec2(distance, 0.0));
|
|
shun_iwasawa |
36e06f |
if(mod(pi_half - angleRange.x, pi_twice) < blur_twice)
|
|
shun_iwasawa |
36e06f |
addPoint(rect, center + vec2(0.0, distance));
|
|
shun_iwasawa |
36e06f |
if(mod(pi - angleRange.x, pi_twice) < blur_twice)
|
|
shun_iwasawa |
36e06f |
addPoint(rect, center + vec2(-distance, 0.0));
|
|
shun_iwasawa |
36e06f |
if(mod(-pi_half - angleRange.x, pi_twice) < blur_twice)
|
|
shun_iwasawa |
36e06f |
addPoint(rect, center + vec2(0.0, -distance));
|
|
shun_iwasawa |
36e06f |
}
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
void main( void )
|
|
shun_iwasawa |
36e06f |
{
|
|
shun_iwasawa |
36e06f |
outputBBox = inputBBox[0];
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
if(outputBBox != infiniteRect)
|
|
shun_iwasawa |
36e06f |
{
|
|
shun_iwasawa |
36e06f |
// Add the bounding box of each blurred corner
|
|
shun_iwasawa |
36e06f |
addBlurredPointBox(outputBBox, inputBBox[0].xy);
|
|
shun_iwasawa |
36e06f |
addBlurredPointBox(outputBBox, inputBBox[0].xw);
|
|
shun_iwasawa |
36e06f |
addBlurredPointBox(outputBBox, inputBBox[0].zy);
|
|
shun_iwasawa |
36e06f |
addBlurredPointBox(outputBBox, inputBBox[0].zw);
|
|
shun_iwasawa |
36e06f |
}
|
|
shun_iwasawa |
36e06f |
|
|
shun_iwasawa |
36e06f |
gl_Position = vec4(0.0); // Does not link without
|
|
shun_iwasawa |
36e06f |
}
|