1
$\begingroup$

I used mineways to import minecraft terrain, but when I do that the textures don't have their alpha channels inputted by default, meaning that I need to go through a ton of materials just imputing the alpha channel to make it transparent. Is there any script that can connect the alpha channel to all of the corresponding bsdf's? enter image description here In the picture the grass looks dumb because there is no transparency, so it is just black

$\endgroup$
1

1 Answer 1

3
$\begingroup$

Try this. I had it laying around.

# Tested with Blender 2.90
import bpy
for mat in bpy.data.materials:
    if not mat.use_nodes: continue
    for n in mat.node_tree.nodes:
        if n.type == 'BSDF_PRINCIPLED': break
    else: continue
    if n.inputs["Alpha"].links: continue  # skip if already has linked Alpha
    soc = n.inputs["Base Color"]
    if not soc.links: continue
    if soc.links[0].from_socket.name != "Color": continue
    tex = soc.links[0].from_node
    if tex.type != 'TEX_IMAGE': continue
    if not tex.image: continue
    if tex.image.depth != 32: continue  # guess if image has alpha channel
    mat.node_tree.links.new(tex.outputs["Alpha"], n.inputs["Alpha"])
    mat.blend_method = 'HASHED'
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .