xxxxxxxxxx
58
precision highp float;
uniform sampler2D uTexture;
uniform vec2 uTextureSize;
uniform vec2 uCanvasSize;
uniform float uOffset;
uniform vec4 uShadeColor;
uniform float uShadeExponent;
uniform float uDeltaAngle;
varying vec2 vTexCoord;
const int BlurSampleCount = 39;
const float EPS = 1.0e-6;
vec2 Map(vec2 uv)
{
return vec2(uv.x, 1.0 - acos(2.0 * uv.y - 1.0) / PI);
}
void main()
{
float diameter = uTextureSize.y / PI;
vec2 pixCoord = floor(gl_FragCoord.xy) / (uCanvasSize - 2.0);
float dist = abs(2.0 * pixCoord.y - 1.0);
float t = pow(1.0 - pow(dist, uShadeExponent), 1.0 / uShadeExponent);
vec2 uv = fract(vTexCoord - vec2(0.0, uOffset));
vec2 sampleFrom = Map(uv);
vec4 sampledColor = texture2D(uTexture, sampleFrom);
float totalWeight = 1.0;
const int loopCount = (BlurSampleCount - 1) / 2;
for (int i = 0; i < loopCount; ++i)
{
float dist = float(i + 1) / float(loopCount);
// vec2 sampleOffset = vec2(0.0, uDeltaAngle * float(i) / uTextureSize.y);
vec2 sampleOffset = vec2(0.0, uDeltaAngle * dist);
vec2 lowerSampleFrom = Map(fract(uv + sampleOffset));
vec2 upperSampleFrom = Map(fract(uv - sampleOffset));
sampledColor += texture2D(uTexture, lowerSampleFrom);
sampledColor += texture2D(uTexture, upperSampleFrom);
totalWeight += 2.0 * (1.0 - dist);
}
sampledColor /= totalWeight;
gl_FragColor = mix(uShadeColor, sampledColor, t);
// gl_FragColor = vec4(0.0, uv.y, 1.0, 1.0);
// gl_FragColor = APPROX(gl_FragCoord.y, 100.5) ?
// vec4(1.0) : vec4(vec3(0.0), 1.0);
}