Skip to content

Commit 05f461d

Browse files
authored
Merge pull request #5491 from EVAST9919/blob-quick-fix
CircularBlob shader improvements
2 parents 488df85 + e583d50 commit 05f461d

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

osu.Framework/Resources/Shaders/sh_CircularBlobUtils.h

+10-11
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,37 @@ highp float noise(highp vec2 st)
2424
}
2525

2626
lowp float blobAlphaAt(highp vec2 pixelPos, mediump float innerRadius, highp float texelSize, mediump float frequency, mediump float amplitude, int seed)
27-
{
27+
{
2828
// Compute angle of the current pixel in the (0, 2*PI) range
2929
mediump float pixelAngle = atan(0.5 - pixelPos.y, 0.5 - pixelPos.x) - HALF_PI;
3030
if (pixelAngle < 0.0)
3131
pixelAngle += TWO_PI;
3232

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
3437

3538
mediump float pathRadius = innerRadius * 0.25;
3639

3740
highp float shortestDistance = 1.0;
3841

39-
mediump float startAngle = pixelAngle - HALF_PI * 0.5 - HALF_PI;
42+
mediump float startAngle = pixelAngle - searchRange * 0.5;
4043

4144
// Looks to be random enough but still consistent
4245
highp vec2 noisePosition = vec2(random(vec2(float(seed) * 0.0001)) * 100000.0, random(vec2(float(seed) * 0.0001)) * 100000.0);
4346

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
4649
for (int i = 0; i < pointCount; i++)
4750
{
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));
5053

5154
highp float noiseValue = noise(noisePosition + cs * vec2(frequency));
5255
highp vec2 pos = vec2(0.5) + cs * vec2(0.5 - pathRadius - texelSize - noiseValue * 0.5 * amplitude);
5356

5457
shortestDistance = min(shortestDistance, distance(pixelPos, pos));
55-
56-
// No need to loop further if already inside the shape
57-
if (shortestDistance < pathRadius)
58-
break;
5958
}
6059

6160
return smoothstep(texelSize, 0.0, shortestDistance - pathRadius);

0 commit comments

Comments
 (0)