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.

Make sure that the Bifrost mesh you want to sample has a valid
face_vertex_uvproperty.Add a
create_texture_samplesnode to the graph, and connect the mesh into itsgeometryport.Set the desired pixel resolution and sampling density on the
create_texture_samplesnode.Add a
bake_texture_samplesnode, and connect thecreate_texture_samplesnode'ssample_pointsoutput into itssample_pointsinput.Connect the data that you want to bake into the
sampled_datainput. 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, andsample_locations) of thecreate_texture_samplesnode to create your own complex data look-ups, for example, using geometry queries (see Query data on geometric objects). Thesample_is_validoutput 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_samplesnode to add or blend color values over time, as for wet maps and other effects.Connect the output of the
bake_texture_samplesnode to awrite_texturenode, and set its parameters.Connect the
out_textureoutput of thewrite_texturenode to theoutputnode 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
ifnode to control when the files are written.
