@@ -29,7 +29,7 @@ varying vec2 v_coords;
2929uniform vec4 geo;
3030// uniform vec2 output_size;
3131uniform float corner_radius;
32- // uniform float noise;
32+ uniform float noise;
3333uniform float ignore_alpha;
3434
3535// float rounding_alpha(vec2 coords, vec2 size, float radius) {
@@ -58,13 +58,22 @@ float fast_rounding_alpha(vec2 coords, vec2 size, float radius) {
5858 return 1.0 - smoothstep (radius - 0.5 , radius + 0.5 , sdf);
5959}
6060
61- // // Noise function copied from hyprland.
62- // // I like the effect it gave, can be tweaked further
63- // float hash(vec2 p) {
64- // vec3 p3 = fract(vec3(p.xyx) * 727.727); // wysi :wink: :wink:
65- // p3 += dot(p3, p3.xyz + 33.33);
66- // return fract((p3.x + p3.y) * p3.z);
67- // }
61+ // 优化3:蓝噪声(Blue Noise)近似
62+ float blue_noise(vec2 uv) {
63+ // 使用旋转的三角波
64+ float x = uv.x * 1.61803398875 ; // 黄金比例
65+ float y = uv.y * 1.61803398875 ;
66+
67+ float noise = sin (x * 12.9898 + y * 78.233 ) * 43758.5453 ;
68+ noise = fract (noise);
69+
70+ // 添加高频分量
71+ noise += sin (x * 26.9898 + y * 92.233 ) * 43758.5453 ;
72+ noise = fract (noise) * 0.5 + 0.25 ; // 限制在[0.25, 0.75]
73+
74+ return noise - 0.5 ; // 居中在0
75+ }
76+
6877
6978void main() {
7079 vec4 color = texture2D (tex, v_coords);
@@ -86,10 +95,9 @@ void main() {
8695 vec2 size = geo.zw;
8796 vec2 loc = gl_FragCoord .xy - geo.xy;
8897
89- // // 噪声(只在alpha测试通过时添加)
90- // float noiseHash = hash(loc / size);
91- // float noise_contrib = (noiseHash - 0.5) * noise;
92- // color.rgb += noise_contrib * alphaMask; // 用alphaMask控制
98+ // 噪声(只在alpha测试通过时添加)
99+ float noise_contrib = blue_noise(loc / size) * noise * 0.08 ;
100+ color.rgb = mix (color.rgb, color.rgb + noise_contrib, alphaMask);
93101
94102 float round_alpha = fast_rounding_alpha(loc, size, corner_radius);
95103
0 commit comments