I’m working on a task that involves generating a large number of textures in Blender using Python (bpy) as a standalone (without the GUI). While I can automate the creation of shader nodes, I’m struggling to extract the resulting texture images efficiently. Currently, I render the images, but this involves saving them to files, which isn’t necessary for my task and adds significant runtime overhead.
Since my textures are 2D and only depend on the shader nodes (lighting, camera angle, etc., are irrelevant), I’m wondering:
Is there a way to render an image and access the pixel values directly from a script, without saving to a file?
Alternatively, is there another method to directly sample the output of the shader nodes?
(Edit: some people offered baking as a method to sample the output of the shader. However, that method is only available using cycles, and from my attempts it is even slower than a full render. These are the settings I used for baking, is there a faster method?)
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.cycles.samples = 1
bpy.context.scene.cycles.bake_type = 'EMIT'
bake_image = bpy.data.images.new("BakeResult", width=512, height=512)
image_node = nodes.new('ShaderNodeTexImage')
image_node.image = bake_image
image_node.select = True
material.node_tree.nodes.active = image_node bpy.ops.object.bake(type='EMIT')