3
$\begingroup$

Can float vertex layer data added with bmesh, be used in rendering?

Let us say we added some data to all verteces: bm.verts.layers.float.new('G')

Can this "G" be used in Cycles rendering nodes? As a source for a factor, etc?

$\endgroup$
3
$\begingroup$

As far as I know, only special custom data layers can be used in a render or the 3D view:

  • Loop UV
  • Loop colour (i.e. vertex colour)
  • Vertex defom (i.e. vertex groups) - but only indirectly, e.g. as deformation

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.

Note that 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

Screenshot of node setup to use UV layer for colour

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.