From d5c0d4b77c15002a7e15fbe3ee146def8d11cd27 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Tue, 1 Dec 2020 20:52:55 +0100 Subject: glTF: implement occlusion strength (importer & exporter) --- .../blender/exp/gltf2_blender_gather_texture_info.py | 13 +++++++++++++ .../blender/imp/gltf2_blender_pbrMetallicRoughness.py | 19 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'io_scene_gltf2/blender') diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py index 59cd5614..30975a3f 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py @@ -123,6 +123,19 @@ def __gather_normal_scale(primary_socket, export_settings): # MaterialOcclusionTextureInfo only def __gather_occlusion_strength(primary_socket, export_settings): + # Look for a MixRGB node that mixes with pure white in front of + # primary_socket. The mix factor gives the occlusion strength. + node = gltf2_blender_get.previous_node(primary_socket) + if node and node.type == 'MIX_RGB' and node.blend_type == 'MIX': + fac = gltf2_blender_get.get_const_from_socket(node.inputs['Fac'], kind='VALUE') + col1 = gltf2_blender_get.get_const_from_socket(node.inputs['Color1'], kind='RGB') + col2 = gltf2_blender_get.get_const_from_socket(node.inputs['Color2'], kind='RGB') + if fac is not None: + if col1 == [1, 1, 1] and col2 is None: + return fac + if col1 is None and col2 == [1, 1, 1]: + return 1.0 - fac # reversed for reversed inputs + return None diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py index 4bc584b0..21400bc0 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py @@ -433,13 +433,30 @@ def normal(mh: MaterialHelper, location, normal_socket): ) -# [Texture] => [Separate R] => +# [Texture] => [Separate R] => [Mix Strength] => def occlusion(mh: MaterialHelper, location, occlusion_socket): x, y = location if mh.pymat.occlusion_texture is None: return + strength = mh.pymat.occlusion_texture.strength + if strength is None: strength = 1.0 + if strength != 1.0: + # Mix with white + node = mh.node_tree.nodes.new('ShaderNodeMixRGB') + node.label = 'Occlusion Strength' + node.location = x - 140, y + node.blend_type = 'MIX' + # Outputs + mh.node_tree.links.new(occlusion_socket, node.outputs[0]) + # Inputs + node.inputs['Fac'].default_value = strength + node.inputs['Color1'].default_value = [1, 1, 1, 1] + occlusion_socket = node.inputs['Color2'] + + x -= 200 + # Separate RGB node = mh.node_tree.nodes.new('ShaderNodeSeparateRGB') node.location = x - 150, y - 75 -- cgit v1.2.3