Hi everyone!
I have a way to generate .ply files of 3D models, with color attributes added to each vertex. I am importing these to blender, and the attribute node makes these colors visible in my material.
I have been trying for a while now to have the alpha channel define transparency for some of these nodes, but it seems like cycles does not support an alpha channel?
My plan B has been to color all the vertexes I want transparency for - in one color (for example black), and then make all the black vertexes transparent. Does anyone know how to do this?
Just use the attribute node as an input factor in a mix shader node, of which the two shaders are a transparency shader and the diffuse/glossy that you need.
I want the grey areas to be transparent. I have tried your suggestion in many different versions, but the wanted areas don’t seem to render transparently.
if colindices:
for i, f in enumerate(vcol_lay.data):
# XXX, colors dont come in right, needs further investigation.
ply_col = mesh_colors[i]
if len(ply_col) == 4:
f_col = f.color1, f.color2, f.color3, f.color4
else:
f_col = f.color1, f.color2, f.color3
for j, col in enumerate(f_col):
col.r, col.g, col.b = ply_col[j]
which, besides the comment, assumes that there could be f.color4 (alpha?) but then settles on RGB only as i get it.
Where you would get RGB information if you had used vertex colors from .ply as a mask (b/w)?
ply_col = mesh_colors[i]
if len(ply_col) == 4:
f_col = f.color1, f.color2, f.color3, f.color4
else:
f_col = f.color1, f.color2, f.color3
for j, col in enumerate(f_col):
col.r, col.g, col.b = ply_col[j]
This is misleading and looks buggy. If you look farther up in the script you’ll see that only 3 values (R, G, B) are ever read in to the mesh_colors list from the input ply file. The alpha value is ignored, and from my understanding Blender’s vertex colors can’t even store alpha values.
I recently had to do exactly what the OP described as plan B. I had colored verts with alpha = 1 and other verts with alpha = 0 that I wanted to hide. I colored all of the alpha = 0 verts black, which in my case didn’t conflict with the colors of the alpha=1 verts. In Blender I then thresholded the black verts and used them to set the material alpha. I guess it would be possible to do something similar if you wanted partial transparency but things could get complicated quickly. Below is the setup for the BI material I used. You should be able to do something similar for Cycles.