diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2020-09-05 16:14:40 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2020-09-05 16:14:40 +0300 |
commit | 0dca80fdc4e81ee7163d46366ab0905c6d2b8ef9 (patch) | |
tree | bd458766db7755faddff727637136a56fad4152a /io_scene_gltf2/blender | |
parent | 414448fd3834524121d1114904033c4520936085 (diff) |
glTF: manage KHR_materials_unlit
Diffstat (limited to 'io_scene_gltf2/blender')
-rwxr-xr-x | io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py | 39 | ||||
-rw-r--r-- | io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_unlit.py | 3 |
2 files changed, 37 insertions, 5 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 ea597f90..3ad17fe2 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py @@ -89,7 +89,7 @@ def __gather_alpha_cutoff(blender_material, export_settings): def __gather_alpha_mode(blender_material, export_settings): if blender_material.blend_method == 'CLIP': return 'MASK' - elif blender_material.blend_method == 'BLEND': + elif blender_material.blend_method in ['BLEND', 'HASHED']: return 'BLEND' return None @@ -141,7 +141,11 @@ def __gather_extensions(blender_material, export_settings): if clearcoat_extension: extensions["KHR_materials_clearcoat"] = clearcoat_extension - # TODO KHR_materials_pbrSpecularGlossiness + # KHR_materials_transmission + + transmission_extension = __gather_transmission_extension(blender_material, export_settings) + if transmission_extension: + extensions["KHR_materials_transmission"] = transmission_extension return extensions if extensions else None @@ -284,3 +288,34 @@ def __gather_clearcoat_extension(blender_material, export_settings): ) return Extension('KHR_materials_clearcoat', clearcoat_extension, False) + +def __gather_transmission_extension(blender_material, export_settings): + transmission_enabled = False + has_transmission_texture = False + + transmission_extension = {} + transmission_slots = () + + transmission_socket = gltf2_blender_get.get_socket(blender_material, 'Transmission') + + if isinstance(transmission_socket, bpy.types.NodeSocket) and not transmission_socket.is_linked: + transmission_extension['transmissionFactor'] = transmission_socket.default_value + transmission_enabled = transmission_extension['transmissionFactor'] > 0 + elif __has_image_node_from_socket(transmission_socket): + transmission_extension['transmissionFactor'] = 1 + has_transmission_texture = True + transmission_enabled = True + + if not transmission_enabled: + return None + + # Pack transmission channel (R). + if has_transmission_texture: + transmission_slots = (transmission_socket,) + + if len(transmission_slots) > 0: + combined_texture = gltf2_blender_gather_texture_info.gather_texture_info(transmission_slots, export_settings) + if has_transmission_texture: + transmission_extension['transmissionTexture'] = combined_texture + + return Extension('KHR_materials_transmission', transmission_extension, False) diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_unlit.py b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_unlit.py index cd0a8568..d2366454 100644 --- a/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_unlit.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_unlit.py @@ -34,9 +34,6 @@ def unlit(mh): mh.node_tree.links.new(mix_node.inputs['Fac'], lightpath_node.outputs['Is Camera Ray']) mh.node_tree.links.new(mix_node.inputs[1], transparent_node.outputs[0]) mh.node_tree.links.new(mix_node.inputs[2], emission_node.outputs[0]) - # Using transparency requires alpha blending for Eevee - if mh.is_opaque(): - mh.mat.blend_method = 'HASHED' # TODO check best result in eevee _emission_socket, alpha_socket = make_output_nodes( mh, |