Sun shadows fix

This commit is contained in:
Lubos Lenco 2017-11-02 23:12:17 +01:00
parent 8efdc60e82
commit f610985aea
5 changed files with 27 additions and 38 deletions

View file

@ -148,11 +148,15 @@ void main() {
float visibility = 1.0;
#ifndef _NoShadows
// TODO: merge..
// float cosAngle = max(1.0 - dotNL, 0.0);
// vec3 noff = n * shadowsBias * cosAngle;
if (lightShadow == 1) {
// vec4 lampPos = LWVP * vec4(p + noff, 1.0);
vec4 lampPos = LWVP * vec4(p, 1.0);
if (lampPos.w > 0.0) visibility = shadowTest(lampPos.xyz / lampPos.w);
}
else if (lightShadow == 2) { // Cube
// visibility = shadowTestCube(lp + noff, l);
visibility = shadowTestCube(lp, l);
}
#endif

View file

@ -99,19 +99,19 @@ void main() {
vec3 albedo = surfaceAlbedo(g1.rgb, metrough.x); // g1.rgb - basecolor
vec3 f0 = surfaceF0(g1.rgb, metrough.x);
float dotNL = dot(n, l);
float visibility = 1.0;
#ifndef _NoShadows
if (lightShadow == 1) {
// float cosAngle = max(1.0 - dotNL, 0.0);
// vec3 noff = n * shadowsBias * cosAngle;
// vec4 lampPos = LWVP * vec4(p + noff, 1.0);
vec4 lampPos = LWVP * vec4(p, 1.0);
if (lampPos.w > 0.0) {
visibility = shadowTest(lampPos.xyz / lampPos.w);
}
if (lampPos.w > 0.0) visibility = shadowTest(lampPos.xyz / lampPos.w);
}
#endif
float dotNL = dot(n, l);
#ifdef _VoxelGIShadow // #else
#ifdef _VoxelGICam
vec3 voxpos = (p - eyeSnap) / voxelgiHalfExtents;

View file

@ -2186,7 +2186,7 @@ class ArmoryExporter:
o['near_plane'] = objref.arm_clip_start
o['far_plane'] = objref.arm_clip_end
o['fov'] = objref.arm_fov
o['shadows_bias'] = objref.arm_shadows_bias
o['shadows_bias'] = objref.arm_shadows_bias * 0.0001
rpdat = arm.utils.get_rp()
if rpdat.rp_shadowmap == 'None':
o['shadowmap_size'] = 0
@ -2194,12 +2194,8 @@ class ArmoryExporter:
o['shadowmap_size'] = int(rpdat.rp_shadowmap)
if o['type'] == 'sun': # Scale bias for ortho light matrix
o['shadows_bias'] *= 10.0
if (objtype == 'POINT' or objtype == 'SPOT') and objref.shadow_soft_size > 0.1: # No sun for now
lamp_size = objref.shadow_soft_size
# Slightly higher bias for high sizes
if lamp_size > 1:
o['shadows_bias'] += 0.00001 * lamp_size
o['lamp_size'] = lamp_size * 10 # Match to Cycles
if (objtype == 'POINT' or objtype == 'SPOT') and objref.shadow_soft_size > 0.1:
o['lamp_size'] = objref.shadow_soft_size * 10 # Match to Cycles
gapi = arm.utils.get_gapi()
mobile_mat = rpdat.arm_material_model == 'Mobile' or rpdat.arm_material_model == 'Solid'
if objtype == 'POINT' and objref.arm_omni_shadows and not gapi.startswith('direct3d') and not mobile_mat:
@ -2256,17 +2252,16 @@ class ArmoryExporter:
else:
return [0.051, 0.051, 0.051, 1.0]
def extract_projection(self, o, proj, with_aspect=False):
def extract_projection(self, o, proj, with_planes=True):
a = proj[0][0]
b = proj[1][1]
c = proj[2][2]
d = proj[2][3]
k = (c - 1.0) / (c + 1.0)
o['near_plane'] = (d * (1.0 - k)) / (2.0 * k)
o['far_plane'] = k * o['near_plane'];
o['fov'] = 2.0 * math.atan(1.0 / b)
if with_aspect:
o['aspect'] = b / a
if with_planes:
o['near_plane'] = (d * (1.0 - k)) / (2.0 * k)
o['far_plane'] = k * o['near_plane'];
def export_camera(self, objectRef):
o = {}
@ -2286,8 +2281,9 @@ class ArmoryExporter:
if wrd.arm_play_camera != 'Scene':
pw = self.get_viewport_panels_w() # Tool shelf and properties hidden
proj, is_persp = self.get_viewport_projection_matrix()
if (pw == 0 or ArmoryExporter.in_viewport) and is_persp:
self.extract_projection(o, proj, with_aspect=ArmoryExporter.in_viewport)
windowed = not ArmoryExporter.in_viewport
if proj != None and is_persp and (pw == 0 or windowed):
self.extract_projection(o, proj, with_planes=False)
if objref.type == 'PERSP':
o['type'] = 'perspective'
@ -2756,7 +2752,7 @@ class ArmoryExporter:
o = {}
o['name'] = 'DefaultCamera'
o['near_plane'] = 0.1
o['far_plane'] = 200.0
o['far_plane'] = 100.0
o['fov'] = 0.85
# if ArmoryExporter.in_viewport: # Wrong P returned when no camera present?
# pw = self.get_viewport_panels_w()
@ -2770,7 +2766,6 @@ class ArmoryExporter:
# o['near_plane'] = (d * (1.0 - k)) / (2.0 * k)
# o['far_plane'] = k * o['near_plane'];
# o['fov'] = 2.0 * math.atan(1.0 / b)
# o['aspect'] = b / a
o['type'] = 'perspective'
o['frustum_culling'] = True
o['render_path'] = 'armory_default/armory_default'

View file

@ -16,12 +16,7 @@ def make(context_id, rpasses, shadowmap=False):
if is_disp:
vs.append({'name': 'nor', 'size': 3})
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 })
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 })
vert = con_depth.make_vert()
frag = con_depth.make_frag()

View file

@ -16,7 +16,7 @@ except ImportError:
pass
# Armory version
arm_version = '17.10'
arm_version = '0.1.0'
def update_preset(self, context):
make_renderer.set_preset(self, context, self.rp_preset)
@ -367,7 +367,7 @@ def init_properties():
bpy.types.Lamp.arm_clip_start = bpy.props.FloatProperty(name="Clip Start", default=0.1)
bpy.types.Lamp.arm_clip_end = bpy.props.FloatProperty(name="Clip End", default=50.0)
bpy.types.Lamp.arm_fov = bpy.props.FloatProperty(name="Field of View", default=0.84)
bpy.types.Lamp.arm_shadows_bias = bpy.props.FloatProperty(name="Bias", description="Depth offset for shadow acne", default=0.0001)
bpy.types.Lamp.arm_shadows_bias = bpy.props.FloatProperty(name="Bias", description="Depth offset to fight shadow acne", default=1.0)
bpy.types.Lamp.arm_omni_shadows = bpy.props.BoolProperty(name="Omni-Shadows", description="Draw shadows to all faces of the cube map", default=True)
bpy.types.World.arm_pcfsize = bpy.props.FloatProperty(name="PCF Size", description="Filter size", default=0.001)
@ -418,14 +418,9 @@ def init_properties_on_load():
# Outdated project
if bpy.data.filepath != '' and wrd.arm_version != arm_version: # Call on project load only
print('Project updated to sdk v' + arm_version)
# TODO: deprecated - Cycles profile merged into Full
if arm_version == '17.10':
if len(wrd.arm_rplist) > 0:
rpdat = arm.utils.get_rp()
if rpdat.arm_material_model == 'Solid':
rpdat.arm_material_model = 'Mobile'
else:
rpdat.arm_material_model = 'Full'
if arm_version == '0.1.0':
for lamp in bpy.data.lamps:
lamp.arm_shadows_bias = 1.0
wrd.arm_version = arm_version
arm.make.clean_project()
# Set url for embedded player