From 8b052f21be511f27dfd654d52bcee0ea5ef5ee70 Mon Sep 17 00:00:00 2001 From: Mr Robot Date: Fri, 2 Oct 2026 19:07:55 +0200 Subject: [PATCH 1/3] Use float divisors for GLES PBR probe blending --- .../pbrlighting/PBRLightingUtils.glsllib | 6 +- .../material/PbrProbeBlendingSourceTest.java | 65 +++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java diff --git a/jme3-core/src/main/resources/Common/ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib index ddd42c08cd..6bb7867af6 100644 --- a/jme3-core/src/main/resources/Common/ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib +++ b/jme3-core/src/main/resources/Common/ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib @@ -696,11 +696,11 @@ float invNdf3 = max(1.0 - ndf3,0.0); sumNdf = max(sumNdf + ndf3, 1e-4); sumInvNdf = max(sumInvNdf + invNdf3, 1e-4); - weight3 = ((1.0 - (ndf3 / sumNdf)) / (NB_PROBES - 1)) * (invNdf3 / sumInvNdf); + weight3 = ((1.0 - (ndf3 / sumNdf)) / float(NB_PROBES - 1)) * (invNdf3 / sumInvNdf); #endif - weight1 = ((1.0 - (ndf / sumNdf)) / (NB_PROBES - 1)) * (invNdf / sumInvNdf); - weight2 = ((1.0 - (ndf2 / sumNdf)) / (NB_PROBES - 1)) * (invNdf2 / sumInvNdf); + weight1 = ((1.0 - (ndf / sumNdf)) / float(NB_PROBES - 1)) * (invNdf / sumInvNdf); + weight2 = ((1.0 - (ndf2 / sumNdf)) / float(NB_PROBES - 1)) * (invNdf2 / sumInvNdf); float weightSum = weight1 + weight2 + weight3; if (weightSum > 1e-4) { diff --git a/jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java b/jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java new file mode 100644 index 0000000000..64f7f88f28 --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2026 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.material; + +import com.jme3.asset.AssetManager; +import com.jme3.system.TestUtil; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** Checks the floating-point divisor required by GLSL ES probe blending. */ +public class PbrProbeBlendingSourceTest { + + @Test + public void probeBlendWeightsUseFloatingPointDivisors() { + AssetManager assets = TestUtil.createAssetManager(); + String source = (String) assets.loadAsset("Common/MatDefs/Light/PBRLighting.frag"); + Matcher assignments = Pattern.compile("(?m)^\\s*weight([123])\\s*=\\s*([^;]+);").matcher(source); + Set weights = new HashSet<>(); + while (assignments.find()) { + String expression = assignments.group(2); + if (expression.contains("sumNdf")) { + weights.add(assignments.group(1)); + assertTrue(expression.contains("/ float(NB_PROBES - 1)"), + "weight" + assignments.group(1) + " must not divide a float by an int"); + } + } + assertEquals(new HashSet<>(Arrays.asList("1", "2", "3")), weights); + } +} From a82e2fa92f68a0ae2790a5b60f51b3210086a3d8 Mon Sep 17 00:00:00 2001 From: Mr Robot Date: Fri, 2 Oct 2026 20:38:52 +0200 Subject: [PATCH 2/3] Allow harmless whitespace in probe divisor regression --- .../java/com/jme3/material/PbrProbeBlendingSourceTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java b/jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java index 64f7f88f28..9f1b309768 100644 --- a/jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java +++ b/jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java @@ -51,12 +51,13 @@ public void probeBlendWeightsUseFloatingPointDivisors() { AssetManager assets = TestUtil.createAssetManager(); String source = (String) assets.loadAsset("Common/MatDefs/Light/PBRLighting.frag"); Matcher assignments = Pattern.compile("(?m)^\\s*weight([123])\\s*=\\s*([^;]+);").matcher(source); + Pattern floatingPointDivisor = Pattern.compile("/\\s*float\\s*\\(\\s*NB_PROBES\\s*-\\s*1\\s*\\)"); Set weights = new HashSet<>(); while (assignments.find()) { String expression = assignments.group(2); if (expression.contains("sumNdf")) { weights.add(assignments.group(1)); - assertTrue(expression.contains("/ float(NB_PROBES - 1)"), + assertTrue(floatingPointDivisor.matcher(expression).find(), "weight" + assignments.group(1) + " must not divide a float by an int"); } } From eeb322c386af4aa793acc1025a603856e8b6a97d Mon Sep 17 00:00:00 2001 From: Mr Robot Date: Fri, 2 Oct 2026 20:53:56 +0200 Subject: [PATCH 3/3] Remove source-text test as requested in review --- .../material/PbrProbeBlendingSourceTest.java | 66 ------------------- 1 file changed, 66 deletions(-) delete mode 100644 jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java diff --git a/jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java b/jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java deleted file mode 100644 index 9f1b309768..0000000000 --- a/jme3-core/src/test/java/com/jme3/material/PbrProbeBlendingSourceTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2026 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.material; - -import com.jme3.asset.AssetManager; -import com.jme3.system.TestUtil; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** Checks the floating-point divisor required by GLSL ES probe blending. */ -public class PbrProbeBlendingSourceTest { - - @Test - public void probeBlendWeightsUseFloatingPointDivisors() { - AssetManager assets = TestUtil.createAssetManager(); - String source = (String) assets.loadAsset("Common/MatDefs/Light/PBRLighting.frag"); - Matcher assignments = Pattern.compile("(?m)^\\s*weight([123])\\s*=\\s*([^;]+);").matcher(source); - Pattern floatingPointDivisor = Pattern.compile("/\\s*float\\s*\\(\\s*NB_PROBES\\s*-\\s*1\\s*\\)"); - Set weights = new HashSet<>(); - while (assignments.find()) { - String expression = assignments.group(2); - if (expression.contains("sumNdf")) { - weights.add(assignments.group(1)); - assertTrue(floatingPointDivisor.matcher(expression).find(), - "weight" + assignments.group(1) + " must not divide a float by an int"); - } - } - assertEquals(new HashSet<>(Arrays.asList("1", "2", "3")), weights); - } -}