Skip to content

Commit b2f9e68

Browse files
authored
Merge pull request #2367 from yaRnMcDonuts/master
Fix missing wViewDir variable and undeclared/wrongly declared vars
2 parents b174045 + 772f2ea commit b2f9e68

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

jme3-core/src/main/resources/Common/ShaderLib/module/pbrlighting/PBRLightingUtils.glsllib

+28-10
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
Math_lengthAndNormalize(light.vector,dist,L);
237237

238238
float invRange=light.invRadius; // position.w
239-
const float light_threshold=0.01;
239+
const float light_threshold = 0.01;
240240

241241
#ifdef SRGB
242242
light.fallOff = (1.0 - invRange * dist) / (1.0 + invRange * dist * dist); // lightDir.w
@@ -272,11 +272,26 @@
272272

273273
PBRSurface PBRLightingUtils_createPBRSurface(in vec3 wViewDir){
274274

275-
PBRSurface surface;
275+
PBRSurface surface; //creates a new PBRSurface
276+
276277
surface.position = wPosition;
277278
surface.viewDir = wViewDir;
278279
surface.geometryNormal = normalize(wNormal);
279280

281+
//set default values
282+
surface.hasTangents = false;
283+
surface.hasBasicLightMap = false;
284+
surface.albedo = vec3(1.0);
285+
surface.normal = surface.geometryNormal;
286+
surface.emission = vec3(0.0);
287+
surface.ao = vec3(1.0);
288+
surface.lightMapColor = vec3(0.0);
289+
surface.alpha = 1.0;
290+
surface.roughness = 1.0;
291+
surface.metallic = 0.0;
292+
surface.alpha = 1.0;
293+
surface.exposure = 1.0;
294+
280295
return surface;
281296
}
282297

@@ -285,9 +300,9 @@
285300

286301
void PBRLightingUtils_readPBRSurface(inout PBRSurface surface){
287302

288-
surface.bakedLightContribution = vec3(0);
289-
surface.directLightContribution = vec3(0);
290-
surface.envLightContribution = vec3(0);
303+
surface.bakedLightContribution = vec3(0.0);
304+
surface.directLightContribution = vec3(0.0);
305+
surface.envLightContribution = vec3(0.0);
291306

292307
#ifdef ENABLE_PBRLightingUtils_getWorldTangent
293308
vec3 tan = normalize(wTangent.xyz);
@@ -297,7 +312,7 @@
297312

298313

299314
#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
300-
vec3 vViewDir = wViewDir * surface.tbnMat;
315+
vec3 vViewDir = surface.viewDir * surface.tbnMat;
301316
#ifdef STEEP_PARALLAX
302317
#ifdef NORMALMAP_PARALLAX
303318
//parallax map is stored in the alpha channel of the normal map
@@ -429,7 +444,7 @@
429444
#endif
430445
surface.emission = emissive.rgb * pow(emissive.a, m_EmissivePower) * m_EmissiveIntensity;
431446
#else
432-
surface.emission = vec3(0);
447+
surface.emission = vec3(0.0);
433448
#endif
434449

435450
PBRLightingUtils_readSunLightExposureParams(surface);
@@ -573,8 +588,8 @@
573588

574589

575590
#if NB_PROBES > 0
576-
float probeNdfSum=0;
577-
float invProbeNdfSum=0;
591+
float probeNdfSum = 0.0;
592+
float invProbeNdfSum = 0.0;
578593

579594
#for i=1..4 ( #if NB_PROBES >= $i $0 #endif )
580595
vec3 probeColor$i;
@@ -607,7 +622,7 @@
607622
#endfor
608623

609624
#if NB_PROBES > 1
610-
float probeWeightSum=0;
625+
float probeWeightSum = 0.0;
611626
#for i=1..4 ( #if NB_PROBES >= $i $0 #endif )
612627
float probeWeight$i = ((1.0 - (probeNdf$i / probeNdfSum)) / (NB_PROBES - 1)) * ( probeInvNdf$i / invProbeNdfSum);
613628
probeWeightSum += probeWeight$i;
@@ -650,6 +665,9 @@
650665
else if(debugValuesMode == 7){
651666
outputColorForLayer.rgb = vec3(surface.alpha);
652667
}
668+
else if(debugValuesMode == 8){
669+
outputColorForLayer.rgb = vec3(surface.geometryNormal);
670+
}
653671

654672
if(debugValuesMode >= 0){
655673
gl_FragColor.a = 1.0;

0 commit comments

Comments
 (0)