From 139b7d29bd0ec621942ee4bdfb16e24bb6340e97 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Mon, 10 Feb 2025 00:34:18 -0500 Subject: [PATCH 1/4] Fix missing wViewDir variable The wViewDir varying was changed to be stored in the surfface.viewDir value, so all references in the shader needed to be updated to match this. I also changed some floats to be in decimal format. --- .../module/pbrlighting/PBRLightingUtils.glsllib | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 d943e8df67..c880f94099 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 @@ -285,9 +285,9 @@ void PBRLightingUtils_readPBRSurface(inout PBRSurface surface){ - surface.bakedLightContribution = vec3(0); - surface.directLightContribution = vec3(0); - surface.envLightContribution = vec3(0); + surface.bakedLightContribution = vec3(0.0); + surface.directLightContribution = vec3(0.0); + surface.envLightContribution = vec3(0.0); #ifdef ENABLE_PBRLightingUtils_getWorldTangent vec3 tan = normalize(wTangent.xyz); @@ -297,7 +297,7 @@ #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) - vec3 vViewDir = wViewDir * surface.tbnMat; + vec3 vViewDir = surface.viewDir * surface.tbnMat; #ifdef STEEP_PARALLAX #ifdef NORMALMAP_PARALLAX //parallax map is stored in the alpha channel of the normal map @@ -429,7 +429,7 @@ #endif surface.emission = emissive.rgb * pow(emissive.a, m_EmissivePower) * m_EmissiveIntensity; #else - surface.emission = vec3(0); + surface.emission = vec3(0.0); #endif PBRLightingUtils_readSunLightExposureParams(surface); @@ -573,8 +573,8 @@ #if NB_PROBES > 0 - float probeNdfSum=0; - float invProbeNdfSum=0; + float probeNdfSum = 0.0; + float invProbeNdfSum = 0.0; #for i=1..4 ( #if NB_PROBES >= $i $0 #endif ) vec3 probeColor$i; @@ -607,7 +607,7 @@ #endfor #if NB_PROBES > 1 - float probeWeightSum=0; + float probeWeightSum= 0.0; #for i=1..4 ( #if NB_PROBES >= $i $0 #endif ) float probeWeight$i = ((1.0 - (probeNdf$i / probeNdfSum)) / (NB_PROBES - 1)) * ( probeInvNdf$i / invProbeNdfSum); probeWeightSum += probeWeight$i; From 841cd7f77a89c64ead4096ef5f4446030c50cf4e Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Mon, 10 Feb 2025 00:44:35 -0500 Subject: [PATCH 2/4] add geometryNormal debug mode --- .../ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib | 3 +++ 1 file changed, 3 insertions(+) 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 c880f94099..5d6d61b2ef 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 @@ -650,6 +650,9 @@ else if(debugValuesMode == 7){ outputColorForLayer.rgb = vec3(surface.alpha); } + else if(debugValuesMode == 8){ + outputColorForLayer.rgb = vec3(surface.geometryNormal); + } if(debugValuesMode >= 0){ gl_FragColor.a = 1.0; From 3ddc195b056dff32e1bb2d9732f92969d3da4972 Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Mon, 10 Feb 2025 00:47:16 -0500 Subject: [PATCH 3/4] minor formatting edits --- .../ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 5d6d61b2ef..431acad822 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 @@ -236,7 +236,7 @@ Math_lengthAndNormalize(light.vector,dist,L); float invRange=light.invRadius; // position.w - const float light_threshold=0.01; + const float light_threshold = 0.01; #ifdef SRGB light.fallOff = (1.0 - invRange * dist) / (1.0 + invRange * dist * dist); // lightDir.w @@ -607,7 +607,7 @@ #endfor #if NB_PROBES > 1 - float probeWeightSum= 0.0; + float probeWeightSum = 0.0; #for i=1..4 ( #if NB_PROBES >= $i $0 #endif ) float probeWeight$i = ((1.0 - (probeNdf$i / probeNdfSum)) / (NB_PROBES - 1)) * ( probeInvNdf$i / invProbeNdfSum); probeWeightSum += probeWeight$i; From 9a1c11c719b45bda9ec04b8a2347f5db6c6d26be Mon Sep 17 00:00:00 2001 From: Ryan McDonough Date: Mon, 10 Feb 2025 03:51:44 -0500 Subject: [PATCH 4/4] Set non null values as defaults for vars in PBRSurface --- .../module/pbrlighting/PBRLightingUtils.glsllib | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 431acad822..2e64facde7 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 @@ -272,11 +272,26 @@ PBRSurface PBRLightingUtils_createPBRSurface(in vec3 wViewDir){ - PBRSurface surface; + PBRSurface surface; //creates a new PBRSurface + surface.position = wPosition; surface.viewDir = wViewDir; surface.geometryNormal = normalize(wNormal); + //set default values + surface.hasTangents = false; + surface.hasBasicLightMap = false; + surface.albedo = vec3(1.0); + surface.normal = surface.geometryNormal; + surface.emission = vec3(0.0); + surface.ao = vec3(1.0); + surface.lightMapColor = vec3(0.0); + surface.alpha = 1.0; + surface.roughness = 1.0; + surface.metallic = 0.0; + surface.alpha = 1.0; + surface.exposure = 1.0; + return surface; }