glTF exporter: Manage emission strength in materials

This commit is contained in:
Julien Duroure 2020-09-16 18:00:14 +02:00
parent 59787f0f2f
commit f3cf3a16e9
3 changed files with 35 additions and 12 deletions

View File

@ -15,7 +15,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
"version": (1, 4, 24),
"version": (1, 4, 25),
'blender': (2, 90, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',

View File

@ -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

View File

@ -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