Can float vertex layer data added with bmesh, be used in rendering?
Let us say we added some data to all verteces:
Can this "G" be used in Cycles rendering nodes? As a source for a factor, etc?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
As far as I know, only special custom data layers can be used in a render or the 3D view:
If you want to see your data in a render, you need to transfer it to a UV layer or
vertex loop colour layer first. To transfer to a colour layer, you can do something like this:
color_layer = mesh.loops.layers.color.new('Foo') for vert in mesh.verts: val = vert[my_cdata] col = (val, val, val) for loop in vert.link_loops: loop[color_layer] = col
Then you can use the 'Foo' layer in a render.
val will be automatically clipped to be between 0 and 1.
When transferring to vertex colours you will lose precision, because each channel is stored in a single byte (whereas float custom data is stored in 4 bytes). You can get better precision by using a UV layer, which stores floats - but only two channels (x and y). When using a UV layer, the values will not be color-managed; this can be useful or not, depending on your material. Storing in a UV layer is similar:
uv_layer = mesh.loops.layers.uv.new('Foo') for vert in mesh.verts: val = vert[my_cdata] for loop in vert.link_loops: loop[uv_layer].uv.x = val