Add cast_shadow to lightArray data
This was done to undo the hardcoded nature of "receiveShadows", which doesn't play nice when you have multiple lights of the same type and one or several have cast_shadow set to false. By simply "passing" the cast_shadow parameter within the lightArray it was possible to detect lights that don't cast shadows before actually wasting gpu cycles to render shadows with garbage data. Support for deferred desktop and mobile, and forward was added.
This commit is contained in:
parent
26c29fe15e
commit
7463de6140
|
@ -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
|
||||
|
|
|
@ -34,7 +34,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
|
||||
|
@ -255,18 +255,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(');')
|
||||
|
|
Loading…
Reference in a new issue