Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1725 Texture can now be plugged directly on socket #1726

Merged
merged 28 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3b7e6e3
Fix #1725 Texture can now be plugged directly on socket
julienduroure Sep 10, 2022
288c34b
Merge branch 'master' into fix_1725_texture_plugged_directly
julienduroure Sep 19, 2022
8cd95ce
Merge branch 'master' into fix_1725_texture_plugged_directly
julienduroure Sep 25, 2022
b9f00f2
Merge branch 'master' into fix_1725_texture_plugged_directly
julienduroure Oct 6, 2022
e628946
Merge branch 'master' into fix_1725_texture_plugged_directly
julienduroure Oct 10, 2022
27b948c
Merge branch 'master' into fix_1725_texture_plugged_directly
julienduroure Jan 9, 2023
236a2b6
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Jan 12, 2023
7d8c7f9
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Jan 18, 2023
5de8730
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Feb 17, 2023
a1c232b
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Mar 31, 2023
d055bcf
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Apr 13, 2023
5f1b00b
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure May 11, 2023
2f02450
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure May 24, 2023
477b704
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Sep 4, 2023
15c53aa
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Sep 6, 2023
54f9b68
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Sep 13, 2023
5c0c912
Update patch after changes in Blender
julienduroure Sep 13, 2023
fbcd55f
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Sep 13, 2023
430fb1a
Alpha check not needed, not on same link
julienduroure Sep 13, 2023
7a1890f
Fix Roughness sheen check
julienduroure Sep 13, 2023
c6f1056
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Sep 25, 2023
30988b5
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Sep 27, 2023
7b7f11d
Fix merge
julienduroure Sep 27, 2023
c3f3aa7
Avoid crash when Alpha is not linked to alpha socket
julienduroure Sep 30, 2023
cdc8d8b
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Oct 9, 2023
c0b2b91
Fix after merge
julienduroure Oct 9, 2023
bd23977
Fix merge about nod groups
julienduroure Oct 11, 2023
e970c90
Merge branch 'main' into fix_1725_texture_plugged_directly
julienduroure Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.