Depth pass fix

This commit is contained in:
Lubos Lenco 2017-10-24 13:13:26 +02:00
parent e5e7a9ed8f
commit 329b838c20
7 changed files with 170 additions and 168 deletions

View file

@ -1,20 +1,165 @@
import bpy
import arm.make_state as state
import arm.material.cycles as cycles
import arm.material.mat_state as mat_state
import arm.material.mat_utils as mat_utils
import arm.material.make_skin as make_skin
import arm.material.make_tess as make_tess
import arm.material.make_particle as make_particle
import arm.material.make_mesh as make_mesh
import arm.utils
def make(context_id):
def make(context_id, rpasses, shadowmap=False):
con_depth = mat_state.data.add_context({ 'name': context_id, '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 })
is_disp = mat_utils.disp_linked(mat_state.output_node) and mat_state.material.arm_tess_shadows
vs = [{'name': 'pos', 'size': 3}]
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 })
vert = con_depth.make_vert()
frag = con_depth.make_frag()
geom = None
tesc = None
tese = None
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix')
vert.write('gl_Position = WVP * vec4(pos, 1.0);')
gapi = arm.utils.get_gapi()
if gapi == 'direct3d9':
frag.add_out('vec4 fragColor') # Definition requred for d3d9 - pixel shader must minimally write all four components of COLOR0
vert.write_main_header('vec4 spos = vec4(pos, 1.0);')
parse_opacity = 'translucent' in rpasses or mat_state.material.arm_discard
if parse_opacity:
frag.write('vec3 n;') # Discard at compile time
frag.write('float dotNV;')
frag.write('float opacity;')
if con_depth.is_elem('bone'):
make_skin.skin_pos(vert)
if con_depth.is_elem('off'):
vert.write('spos.xyz += off;')
wrd = bpy.data.worlds['Arm']
if mat_state.material.arm_particle == 'gpu':
make_particle.write(vert)
if is_disp:
tesc = con_depth.make_tesc()
tese = con_depth.make_tese()
tesc.ins = vert.outs
tese.ins = tesc.outs
frag.ins = tese.outs
vert.add_out('vec3 wposition')
vert.add_out('vec3 wnormal')
vert.add_uniform('mat4 W', '_worldMatrix')
vert.add_uniform('mat3 N', '_normalMatrix')
vert.write('wnormal = normalize(N * nor);')
vert.write('wposition = vec4(W * spos).xyz;')
make_tess.tesc_levels(tesc, mat_state.material.arm_tess_shadows_inner, mat_state.material.arm_tess_shadows_outer)
make_tess.interpolate(tese, 'wposition', 3)
make_tess.interpolate(tese, 'wnormal', 3, normalize=True)
cycles.parse(mat_state.nodes, con_depth, vert, frag, geom, tesc, tese, parse_surface=False, parse_opacity=parse_opacity)
if con_depth.is_elem('tex'):
vert.add_out('vec2 texCoord')
vert.write('texCoord = tex;')
tese.write_pre = True
make_tess.interpolate(tese, 'texCoord', 2, declare_out=frag.contains('texCoord'))
tese.write_pre = False
if con_depth.is_elem('tex1'):
vert.add_out('vec2 texCoord1')
vert.write('texCoord1 = tex1;')
tese.write_pre = True
make_tess.interpolate(tese, 'texCoord1', 2, declare_out=frag.contains('texCoord1'))
tese.write_pre = False
if con_depth.is_elem('col'):
vert.add_out('vec3 vcolor')
vert.write('vcolor = col;')
tese.write_pre = True
make_tess.interpolate(tese, 'vcolor', 3, declare_out=frag.contains('vcolor'))
tese.write_pre = False
if shadowmap:
tese.add_uniform('mat4 LVP', '_lampViewProjectionMatrix')
tese.write('wposition += wnormal * disp * 0.2;')
tese.write('gl_Position = LVP * vec4(wposition, 1.0);')
else:
tese.add_uniform('mat4 VP', '_viewProjectionMatrix')
tese.write('wposition += wnormal * disp * 0.2;')
tese.write('gl_Position = VP * vec4(wposition, 1.0);')
# No displacement
else:
frag.ins = vert.outs
billboard = mat_state.material.arm_billboard
if shadowmap:
if billboard == 'spherical':
vert.add_uniform('mat4 LWVP', '_lampWorldViewProjectionMatrixSphere')
elif billboard == 'cylindrical':
vert.add_uniform('mat4 LWVP', '_lampWorldViewProjectionMatrixCylinder')
else: # off
vert.add_uniform('mat4 LWVP', '_lampWorldViewProjectionMatrix')
vert.write('gl_Position = LWVP * spos;')
else:
if billboard == 'spherical':
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrixSphere')
elif billboard == 'cylindrical':
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrixCylinder')
else: # off
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix')
vert.write('gl_Position = WVP * spos;')
if parse_opacity:
cycles.parse(mat_state.nodes, con_depth, vert, frag, geom, tesc, tese, parse_surface=False, parse_opacity=True)
if con_depth.is_elem('tex'):
vert.add_out('vec2 texCoord')
if mat_state.material.arm_tilesheet_mat:
vert.add_uniform('vec2 tilesheetOffset', '_tilesheetOffset')
vert.write('texCoord = tex + tilesheetOffset;')
else:
vert.write('texCoord = tex;')
if con_depth.is_elem('tex1'):
vert.add_out('vec2 texCoord1')
vert.write('texCoord1 = tex1;')
if con_depth.is_elem('col'):
vert.add_out('vec3 vcolor')
vert.write('vcolor = col;')
# TODO: interleaved buffer has to match vertex structure of mesh context
if not bpy.data.worlds['Arm'].arm_deinterleaved_buffers:
con_depth.add_elem('nor', 3)
if mat_state.con_mesh != None:
if mat_state.con_mesh.is_elem('tex'):
con_depth.add_elem('tex', 2)
if mat_state.con_mesh.is_elem('tex1'):
con_depth.add_elem('tex1', 2)
if mat_state.con_mesh.is_elem('col'):
con_depth.add_elem('col', 3)
if mat_state.con_mesh.is_elem('tang'):
con_depth.add_elem('tang', 4)
# TODO: pass vbuf with proper struct
if gapi.startswith('direct3d') and bpy.data.worlds['Arm'].arm_deinterleaved_buffers == False:
vert.write('vec3 t1 = nor; // TODO: Temp for d3d')
if con_depth.is_elem('tex'):
vert.write('vec2 t2 = tex; // TODO: Temp for d3d')
if parse_opacity:
opac = mat_state.material.arm_discard_opacity_shadows
frag.write('if (opacity < {0}) discard;'.format(opac))
# frag.add_out('vec4 fragColor')
# frag.write('fragColor = vec4(0.0);')
make_mesh.make_finalize(con_depth)
return con_depth

View file

@ -14,6 +14,9 @@ write_material_attribs_post = None
write_vertex_attribs = None
def make(context_id):
rpdat = arm.utils.get_rp()
rid = rpdat.rp_renderer
con = { 'name': context_id, 'depth_write': True, 'compare_mode': 'less', 'cull_mode': 'clockwise' }
# TODO: blend context
@ -24,11 +27,14 @@ def make(context_id):
con['blend_destination'] = 'blend_one'
con['blend_operation'] = 'add'
con['depth_write'] = False
dprepass = rid == 'Forward' and rpdat.rp_depthprepass
if dprepass:
con['depth_write'] = False
con['compare_mode'] = 'equal'
con_mesh = mat_state.data.add_context(con)
mat_state.con_mesh = con_mesh
rpdat = arm.utils.get_rp()
rid = rpdat.rp_renderer
if rid == 'Forward' or blend:
if rpdat.arm_material_model == 'Mobile':
make_forward_mobile(con_mesh)

View file

@ -8,7 +8,6 @@ from arm.material.shader_data import ShaderData
import arm.material.cycles as cycles
import arm.material.make_mesh as make_mesh
import arm.material.make_rect as make_rect
import arm.material.make_shadowmap as make_shadowmap
import arm.material.make_transluc as make_transluc
import arm.material.make_overlay as make_overlay
import arm.material.make_depth as make_depth
@ -68,7 +67,7 @@ def build(material, mat_users, mat_armusers):
con = make_rect.make(rp)
elif rp == 'shadowmap':
con = make_shadowmap.make(rp, rpasses)
con = make_depth.make(rp, rpasses, shadowmap=True)
elif rp == 'translucent':
con = make_transluc.make(rp)
@ -80,7 +79,7 @@ def build(material, mat_users, mat_armusers):
con = make_decal.make(rp)
elif rp == 'depth':
con = make_depth.make(rp)
con = make_depth.make(rp, rpasses)
elif rp == 'voxel':
con = make_voxel.make(rp)

View file

@ -1,150 +0,0 @@
import bpy
import arm.material.cycles as cycles
import arm.material.mat_state as mat_state
import arm.material.mat_utils as mat_utils
import arm.material.make_skin as make_skin
import arm.material.make_tess as make_tess
import arm.material.make_particle as make_particle
import arm.material.make_mesh as make_mesh
import arm.utils
def make(context_id, rpasses):
is_disp = mat_utils.disp_linked(mat_state.output_node) and mat_state.material.arm_tess_shadows
vs = [{'name': 'pos', 'size': 3}]
if is_disp:
vs.append({'name': 'nor', 'size': 3})
con_shadowmap = 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_shadowmap.make_vert()
frag = con_shadowmap.make_frag()
geom = None
tesc = None
tese = None
gapi = arm.utils.get_gapi()
if gapi == 'direct3d9':
frag.add_out('vec4 fragColor') # Definition requred for d3d9 - pixel shader must minimally write all four components of COLOR0
vert.write_main_header('vec4 spos = vec4(pos, 1.0);')
parse_opacity = 'translucent' in rpasses or mat_state.material.arm_discard
if parse_opacity:
frag.write('vec3 n;') # Discard at compile time
frag.write('float dotNV;')
frag.write('float opacity;')
if con_shadowmap.is_elem('bone'):
make_skin.skin_pos(vert)
if con_shadowmap.is_elem('off'):
vert.write('spos.xyz += off;')
wrd = bpy.data.worlds['Arm']
if mat_state.material.arm_particle == 'gpu':
make_particle.write(vert)
if is_disp:
tesc = con_shadowmap.make_tesc()
tese = con_shadowmap.make_tese()
tesc.ins = vert.outs
tese.ins = tesc.outs
frag.ins = tese.outs
vert.add_out('vec3 wposition')
vert.add_out('vec3 wnormal')
vert.add_uniform('mat4 W', '_worldMatrix')
vert.add_uniform('mat3 N', '_normalMatrix')
vert.write('wnormal = normalize(N * nor);')
vert.write('wposition = vec4(W * spos).xyz;')
make_tess.tesc_levels(tesc, mat_state.material.arm_tess_shadows_inner, mat_state.material.arm_tess_shadows_outer)
make_tess.interpolate(tese, 'wposition', 3)
make_tess.interpolate(tese, 'wnormal', 3, normalize=True)
cycles.parse(mat_state.nodes, con_shadowmap, vert, frag, geom, tesc, tese, parse_surface=False, parse_opacity=parse_opacity)
if con_shadowmap.is_elem('tex'):
vert.add_out('vec2 texCoord')
vert.write('texCoord = tex;')
tese.write_pre = True
make_tess.interpolate(tese, 'texCoord', 2, declare_out=frag.contains('texCoord'))
tese.write_pre = False
if con_shadowmap.is_elem('tex1'):
vert.add_out('vec2 texCoord1')
vert.write('texCoord1 = tex1;')
tese.write_pre = True
make_tess.interpolate(tese, 'texCoord1', 2, declare_out=frag.contains('texCoord1'))
tese.write_pre = False
if con_shadowmap.is_elem('col'):
vert.add_out('vec3 vcolor')
vert.write('vcolor = col;')
tese.write_pre = True
make_tess.interpolate(tese, 'vcolor', 3, declare_out=frag.contains('vcolor'))
tese.write_pre = False
tese.add_uniform('mat4 LVP', '_lampViewProjectionMatrix')
tese.write('wposition += wnormal * disp * 0.2;')
tese.write('gl_Position = LVP * vec4(wposition, 1.0);')
# No displacement
else:
frag.ins = vert.outs
billboard = mat_state.material.arm_billboard
if billboard == 'spherical':
vert.add_uniform('mat4 LWVP', '_lampWorldViewProjectionMatrixSphere')
elif billboard == 'cylindrical':
vert.add_uniform('mat4 LWVP', '_lampWorldViewProjectionMatrixCylinder')
else: # off
vert.add_uniform('mat4 LWVP', '_lampWorldViewProjectionMatrix')
vert.write('gl_Position = LWVP * spos;')
if parse_opacity:
cycles.parse(mat_state.nodes, con_shadowmap, vert, frag, geom, tesc, tese, parse_surface=False, parse_opacity=True)
if con_shadowmap.is_elem('tex'):
vert.add_out('vec2 texCoord')
if mat_state.material.arm_tilesheet_mat:
vert.add_uniform('vec2 tilesheetOffset', '_tilesheetOffset')
vert.write('texCoord = tex + tilesheetOffset;')
else:
vert.write('texCoord = tex;')
if con_shadowmap.is_elem('tex1'):
vert.add_out('vec2 texCoord1')
vert.write('texCoord1 = tex1;')
if con_shadowmap.is_elem('col'):
vert.add_out('vec3 vcolor')
vert.write('vcolor = col;')
# TODO: interleaved buffer has to match vertex structure of mesh context
if not bpy.data.worlds['Arm'].arm_deinterleaved_buffers:
con_shadowmap.add_elem('nor', 3)
if mat_state.con_mesh != None:
if mat_state.con_mesh.is_elem('tex'):
con_shadowmap.add_elem('tex', 2)
if mat_state.con_mesh.is_elem('tex1'):
con_shadowmap.add_elem('tex1', 2)
if mat_state.con_mesh.is_elem('col'):
con_shadowmap.add_elem('col', 3)
if mat_state.con_mesh.is_elem('tang'):
con_shadowmap.add_elem('tang', 4)
# TODO: pass vbuf with proper struct
if gapi.startswith('direct3d') and bpy.data.worlds['Arm'].arm_deinterleaved_buffers == False:
vert.write('vec3 t1 = nor; // TODO: Temp for d3d')
if con_shadowmap.is_elem('tex'):
vert.write('vec2 t2 = tex; // TODO: Temp for d3d')
if parse_opacity:
opac = mat_state.material.arm_discard_opacity_shadows
frag.write('if (opacity < {0}) discard;'.format(opac))
# frag.write('fragColor = vec4(0.0);')
make_mesh.make_finalize(con_shadowmap)
return con_shadowmap

View file

@ -23,9 +23,6 @@ def get_rpasses(material):
ar = []
# if material.depthpass:
# ar.append('depth')
rpdat = arm.utils.get_rp()
vgirefract = rpdat.rp_gi == 'Voxel GI' and rpdat.arm_voxelgi_refraction
@ -43,7 +40,9 @@ def get_rpasses(material):
ar.append('voxel')
if rpdat.rp_renderer == 'Deferred Plus':
ar.append('rect')
if rpdat.rp_depthprepass:
ar.append('depth')
shadows_enabled = False
if rpdat.rp_shadowmap != 'None':
shadows_enabled = True

View file

@ -33,6 +33,9 @@ def invalidate_instance_cache(self, context):
for slot in context.object.material_slots:
slot.material.is_cached = False
def invalidate_compiler_cache(self, context):
bpy.data.worlds['Arm'].arm_recompile = True
def update_mat_cache(self, context):
if self.is_cached == True:
self.lock_cache = True
@ -135,8 +138,8 @@ def init_properties():
('Krom', 'Krom', 'Krom')],
name="Runtime", description="Player runtime used when launching in new window", default='Krom', update=assets.invalidate_shader_cache)
bpy.types.World.arm_loadbar = BoolProperty(name="Load Bar", description="Show asset loading progress on published builds", default=True)
bpy.types.World.arm_vsync = BoolProperty(name="VSync", description="Vertical Synchronization", default=True)
bpy.types.World.arm_dce = BoolProperty(name="DCE", description="Enable dead code elimination for publish builds", default=True)
bpy.types.World.arm_vsync = BoolProperty(name="VSync", description="Vertical Synchronization", default=True, update=invalidate_compiler_cache)
bpy.types.World.arm_dce = BoolProperty(name="DCE", description="Enable dead code elimination for publish builds", default=True, update=invalidate_compiler_cache)
bpy.types.World.arm_asset_compression = BoolProperty(name="Asset Compression", description="Enable scene data compression", default=False)
bpy.types.World.arm_winmode = EnumProperty(
items = [('Window', 'Window', 'Window'),

View file

@ -64,7 +64,7 @@ class ArmRPListItem(bpy.types.PropertyGroup):
('Deferred Plus', 'Deferred Plus', 'Deferred Plus'),
],
name="Renderer", description="Renderer type", default='Deferred', update=update_renderpath)
rp_depthprepass = bpy.props.BoolProperty(name="Depth Prepass", description="Depth Prepass for mesh context", default=False, update=update_renderpath)
rp_depthprepass = bpy.props.BoolProperty(name="Depth Prepass", description="Depth Prepass for mesh context", default=True, update=update_renderpath)
rp_hdr = bpy.props.BoolProperty(name="HDR", description="Render in HDR Space", default=True, update=update_renderpath)
rp_render_to_texture = bpy.props.BoolProperty(name="Post Process", description="Render scene to texture for further processing", default=True, update=update_renderpath)
rp_background = EnumProperty(