From 531885abeb4e6a03296ad3095782ffecf91ac593 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Fri, 28 Nov 2025 13:04:39 +0100 Subject: [PATCH] Optimize Vogel disk sampling sqrt. --- src/nodes/utils/PostProcessingUtils.js | 2 +- .../shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nodes/utils/PostProcessingUtils.js b/src/nodes/utils/PostProcessingUtils.js index 1d17d968021e38..ac731929191351 100644 --- a/src/nodes/utils/PostProcessingUtils.js +++ b/src/nodes/utils/PostProcessingUtils.js @@ -139,7 +139,7 @@ export const interleavedGradientNoise = Fn( ( [ position ] ) => { export const vogelDiskSample = Fn( ( [ sampleIndex, samplesCount, phi ] ) => { const goldenAngle = float( 2.399963229728653 ); // 2π * (2 - φ) where φ is golden ratio - const r = sqrt( float( sampleIndex ).add( 0.5 ) ).div( sqrt( float( samplesCount ) ) ); + const r = sqrt( float( sampleIndex ).add( 0.5 ).div( float( samplesCount ) ) ); const theta = float( sampleIndex ).mul( goldenAngle ).add( phi ); return vec2( cos( theta ), sin( theta ) ).mul( r ); diff --git a/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js b/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js index 2f798f496a73a5..ca97b9bfe434d1 100644 --- a/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +++ b/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js @@ -104,7 +104,7 @@ export default /* glsl */` vec2 vogelDiskSample( int sampleIndex, int samplesCount, float phi ) { const float goldenAngle = 2.399963229728653; - float r = sqrt( float( sampleIndex ) + 0.5 ) / sqrt( float( samplesCount ) ); + float r = sqrt( ( float( sampleIndex ) + 0.5 ) / float( samplesCount ) ); float theta = float( sampleIndex ) * goldenAngle + phi; return vec2( cos( theta ), sin( theta ) ) * r;