Toshihiro Shimizu 890ddd
#ifdef GL_ES
Toshihiro Shimizu 890ddd
precision mediump float;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
uniform mat3 worldToOutput;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
uniform vec4 outputRect;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
varying vec4 inputRect[1];
Toshihiro Shimizu 890ddd
varying mat3 worldToInput[1];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
uniform vec2  center;
Toshihiro Shimizu 890ddd
uniform float radius;
Toshihiro Shimizu 890ddd
uniform float blur;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
float det(mat3 m) { return m[0][0] * m[1][1] - m[0][1] * m[1][0]; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
float scale     = sqrt(abs(det(worldToOutput)));
Toshihiro Shimizu 890ddd
  
Toshihiro Shimizu 890ddd
vec2  center_   = (worldToOutput * vec3(center, 1.0)).xy;
Toshihiro Shimizu 890ddd
float rad_      = scale * max(radius, 0.0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void addPoint(inout vec4 rect, vec2 p) {
Toshihiro Shimizu 890ddd
  rect.xy = min(rect.xy, p);
Toshihiro Shimizu 890ddd
  rect.zw = max(rect.zw, p);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void addBlurredPointBox(inout vec4 rect, vec2 p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
  vec2 v        = p - center_;
Toshihiro Shimizu 890ddd
  float vLength = length(v);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  float dist    = max(length(v) - rad_, 0.0);
Toshihiro Shimizu 890ddd
  float b       = blur * dist;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  v *= (b / max(vLength, 0.01));
Toshihiro Shimizu 890ddd
  
Toshihiro Shimizu 890ddd
  addPoint(rect, p - v);
Toshihiro Shimizu 890ddd
  addPoint(rect, p + v);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void main( void )
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
  worldToInput[0] = worldToOutput;                    // Let the input and output references be the same
Toshihiro Shimizu 890ddd
  inputRect[0]    = outputRect;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  // Add the bounding box of each blurred corner
Toshihiro Shimizu 890ddd
  addBlurredPointBox(inputRect[0], outputRect.xy);
Toshihiro Shimizu 890ddd
  addBlurredPointBox(inputRect[0], outputRect.xw);
Toshihiro Shimizu 890ddd
  addBlurredPointBox(inputRect[0], outputRect.zy);
Toshihiro Shimizu 890ddd
  addBlurredPointBox(inputRect[0], outputRect.zw);
Toshihiro Shimizu 890ddd
  
Toshihiro Shimizu 890ddd
  gl_Position = vec4(0.0);                            // Does not link without
Toshihiro Shimizu 890ddd
}