armory/blender/arm/material/mat_utils.py

82 lines
2.7 KiB
Python
Raw Normal View History

2017-02-07 14:55:49 +01:00
import bpy
2017-03-15 12:30:14 +01:00
import arm.utils
import arm.make_state as make_state
import arm.material.cycles as cycles
import arm.log as log
2016-12-19 01:25:22 +01:00
2017-02-09 22:52:47 +01:00
add_mesh_contexts = []
2016-12-19 01:25:22 +01:00
def disp_linked(output_node):
2017-01-14 16:32:10 +01:00
# Armory PBR with unlinked height socket
linked = output_node.inputs[2].is_linked
2017-03-15 12:30:14 +01:00
tess_enabled = arm.utils.tess_enabled(make_state.target)
2017-01-14 16:32:10 +01:00
if linked:
2016-12-19 01:25:22 +01:00
l = output_node.inputs[2].links[0]
2017-07-07 18:21:44 +02:00
if l.from_node.type == 'GROUP' and l.from_node.node_tree.name.startswith('Armory PBR') and \
2017-07-09 19:44:19 +02:00
((len(l.from_node.inputs) == 14 and l.from_node.inputs[10].is_linked == False) or (len(l.from_node.inputs) != 14 and l.from_node.inputs[7].is_linked == False)):
2016-12-19 01:25:22 +01:00
return False
2017-01-14 16:32:10 +01:00
if linked and not tess_enabled:
log.warn('Tessellation not available on ' + make_state.target)
return tess_enabled and linked
2016-12-19 01:25:22 +01:00
def get_rpasses(material):
ar = []
2017-08-21 20:16:06 +02:00
rpdat = arm.utils.get_rp()
2017-10-12 12:12:48 +02:00
vgirefract = rpdat.rp_gi == 'Voxel GI' and rpdat.arm_voxelgi_refraction
2017-08-13 20:28:06 +02:00
2017-08-21 12:17:55 +02:00
if material.arm_decal:
2017-08-23 22:53:39 +02:00
ar.append('decal')
2017-08-21 12:17:55 +02:00
elif material.arm_overlay:
2017-08-23 22:53:39 +02:00
ar.append('overlay')
2017-08-21 12:17:55 +02:00
elif is_transluc(material) and not material.arm_discard and not vgirefract:
2016-12-19 01:25:22 +01:00
ar.append('translucent')
else:
ar.append('mesh')
2017-02-09 22:52:47 +01:00
for con in add_mesh_contexts:
ar.append(con)
2017-10-12 12:12:48 +02:00
if rpdat.rp_gi == 'Voxel GI' or rpdat.rp_gi == 'Voxel AO':
2017-02-18 20:18:38 +01:00
ar.append('voxel')
2017-08-21 20:16:06 +02:00
if rpdat.rp_renderer == 'Deferred Plus':
2017-03-28 14:30:51 +02:00
ar.append('rect')
2017-11-02 14:01:53 +01:00
if rpdat.rp_renderer == 'Forward' and rpdat.rp_depthprepass:
2017-10-24 13:13:26 +02:00
ar.append('depth')
2017-02-07 14:55:49 +01:00
shadows_enabled = False
2017-11-22 21:17:36 +01:00
if rpdat.rp_shadowmap != 'Off':
2017-08-19 12:10:06 +02:00
shadows_enabled = True
2017-02-07 14:55:49 +01:00
2017-08-21 12:17:55 +02:00
if material.arm_cast_shadow and shadows_enabled and ('mesh' in ar or 'translucent' in ar):
2016-12-20 00:39:18 +01:00
ar.append('shadowmap')
2016-12-19 01:25:22 +01:00
return ar
def is_transluc(material):
nodes = material.node_tree.nodes
output_node = cycles.node_by_type(nodes, 'OUTPUT_MATERIAL')
if output_node == None or output_node.inputs[0].is_linked == False:
return False
surface_node = output_node.inputs[0].links[0].from_node
return is_transluc_traverse(surface_node)
def is_transluc_traverse(node):
2017-01-12 12:11:25 +01:00
# TODO: traverse groups
2016-12-19 01:25:22 +01:00
if is_transluc_type(node):
return True
for inp in node.inputs:
if inp.is_linked:
res = is_transluc_traverse(inp.links[0].from_node)
if res:
return True
return False
def is_transluc_type(node):
if node.type == 'BSDF_GLASS' or \
node.type == 'BSDF_TRANSPARENT' or \
node.type == 'BSDF_TRANSLUCENT' or \
2017-11-22 21:17:36 +01:00
(node.type == 'GROUP' and node.node_tree.name.startswith('Armory PBR') and (node.inputs[1].is_linked or node.inputs[1].default_value != 1.0)):
2016-12-19 01:25:22 +01:00
return True
return False