Merge pull request #2128 from N8n5h/light-fix-2

Fix shadows not working when there are lights present with cast_shadow=false
This commit is contained in:
Lubos Lenco 2021-03-16 08:28:19 +01:00 committed by GitHub
commit 7d78e01bb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 22 deletions

View file

@ -94,7 +94,7 @@ uniform vec3 eye;
uniform vec3 eyeLook;
#ifdef _Clusters
uniform vec4 lightsArray[maxLights * 2];
uniform vec4 lightsArray[maxLights * 3];
#ifdef _Spot
uniform vec4 lightsArraySpot[maxLights];
#endif
@ -456,18 +456,19 @@ void main() {
n,
v,
dotNV,
lightsArray[li * 2].xyz, // lp
lightsArray[li * 2 + 1].xyz, // lightCol
lightsArray[li * 3].xyz, // lp
lightsArray[li * 3 + 1].xyz, // lightCol
albedo,
roughness,
occspec.y,
f0
#ifdef _ShadowMap
, li, lightsArray[li * 2].w, true // bias
// light index, shadow bias, cast_shadows
, li, lightsArray[li * 3 + 2].x, lightsArray[li * 3 + 2].z != 0.0
#endif
#ifdef _Spot
, lightsArray[li * 2 + 1].w != 0.0
, lightsArray[li * 2 + 1].w // cutoff
, lightsArray[li * 3 + 2].y != 0.0
, lightsArray[li * 3 + 2].y // cutoff
, lightsArraySpot[li].w // cutoff - exponent
, lightsArraySpot[li].xyz // spotDir
#endif

View file

@ -37,7 +37,7 @@ uniform vec3 eye;
uniform vec3 eyeLook;
#ifdef _Clusters
uniform vec4 lightsArray[maxLights * 2];
uniform vec4 lightsArray[maxLights * 3];
#ifdef _Spot
uniform vec4 lightsArraySpot[maxLights];
#endif
@ -258,18 +258,19 @@ void main() {
n,
v,
dotNV,
lightsArray[li * 2].xyz, // lp
lightsArray[li * 2 + 1].xyz, // lightCol
lightsArray[li * 3].xyz, // lp
lightsArray[li * 3 + 1].xyz, // lightCol
albedo,
roughness,
occspec.y,
f0
#ifdef _ShadowMap
, li, lightsArray[li * 2].w, true // bias
// light index, shadow bias, cast_shadows
, li, lightsArray[li * 3 + 2].x, lightsArray[li * 3 + 2].z != 0.0
#endif
#ifdef _Spot
, lightsArray[li * 2 + 1].w != 0.0
, lightsArray[li * 2 + 1].w // cutoff
, lightsArray[li * 3 + 2].y != 0.0
, lightsArray[li * 3 + 2].y // cutoff
, lightsArraySpot[li].w // cutoff - exponent
, lightsArraySpot[li].xyz // spotDir
#endif

View file

@ -12,7 +12,7 @@ uniform sampler2D gbufferD;
uniform sampler2D snoise;
#ifdef _Clusters
uniform vec4 lightsArray[maxLights * 2];
uniform vec4 lightsArray[maxLights * 3];
#ifdef _Spot
uniform vec4 lightsArraySpot[maxLights];
#endif

View file

@ -57,7 +57,11 @@ class Inc {
break;
if (LightObject.discardLightCulled(light)) continue;
if (light.data.raw.type == "point") {
for(k in 0...light.tileOffsetX.length) {
if (!light.data.raw.cast_shadow) {
j += 4 * 6;
continue;
}
for(k in 0...6) {
LightObject.pointLightsData[j ] = light.tileOffsetX[k]; // posx
LightObject.pointLightsData[j + 1] = light.tileOffsetY[k]; // posy
LightObject.pointLightsData[j + 2] = light.tileScale[k]; // tile scale factor relative to atlas

View file

@ -9,7 +9,7 @@ def write(vert, frag):
frag.add_include_front('std/clusters.glsl')
frag.add_uniform('vec2 cameraProj', link='_cameraPlaneProj')
frag.add_uniform('vec2 cameraPlane', link='_cameraPlane')
frag.add_uniform('vec4 lightsArray[maxLights * 2]', link='_lightsArray')
frag.add_uniform('vec4 lightsArray[maxLights * 3]', link='_lightsArray')
frag.add_uniform('sampler2D clustersData', link='_clustersData')
if is_shadows:
frag.add_uniform('bool receiveShadow')
@ -56,19 +56,19 @@ def write(vert, frag):
frag.write(' n,')
frag.write(' vVec,')
frag.write(' dotNV,')
frag.write(' lightsArray[li * 2].xyz,') # lp
frag.write(' lightsArray[li * 2 + 1].xyz,') # lightCol
frag.write(' lightsArray[li * 3].xyz,') # lp
frag.write(' lightsArray[li * 3 + 1].xyz,') # lightCol
frag.write(' albedo,')
frag.write(' roughness,')
frag.write(' specular,')
frag.write(' f0')
if is_shadows:
frag.write(' , li, lightsArray[li * 2].w, receiveShadow') # bias
frag.write('\t, li, lightsArray[li * 3 + 2].x, lightsArray[li * 3 + 2].z != 0.0') # bias
if '_Spot' in wrd.world_defs:
frag.write(' , lightsArray[li * 2 + 1].w != 0.0')
frag.write(' , lightsArray[li * 2 + 1].w') # cutoff
frag.write(' , lightsArraySpot[li].w') # cutoff - exponent
frag.write(' , lightsArraySpot[li].xyz') # spotDir
frag.write('\t, lightsArray[li * 3 + 2].y != 0.0')
frag.write('\t, lightsArray[li * 3 + 2].y') # cutoff
frag.write('\t, lightsArraySpot[li].w') # cutoff - exponent
frag.write('\t, lightsArraySpot[li].xyz') # spotDir
if '_VoxelShadow' in wrd.world_defs and '_VoxelAOvar' in wrd.world_defs:
frag.write(' , voxels, voxpos')
frag.write(');')