diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2020-09-16 19:00:14 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2020-09-17 16:23:03 +0300 |
commit | f3cf3a16e989eb2b407be466be8ecb2aa951275c (patch) | |
tree | 723d63bdb4df6152a20c81ca84b578ee5cdebece /io_scene_gltf2/blender | |
parent | 59787f0f2f74fed8159554c105c6c01802070271 (diff) |
glTF exporter: Manage emission strength in materials
Diffstat (limited to 'io_scene_gltf2/blender')
-rwxr-xr-x | io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py | 33 | ||||
-rwxr-xr-x | io_scene_gltf2/blender/exp/gltf2_blender_get.py | 12 |
2 files changed, 34 insertions, 11 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py index 0e764621..8dc5896f 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py @@ -109,13 +109,36 @@ def __gather_emissive_factor(blender_material, export_settings): if emissive_socket is None: emissive_socket = gltf2_blender_get.get_socket_old(blender_material, "EmissiveFactor") if isinstance(emissive_socket, bpy.types.NodeSocket): - fac = gltf2_blender_get.get_factor_from_socket(emissive_socket, kind='RGB') - if fac is None and emissive_socket.is_linked: + factor = gltf2_blender_get.get_factor_from_socket(emissive_socket, kind='RGB') + + if factor is None and emissive_socket.is_linked: # In glTF, the default emissiveFactor is all zeros, so if an emission texture is connected, # we have to manually set it to all ones. - fac = [1.0, 1.0, 1.0] - if fac == [0, 0, 0]: fac = None - return fac + factor = [1.0, 1.0, 1.0] + + if factor is None: factor = [0.0, 0.0, 0.0] + + # Handle Emission Strength + strength_socket = None + if emissive_socket.node.type == 'EMISSION': + strength_socket = emissive_socket.node.inputs['Strength'] + elif 'Emission Strength' in emissive_socket.node.inputs: + strength_socket = emissive_socket.node.inputs['Emission Strength'] + strength = ( + gltf2_blender_get.get_const_from_socket(strength_socket, kind='VALUE') + if strength_socket is not None + else None + ) + if strength is not None: + factor = [f * strength for f in factor] + + # Clamp to range [0,1] + factor = [min(1.0, f) for f in factor] + + if factor == [0, 0, 0]: factor = None + + return factor + return None diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_get.py b/io_scene_gltf2/blender/exp/gltf2_blender_get.py index 71eb4a2c..6a5152a6 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_get.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_get.py @@ -227,7 +227,7 @@ def get_factor_from_socket(socket, kind): from a MULTIPLY node just before the socket. kind is either 'RGB' or 'VALUE'. """ - fac = __get_const_from_socket(socket, kind) + fac = get_const_from_socket(socket, kind) if fac is not None: return fac @@ -237,19 +237,19 @@ def get_factor_from_socket(socket, kind): if kind == 'RGB': if node.type == 'MIX_RGB' and node.blend_type == 'MULTIPLY': # TODO: handle factor in inputs[0]? - x1 = __get_const_from_socket(node.inputs[1], kind) - x2 = __get_const_from_socket(node.inputs[2], kind) + x1 = get_const_from_socket(node.inputs[1], kind) + x2 = get_const_from_socket(node.inputs[2], kind) if kind == 'VALUE': if node.type == 'MATH' and node.operation == 'MULTIPLY': - x1 = __get_const_from_socket(node.inputs[0], kind) - x2 = __get_const_from_socket(node.inputs[1], kind) + x1 = get_const_from_socket(node.inputs[0], kind) + x2 = get_const_from_socket(node.inputs[1], kind) if x1 is not None and x2 is None: return x1 if x2 is not None and x1 is None: return x2 return None -def __get_const_from_socket(socket, kind): +def get_const_from_socket(socket, kind): if not socket.is_linked: if kind == 'RGB': if socket.type != 'RGBA': return None |