Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2020-12-01 22:52:55 +0300
committerJulien Duroure <julien.duroure@gmail.com>2020-12-01 22:52:55 +0300
commitd5c0d4b77c15002a7e15fbe3ee146def8d11cd27 (patch)
treedaa80929484bb1eaf8d92a6c53ab4cc6820ec438 /io_scene_gltf2/blender
parent008bcf44ef35726f4c1373e46b4dd6e3a5a069e2 (diff)
glTF: implement occlusion strength (importer & exporter)
Diffstat (limited to 'io_scene_gltf2/blender')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py13
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py19
2 files changed, 31 insertions, 1 deletions
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