@@ -10,6 +10,10 @@ const float PI = 3.141592653589793;
1010const float TWO_PI = 6.283185307179586 ;
1111const float HALF_PI = 1.5707963267948966 ;
1212
13+ const float goldenAngle = 2.39996323 ;
14+ const int sampleCount = 256 ;
15+ const float sampleCountF = float (sampleCount);
16+
1317in vec2 in_uv;
1418uniform sampler2D in_texture;
1519uniform vec2 in_resolution;
@@ -18,7 +22,6 @@ uniform vec2 u_scale;
1822uniform bool u_ellipse;
1923uniform float u_angle;
2024uniform float u_radius;
21- uniform int u_samples;
2225out vec4 out_color;
2326
2427float rand(vec2 value) {
@@ -51,33 +54,19 @@ void main() {
5154
5255 vec4 result = vec4 (0.0 );
5356 float totalSamples = 0.0 ;
54-
55- // Make blur radius resolution-independent by using a percentage of image size
56- float referenceSize = min (in_resolution.x, in_resolution.y);
57- float normalizedRadius = u_radius / 100.0 ;
58- float radiusPx = normalizedRadius * referenceSize;
59- vec2 texelSize = 1.0 / in_resolution;
60-
61- int sampleCount = max (u_samples, 1 );
62- float sampleCountF = float (sampleCount);
63- float jitter = rand(in_uv * in_resolution);
64- float goldenAngle = 2.39996323 ;
57+ float jitter = rand(in_uv);
6558
6659 // Sample in a circular pattern to avoid axis-aligned artifacts
6760 for (int i = 0 ; i < sampleCount; i++ ) {
6861 float fi = float (i);
6962 float radius = sqrt ((fi + 0.5 ) / sampleCountF);
7063 float theta = (fi + jitter) * goldenAngle;
7164 vec2 direction = vec2 (cos (theta), sin (theta));
72- vec2 offset = direction * (radiusPx * radius) * texelSize;
73- vec2 sampleUV = in_uv + offset;
74-
75- if (sampleUV.x >= 0.0 && sampleUV.x <= 1.0 && sampleUV.y >= 0.0 && sampleUV.y <= 1.0 ) {
76- float weight = exp (- radius * radius * 4.0 );
77- result += texture(in_texture, sampleUV) * weight;
78- totalSamples += weight;
79- }
65+ vec2 offset = direction * (u_radius * radius);
66+ float weight = exp (- radius * radius * 4.0 );
67+ result += texture(in_texture, in_uv + offset) * weight;
68+ totalSamples += weight;
8069 }
8170
82- out_color = totalSamples > 0.0 ? result / totalSamples : texture(in_texture, in_uv) ;
71+ out_color = result / totalSamples;
8372}
0 commit comments