From 787a1b8f1ea8926c587e36e37e3416d3fa6d0e63 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Fri, 1 Feb 2019 19:22:32 +0100 Subject: glTF importer: Fix alpha usage in unlit material Using emission node + is camera ray --- .../imp/gltf2_blender_pbrMetallicRoughness.py | 34 +++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py') diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py index cfa6b83c..72a75880 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py @@ -55,8 +55,8 @@ class BlenderPbr(): main_node = node_tree.nodes.new('ShaderNodeBsdfPrincipled') main_node.location = 0, 0 elif nodetype == "unlit": - main_node = node_tree.nodes.new('ShaderNodeBackground') - main_node.location = 0, 0 + main_node = node_tree.nodes.new('ShaderNodeEmission') + main_node.location = 750, -300 if pypbr.color_type == gltf.SIMPLE: @@ -297,6 +297,32 @@ class BlenderPbr(): node_tree.links.new(metallic_text.inputs[0], metallic_mapping.outputs[0]) # link node to output - - node_tree.links.new(output_node.inputs[0], main_node.outputs[0]) + if nodetype == 'principled': + node_tree.links.new(output_node.inputs[0], main_node.outputs[0]) + elif nodetype == 'unlit': + mix = node_tree.nodes.new('ShaderNodeMixShader') + mix.location = 1000, 0 + path = node_tree.nodes.new('ShaderNodeLightPath') + path.location = 500, 300 + if pypbr.color_type != gltf.SIMPLE: + math = node_tree.nodes.new('ShaderNodeMath') + math.location = 750, 200 + math.operation = 'MULTIPLY' + + # Set material alpha mode to blend + # This is needed for Eevee + material.blend_method = 'HASHED' # TODO check best result in eevee + + transparent = node_tree.nodes.new('ShaderNodeBsdfTransparent') + transparent.location = 750, 0 + + node_tree.links.new(output_node.inputs[0], mix.outputs[0]) + node_tree.links.new(mix.inputs[2], main_node.outputs[0]) + node_tree.links.new(mix.inputs[1], transparent.outputs[0]) + if pypbr.color_type != gltf.SIMPLE: + node_tree.links.new(math.inputs[0], path.outputs[0]) + node_tree.links.new(math.inputs[1], text_node.outputs[1]) + node_tree.links.new(mix.inputs[0], math.outputs[0]) + else: + node_tree.links.new(mix.inputs[0], path.outputs[0]) -- cgit v1.2.3