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
|
|
|
linked = output_node.inputs[2].is_linked
|
2018-05-07 23:09:38 +02:00
|
|
|
if not linked:
|
|
|
|
return False
|
|
|
|
# Armory PBR with unlinked height socket
|
|
|
|
l = output_node.inputs[2].links[0]
|
|
|
|
if l.from_node.type == 'GROUP' and l.from_node.node_tree.name.startswith('Armory PBR') and \
|
|
|
|
l.from_node.inputs[7].is_linked == False:
|
|
|
|
return False
|
2017-11-26 14:45:36 +01:00
|
|
|
disp_enabled = arm.utils.disp_enabled(make_state.target)
|
2018-03-06 22:05:36 +01:00
|
|
|
rpdat = arm.utils.get_rp()
|
2018-05-07 23:09:38 +02:00
|
|
|
if not disp_enabled and rpdat.arm_rp_displacement == 'Tessellation':
|
2017-01-14 16:32:10 +01:00
|
|
|
log.warn('Tessellation not available on ' + make_state.target)
|
2018-05-07 23:09:38 +02:00
|
|
|
return disp_enabled
|
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()
|
2018-01-28 17:28:13 +01:00
|
|
|
has_voxels = arm.utils.voxel_support()
|
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')
|
2016-12-19 01:25:22 +01:00
|
|
|
else:
|
|
|
|
ar.append('mesh')
|
2017-02-09 22:52:47 +01:00
|
|
|
for con in add_mesh_contexts:
|
|
|
|
ar.append(con)
|
2019-01-24 12:47:51 +01:00
|
|
|
if is_transluc(material) and not material.arm_discard and rpdat.rp_translucency_state != 'Off' and not material.arm_blending:
|
|
|
|
ar.append('translucent')
|
2019-04-06 18:52:21 +02:00
|
|
|
if rpdat.rp_voxelao and has_voxels:
|
2017-02-18 20:18:38 +01:00
|
|
|
ar.append('voxel')
|
2018-08-16 17:16:35 +02:00
|
|
|
if rpdat.rp_renderer == 'Forward' and rpdat.rp_depthprepass and not material.arm_blending and not material.arm_particle_flag:
|
2017-10-24 13:13:26 +02:00
|
|
|
ar.append('depth')
|
|
|
|
|
2019-01-24 12:47:51 +01:00
|
|
|
if material.arm_cast_shadow and rpdat.rp_shadows and ('mesh' 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
|
2019-01-23 18:09:53 +01:00
|
|
|
|
|
|
|
def is_emmisive(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_emmisive_traverse(surface_node)
|
|
|
|
|
|
|
|
def is_emmisive_traverse(node):
|
|
|
|
# TODO: traverse groups
|
|
|
|
if is_emmisive_type(node):
|
|
|
|
return True
|
|
|
|
for inp in node.inputs:
|
|
|
|
if inp.is_linked:
|
|
|
|
res = is_emmisive_traverse(inp.links[0].from_node)
|
|
|
|
if res:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def is_emmisive_type(node):
|
|
|
|
if node.type == 'EMISSION' or \
|
|
|
|
(node.type == 'GROUP' and node.node_tree.name.startswith('Armory PBR') and (node.inputs[6].is_linked or node.inputs[6].default_value != 0.0)):
|
|
|
|
return True
|
|
|
|
return False
|