From 302c62fd8888481c7a989a1697e3c47ad2353864 Mon Sep 17 00:00:00 2001 From: WestLangley Date: Thu, 23 Jul 2026 14:02:17 -0400 Subject: [PATCH] Examples: Eliminate branch divergence in volume refinement loops. (#34097) --- examples/webgl_volume_perlin.html | 13 +++---------- examples/webgpu_volume_perlin.html | 13 ++++--------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/examples/webgl_volume_perlin.html b/examples/webgl_volume_perlin.html index b58e6d19ec5340..e81c8272164e11 100644 --- a/examples/webgl_volume_perlin.html +++ b/examples/webgl_volume_perlin.html @@ -195,18 +195,11 @@ for ( int j = 0; j < REFINEMENT_STEPS; j ++ ) { float tm = ( t0 + t1 ) * 0.5; - float dm = sample1( vOrigin + tm * rayDir + 0.5 ); - if ( dm > threshold ) { - - t1 = tm; - - } else { - - t0 = tm; - - } + bool isGreater = dm > threshold; + t1 = isGreater ? tm : t1; + t0 = isGreater ? t0 : tm; } diff --git a/examples/webgpu_volume_perlin.html b/examples/webgpu_volume_perlin.html index 1790757bdb8e17..f0e53ffd5c6220 100644 --- a/examples/webgpu_volume_perlin.html +++ b/examples/webgpu_volume_perlin.html @@ -37,7 +37,7 @@