Posts: 6
Threads: 5
Joined: Apr 2020
I downloaded a model with transparency from tMR (it was using it to put a 2D sprite onto a plane), but when I opened it in Blender, every part that should have been transparent was instead black. I looked online for answers and only found tutorials for making entire materials translucent.
Also strange: when I looked at the model through the Texture Paint tab in Solid shading mode (which would normally display the model with a blank white texture), not only was it using its texture, the parts intended to be transparent were now transparent (i.e. it was displaying correctly).
Could someone who knows Blender better than me explain this?
Posts: 99
Threads: 5
Joined: Nov 2016
You don't need the Mix/TransparentBSDF stuff anymore, you just need to connect the texture Alpha to the PrincipledBSDF Alpha (and set the Blend Mode).
Here's a script you can try that will do this automatically for all materials. Put it in the text editor and hit the Run button.
Code:
# 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'
Posts: 6
Threads: 5
Joined: Apr 2020
Thank you; that was very helpful. One last thing: do I need to run that script every time I open Blender? I ran that script and closed and reopened Blender, and transparent pixels showed up as black again.
Posts: 99
Threads: 5
Joined: Nov 2016
It only affects materials that already exist in the file, so you have to run it after every import.
Posts: 61
Threads: 6
Joined: Jan 2021
for eevee and the viewport:
if it's just a texture with alpha masking (aka the texture being only on part of the mesh with the other part being completely transparent, use alpha clip and if it's a transparent or partially transparent object use alpha blend
for cycles:
it just works