Share

Bake textures to file

The texture-baking nodes in Bifrost let you sample data from a surface in 3D and write it to 2D image files, effectively caching the results of a graph evaluation in the form of texture files. For example, you can create wet maps to track where a liquid has touched a surface. The files can be used like any other image, for example, as weights in another graph or with materials in Maya. UDIM and other texture tile formats are supported.

An example of baking textures

  1. Make sure that the Bifrost mesh you want to sample has a valid face_vertex_uv property.

  2. Add acreate_texture_samples node to the graph, and connect the mesh into its geometry port.

  3. Set the desired pixel resolution and sampling density on the create_texture_samples node.

  4. Add a bake_texture_samples node, and connect the create_texture_samples node's sample_points output into its sample_points input.

  5. Connect the data that you want to bake into the sampled_data input. Use 3D data for RGB and 4D data for RGBA values. 1D data gets promoted to 3D data with constant members. You can connect any of several different data types:

    • A field gets sampled at the sample points' 3D positions.
    • A string gets interpreted as the name of a geo property on the mesh, which is sampled at the sample points' locations.
    • A Bifrost object gets interpreted as a texture and sampled at the sample points' UV positions.
    • A single vector gets interpreted as a constant value for all pixels.
    • An array of vectors gets resized to the correct number of pixels and used as the explicit pixel values.

    If desired, you can use the auxiliary outputs (sample_uvs, sample_positions, and sample_locations) of the create_texture_samples node to create your own complex data look-ups, for example, using geometry queries (see Query data on geometric objects). The sample_is_valid output lets you know if the location corresponding to the UV coordinates exists on the geometry, and take whatever action you prefer if it doesn't.

    You can also use an accumulate_color_texture_samples node to add or blend color values over time, as for wet maps and other effects.

  6. Connect the output of the bake_texture_samples node to a write_texture node, and set its parameters.

  7. Connect the out_texture output of the write_texture node to the output node of the graph to run it.

    Disconnect it if you don't want to rewrite the images every time the graph runs, or use an if node to control when the files are written.

Was this information helpful?