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?
In the picture the grass looks dumb because there is no transparency, so it is just black
-
1$\begingroup$ Same as here? blender.stackexchange.com/questions/160392/… $\endgroup$– batFINGERAug 23, 2021 at 13:37
1 Answer
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'