Skip to content

Commit

Permalink
Merge pull request #1726 from KhronosGroup/fix_1725_texture_plugged_d…
Browse files Browse the repository at this point in the history
…irectly

Fix #1725 Texture can now be plugged directly on socket
  • Loading branch information
julienduroure authored Oct 11, 2023
2 parents 2a21c38 + e970c90 commit dc4d72f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from ...material.gltf2_blender_gather_texture_info import gather_texture_info
from ..gltf2_blender_search_node_tree import \
has_image_node_from_socket, \
get_socket_from_gltf_material_node, \
get_socket, \
get_factor_from_socket

Expand Down Expand Up @@ -53,13 +52,13 @@ def export_specular(blender_material, export_settings):

# Texture
if has_image_node_from_socket(specular_socket, export_settings):
original_specular_texture, uvmap_info, _ = gather_texture_info(
specular_texture, uvmap_info, _ = gather_texture_info(
specular_socket,
(specular_socket,),
(),
export_settings,
)
specular_extension['specularTexture'] = original_specular_texture
specular_extension['specularTexture'] = specular_texture
uvmap_infos.update({'specularTexture': uvmap_info})

if specularcolor_non_linked is True:
Expand All @@ -74,13 +73,13 @@ def export_specular(blender_material, export_settings):

# Texture
if has_image_node_from_socket(speculartint_socket, export_settings):
original_specularcolor_texture, uvmap_info, _ = gather_texture_info(
specularcolor_texture, uvmap_info, _ = gather_texture_info(
speculartint_socket,
(speculartint_socket,),
(),
export_settings,
)
specular_extension['specularColorTexture'] = original_specularcolor_texture
specular_extension['specularColorTexture'] = specularcolor_texture
uvmap_infos.update({'specularColorTexture': uvmap_info})

return Extension('KHR_materials_specular', specular_extension, False), uvmap_infos
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def export_volume(blender_material, export_settings):
volume_extension['thicknessFactor'] = fac if fac != None else 1.0
has_thickness_texture = True

# Pack thickness channel (R).
# Pack thickness channel (G).
if has_thickness_texture:
thickness_slots = (thickness_socket,)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def __get_image_data_mapping(sockets, default_sockets, results, export_settings)

else:
# rudimentarily try follow the node tree to find the correct image data.
src_chan = Channel.R
src_chan = None
for elem in result.path:
if isinstance(elem.from_node, bpy.types.ShaderNodeSeparateColor):
src_chan = {
Expand All @@ -243,6 +243,35 @@ def __get_image_data_mapping(sockets, default_sockets, results, export_settings)
if elem.from_socket.name == 'Alpha':
src_chan = Channel.A


if src_chan is None:
# No SeparateColor node found, so take the specification channel that is needed
# So export is correct if user plug the texture directly to the socket
if socket.socket.name == 'Metallic':
src_chan = Channel.B
elif socket.socket.name == 'Roughness':
src_chan = Channel.G
elif socket.socket.name == 'Occlusion':
src_chan = Channel.R
elif socket.socket.name == 'Alpha':
src_chan = Channel.A
elif socket.socket.name == 'Coat Weight':
src_chan = Channel.R
elif socket.socket.name == 'Coat Roughness':
src_chan = Channel.G
elif socket.socket.name == 'Thickness': # For KHR_materials_volume
src_chan = Channel.G

if src_chan is None:
# Seems we can't find the channel
# We are in a case where user plugged a texture in a Color socket, but we may have used the alpha one
if socket.socket.name in ["Alpha", "Specular IOR Level", "Sheen Roughness"]:
src_chan = Channel.A

if src_chan is None:
# We definitely can't find the channel, so keep the first channel even if this is wrong
src_chan = Channel.R

dst_chan = None

# some sockets need channel rewriting (gltf pbr defines fixed channels for some attributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def detect_shadeless_material(blender_material, export_settings):
else:
return None

socket = NodeSocket(socket, [blender_material.node_tree])
socket = NodeSocket(socket, [blender_material])

# Be careful not to misidentify a lightpath trick as mix-alpha.
result = __detect_lightpath_trick(socket)
Expand Down
Binary file modified tests/scenes/20_specular.blend
Binary file not shown.

0 comments on commit dc4d72f

Please sign in to comment.