44 */
55// @flow
66
7+ /**
8+ * Number of horizontal + vertical blur iterations applied.
9+ * Larger value - stronger blur effect. Low GPU impact.
10+ */
11+ const DEFAULT_BLUR_PASSES = 3
12+ /**
13+ * Spatial radius of the bilateral filter.
14+ * Larger value - smoother mask over a wider area, softer edges. High GPU impact.
15+ */
16+ const SIGMA_SPACE = 10
17+ /**
18+ * Range sensitivity of the bilateral filter.
19+ * Larger value: more smoothing across edges. Low GPU impact.
20+ */
21+ const SIGMA_COLOR = 0.15
22+ /**
23+ * Sampling stride scale for the bilateral kernel.
24+ * Larger value - faster processing, rougher mask refinement. High GPU impact.
25+ */
26+ const SPARSITY_FACTOR = 0.66
27+
728/**
829 * WebGL-based compositor for background effects.
930 * Incorporates joint bilateral filtering and multi-pass blur for improved quality.
@@ -264,8 +285,6 @@ export default class WebGLCompositor {
264285 this . blitSamplerLoc = null
265286
266287 // --- Default parameters ---
267- this . sigmaSpace = 10.0
268- this . sigmaColor = 0.15
269288 this . coverage = [ 0.45 , 0.75 ]
270289 this . lightWrapping = 0.3
271290 this . progressBarColor = [ 0 , 0.4 , 0.62 , 1 ] // Nextcloud default primary color (#00679E)
@@ -468,11 +487,10 @@ export default class WebGLCompositor {
468487 // Calculate filter parameters
469488 const texelWidth = 1 / width
470489 const texelHeight = 1 / height
471- const kSparsityFactor = 0.66
472- const step = Math . max ( 1 , Math . sqrt ( this . sigmaSpace ) * kSparsityFactor )
473- const radius = this . sigmaSpace
490+ const step = Math . max ( 1 , Math . sqrt ( SIGMA_SPACE ) * SPARSITY_FACTOR )
491+ const radius = SIGMA_SPACE
474492 const offset = step > 1 ? step * 0.5 : 0
475- const sigmaTexel = Math . max ( texelWidth , texelHeight ) * this . sigmaSpace
493+ const sigmaTexel = Math . max ( texelWidth , texelHeight ) * SIGMA_SPACE
476494
477495 // Set uniforms
478496 gl . uniform1i ( gl . getUniformLocation ( this . progBilateral , 'u_inputFrame' ) , 0 )
@@ -482,7 +500,7 @@ export default class WebGLCompositor {
482500 gl . uniform1f ( gl . getUniformLocation ( this . progBilateral , 'u_radius' ) , radius )
483501 gl . uniform1f ( gl . getUniformLocation ( this . progBilateral , 'u_offset' ) , offset )
484502 gl . uniform1f ( gl . getUniformLocation ( this . progBilateral , 'u_sigmaTexel' ) , sigmaTexel )
485- gl . uniform1f ( gl . getUniformLocation ( this . progBilateral , 'u_sigmaColor' ) , this . sigmaColor )
503+ gl . uniform1f ( gl . getUniformLocation ( this . progBilateral , 'u_sigmaColor' ) , SIGMA_COLOR )
486504
487505 // Bind textures
488506 gl . activeTexture ( gl . TEXTURE0 )
@@ -532,8 +550,7 @@ export default class WebGLCompositor {
532550 gl . activeTexture ( gl . TEXTURE1 )
533551 gl . bindTexture ( gl . TEXTURE_2D , this . texMaskFiltered )
534552
535- // Apply 3 blur passes
536- for ( let i = 0 ; i < 3 ; i ++ ) {
553+ for ( let i = 0 ; i < DEFAULT_BLUR_PASSES ; i ++ ) {
537554 // Horizontal pass
538555 gl . uniform2f ( gl . getUniformLocation ( this . progBlur , 'u_texelSize' ) , 0 , texelHeight )
539556 gl . bindFramebuffer ( gl . FRAMEBUFFER , this . fboBlur1 )
0 commit comments