Shaders: update OBJ and FBX for for Principled BSDF emission strength
This commit is contained in:
parent
051770b36d
commit
ec4ad081e5
|
@ -1309,7 +1309,7 @@ def fbx_data_material_elements(root, ma, scene_data):
|
|||
elem_props_template_set(tmpl, props, "p_number", b"DiffuseFactor", 1.0)
|
||||
# Principled BSDF only has an emissive color, so we assume factor to be always 1.0.
|
||||
elem_props_template_set(tmpl, props, "p_color", b"EmissiveColor", ma_wrap.emission_color)
|
||||
elem_props_template_set(tmpl, props, "p_number", b"EmissiveFactor", 1.0)
|
||||
elem_props_template_set(tmpl, props, "p_number", b"EmissiveFactor", ma_wrap.emission_strength)
|
||||
# Not in Principled BSDF, so assuming always 0
|
||||
elem_props_template_set(tmpl, props, "p_color", b"AmbientColor", ambient_color)
|
||||
elem_props_template_set(tmpl, props, "p_number", b"AmbientFactor", 0.0)
|
||||
|
@ -1808,7 +1808,7 @@ PRINCIPLED_TEXTURE_SOCKETS_TO_FBX = (
|
|||
("base_color_texture", b"DiffuseColor"),
|
||||
("alpha_texture", b"TransparencyFactor"), # Will be inverted in fact, not much we can do really...
|
||||
# ("base_color_texture", b"TransparentColor"), # Uses diffuse color in Blender!
|
||||
# ("emit", "emit", b"EmissiveFactor"),
|
||||
("emission_strength_texture", b"EmissiveFactor"),
|
||||
("emission_color_texture", b"EmissiveColor"),
|
||||
# ("ambient", "ambient", b"AmbientFactor"),
|
||||
# ("", "", b"AmbientColor"), # World stuff in Blender, for now ignore...
|
||||
|
|
|
@ -1457,10 +1457,9 @@ def blen_read_material(fbx_tmpl, fbx_obj, settings):
|
|||
# We have no metallic (a.k.a. reflection) color...
|
||||
# elem_props_get_color_rgb(fbx_props, b'ReflectionColor', const_color_white)
|
||||
ma_wrap.normalmap_strength = elem_props_get_number(fbx_props, b'BumpFactor', 1.0)
|
||||
# For emission color we can take into account the factor, but only for default values, not in case of texture.
|
||||
emission_factor = elem_props_get_number(fbx_props, b'EmissiveFactor', 1.0)
|
||||
ma_wrap.emission_color = [c * emission_factor
|
||||
for c in elem_props_get_color_rgb(fbx_props, b'EmissiveColor', const_color_black)]
|
||||
# Emission strength and color
|
||||
ma_wrap.emission_strength = elem_props_get_number(fbx_props, b'EmissiveFactor', 1.0)
|
||||
ma_wrap.emission_color = elem_props_get_color_rgb(fbx_props, b'EmissiveColor', const_color_black)
|
||||
|
||||
nodal_material_wrap_map[ma] = ma_wrap
|
||||
|
||||
|
@ -3151,6 +3150,9 @@ def load(operator, context, filepath="",
|
|||
elif lnk_type in {b'EmissiveColor'}:
|
||||
ma_wrap.emission_color_texture.image = image
|
||||
texture_mapping_set(fbx_lnk, ma_wrap.emission_color_texture)
|
||||
elif lnk_type in {b'EmissiveFactor'}:
|
||||
ma_wrap.emission_strength_texture.image = image
|
||||
texture_mapping_set(fbx_lnk, ma_wrap.emission_strength_texture)
|
||||
else:
|
||||
print("WARNING: material link %r ignored" % lnk_type)
|
||||
|
||||
|
|
|
@ -88,7 +88,9 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
|
|||
# XXX TODO Find a way to handle tint and diffuse color, in a consistent way with import...
|
||||
fw('Ks %.6f %.6f %.6f\n' % (mat_wrap.specular, mat_wrap.specular, mat_wrap.specular)) # Specular
|
||||
# Emission, not in original MTL standard but seems pretty common, see T45766.
|
||||
fw('Ke %.6f %.6f %.6f\n' % mat_wrap.emission_color[:3])
|
||||
emission_strength = mat_wrap.emission_strength
|
||||
emission = [emission_strength * c for c in mat_wrap.emission_color[:3]]
|
||||
fw('Ke %.6f %.6f %.6f\n' % tuple(emission))
|
||||
fw('Ni %.6f\n' % mat_wrap.ior) # Refraction index
|
||||
fw('d %.6f\n' % mat_wrap.alpha) # Alpha (obj uses 'd' for dissolve)
|
||||
|
||||
|
@ -117,7 +119,7 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
|
|||
"map_Bump": "normalmap_texture",
|
||||
"disp": None, # displacement...
|
||||
"refl": "metallic_texture",
|
||||
"map_Ke": "emission_color_texture",
|
||||
"map_Ke": "emission_color_texture" if emission_strength != 0.0 else None,
|
||||
}
|
||||
|
||||
for key, mat_wrap_key in sorted(image_map.items()):
|
||||
|
|
|
@ -195,6 +195,7 @@ def create_materials(filepath, relpath,
|
|||
|
||||
elif type == 'Ke':
|
||||
_generic_tex_set(mat_wrap.emission_color_texture, image, 'UV', map_offset, map_scale)
|
||||
mat_wrap.emission_strength = 1.0
|
||||
|
||||
elif type == 'Bump':
|
||||
bump_mult = map_options.get(b'-bm')
|
||||
|
@ -357,6 +358,7 @@ def create_materials(filepath, relpath,
|
|||
# We cannot set context_material.emit right now, we need final diffuse color as well for this.
|
||||
# XXX Unsupported currently
|
||||
context_mat_wrap.emission_color = _get_colors(line_split)
|
||||
context_mat_wrap.emission_strength = 1.0
|
||||
elif line_id == b'ns':
|
||||
# XXX Totally empirical conversion, trying to adapt it
|
||||
# (from 0.0 - 900.0 OBJ specular exponent range to 1.0 - 0.0 Principled BSDF range)...
|
||||
|
|
Loading…
Reference in New Issue