@@ -24,38 +24,37 @@ highp float noise(highp vec2 st)
24
24
}
25
25
26
26
lowp float blobAlphaAt (highp vec2 pixelPos , mediump float innerRadius , highp float texelSize , mediump float frequency , mediump float amplitude , int seed )
27
- {
27
+ {
28
28
// Compute angle of the current pixel in the (0, 2*PI) range
29
29
mediump float pixelAngle = atan (0.5 - pixelPos .y , 0.5 - pixelPos .x ) - HALF_PI ;
30
30
if (pixelAngle < 0.0 )
31
31
pixelAngle += TWO_PI ;
32
32
33
- const int pointCount = 50 ;
33
+ mediump float complexity = (frequency + amplitude ) * 0.5 + 1.0 ;
34
+
35
+ int pointCount = int (ceil (5.0 * complexity ));
36
+ mediump float searchRange = 0.1 * complexity ; // in radians
34
37
35
38
mediump float pathRadius = innerRadius * 0.25 ;
36
39
37
40
highp float shortestDistance = 1.0 ;
38
41
39
- mediump float startAngle = pixelAngle - HALF_PI * 0.5 - HALF_PI ;
42
+ mediump float startAngle = pixelAngle - searchRange * 0.5 ;
40
43
41
44
// Looks to be random enough but still consistent
42
45
highp vec2 noisePosition = vec2 (random (vec2 (float (seed ) * 0.0001 )) * 100000.0 , random (vec2 (float (seed ) * 0.0001 )) * 100000.0 );
43
46
44
- // Distance approximation
45
- // Plot points within a search range (90 degrees seems enough) and check which one is closest
47
+ // Path approximation
48
+ // Plot points within a search range and check which one is closest
46
49
for (int i = 0 ; i < pointCount ; i ++ )
47
50
{
48
- mediump float angle = startAngle + HALF_PI * float (i ) / float (pointCount );
49
- highp vec2 cs = vec2 (cos (angle ), sin (angle ));
51
+ mediump float angle = startAngle + searchRange * float (i ) / float (pointCount );
52
+ highp vec2 cs = vec2 (cos (angle - HALF_PI ), sin (angle - HALF_PI ));
50
53
51
54
highp float noiseValue = noise (noisePosition + cs * vec2 (frequency ));
52
55
highp vec2 pos = vec2 (0.5 ) + cs * vec2 (0.5 - pathRadius - texelSize - noiseValue * 0.5 * amplitude );
53
56
54
57
shortestDistance = min (shortestDistance , distance (pixelPos , pos ));
55
-
56
- // No need to loop further if already inside the shape
57
- if (shortestDistance < pathRadius )
58
- break ;
59
58
}
60
59
61
60
return smoothstep (texelSize , 0.0 , shortestDistance - pathRadius );
0 commit comments