Depth cull fix

This commit is contained in:
Lubos Lenco 2017-10-31 22:49:48 +01:00
parent 6a4a82b5aa
commit f123a7b1eb
2 changed files with 12 additions and 6 deletions

View file

@ -43,20 +43,21 @@ float PCF(const vec2 uv, const float compare) {
}
float lpToDepth(vec3 lp, const vec2 lightPlane) {
// TODO: precompute..
float d = lightPlane.y - lightPlane.x;
// TODO: pass uniforms
float a = lightPlane.y + lightPlane.x;
float b = lightPlane.y - lightPlane.x;
float c = 2.0 * lightPlane.y * lightPlane.x;
lp = abs(lp);
float zcomp = max(lp.x, max(lp.y, lp.z));
zcomp = (lightPlane.y + lightPlane.x) / (d) - (2.0 * lightPlane.y * lightPlane.x) / (d) / zcomp;
zcomp = a / b - c / b / zcomp;
return zcomp * 0.5 + 0.5;
}
float PCFCube(const vec3 lp, const vec3 ml, const float bias, const vec2 lightPlane) {
// return float(texture(shadowMapCube, ml).r + bias > lpToDepth(lp, lightPlane));
const float s = shadowmapCubePcfSize; // 0.001 TODO: incorrect...
float compare = lpToDepth(lp, lightPlane) - bias;
float result = step(compare, texture(shadowMapCube, ml).r);
const float s = shadowmapCubePcfSize; // 0.001 TODO: incorrect...
result += step(compare, texture(shadowMapCube, ml + vec3(s, s, s)).r);
result += step(compare, texture(shadowMapCube, ml + vec3(-s, s, s)).r);
result += step(compare, texture(shadowMapCube, ml + vec3(s, -s, s)).r);

View file

@ -16,7 +16,12 @@ def make(context_id, rpasses, shadowmap=False):
if is_disp:
vs.append({'name': 'nor', 'size': 3})
con_depth = mat_state.data.add_context({ 'name': context_id, 'vertex_structure': vs, 'depth_write': True, 'compare_mode': 'less', 'cull_mode': 'clockwise', 'color_write_red': False, 'color_write_green': False, 'color_write_blue': False, 'color_write_alpha': False })
if not shadowmap or mat_state.material.arm_two_sided or mat_state.material.arm_cull_mode == 'none':
cull_mode = 'clockwise'
else:
cull_mode = 'counter_clockwise'
con_depth = mat_state.data.add_context({ 'name': context_id, 'vertex_structure': vs, 'depth_write': True, 'compare_mode': 'less', 'cull_mode': cull_mode, 'color_write_red': False, 'color_write_green': False, 'color_write_blue': False, 'color_write_alpha': False })
vert = con_depth.make_vert()
frag = con_depth.make_frag()