Cube shadow fixes

This commit is contained in:
luboslenco 2019-02-12 12:39:41 +01:00
parent e6e4206991
commit 24b2cc23cd
4 changed files with 14 additions and 6 deletions

View file

@ -33,8 +33,11 @@ float lpToDepth(vec3 lp, const vec2 lightProj) {
float PCFCube(samplerCubeShadow shadowMapCube, const vec3 lp, vec3 ml, const float bias, const vec2 lightProj, const vec3 n) {
const float s = shadowmapCubePcfSize; // TODO: incorrect...
float compare = lpToDepth(lp - n * bias * 80, lightProj);
ml = ml + n * bias * 80;
float compare = lpToDepth(lp, lightProj) - bias * 1.5;
ml = ml + n * bias * 20;
#ifdef HLSL
ml.y = -ml.y;
#endif
float result = texture(shadowMapCube, vec4(ml, compare));
result += texture(shadowMapCube, vec4(ml + vec3(s, s, s), compare));
result += texture(shadowMapCube, vec4(ml + vec3(-s, s, s), compare));

View file

@ -43,6 +43,9 @@ void main() {
else { // Cube
vec3 lp = lightPos - p;
vec3 l = normalize(lp);
#ifdef HLSL
l.y = -l.y;
#endif
fragColor[0] = float(texture(shadowMapCube, -l).r + shadowsBias > lpToDepth(lp, lightProj));
fragColor[1] = 0.0;
}

View file

@ -1499,7 +1499,6 @@ class ArmoryExporter:
o['strength'] *= 2.6
o['fov'] = 1.5708 # pi/2
o['shadowmap_cube'] = True
o['shadows_bias'] *= 2.0
if objref.shadow_soft_size > 0.1:
o['light_size'] = objref.shadow_soft_size * 10
elif objtype == 'SPOT':

View file

@ -403,11 +403,14 @@ def make_forward_mobile(con_mesh):
frag.add_uniform('vec2 lightProj', link='_lightPlaneProj')
frag.add_uniform('samplerCubeShadow shadowMapPoint[1]')
frag.write('const float s = shadowmapCubePcfSize;') # TODO: incorrect...
frag.write('float compare = lpToDepth(ld - n * pointBias * 80, lightProj);')
frag.write('float compare = lpToDepth(ld, lightProj) - pointBias;')
frag.write('#ifdef HLSL')
frag.write('l.y = -l.y;')
frag.write('#endif')
if '_Legacy' in wrd.world_defs:
frag.write('visibility = float(texture(shadowMapPoint[0], vec3(-l + n * pointBias * 80)).r > compare);')
frag.write('visibility = float(texture(shadowMapPoint[0], vec3(-l + n * pointBias * 20)).r > compare);')
else:
frag.write('visibility = texture(shadowMapPoint[0], vec4(-l + n * pointBias * 80, compare)).r;')
frag.write('visibility = texture(shadowMapPoint[0], vec4(-l + n * pointBias * 20, compare)).r;')
frag.write('direct += basecol * dotNL * pointCol * attenuate(distance(wposition, pointPos)) * visibility;')