I need to render a 3D density plot of custom mathematical functions as part of a scientific visualization. I've seen some demos and it seems that Blender is capable of volumetric rendering. My question is then: how can I do that?
I see that in the Material tab there's a Volume button which turns on volumetric rendering. Then I can choose a Voxel Data file. Cool. But there are a couple of problems I encountered:
None of the file formats (bvox, raw) seems to have any color information, only the density (which I consider to be somewhat like the "alpha" value – am I right?). So how can I supply the color information for my density plots? I need to have a color assigned to each pixel, not just transparency/density. You can think of it as a temperature distribution in which each point in space has assigned a colour, red = hot, blue = cold etc.
I need to be able to animate this density plot inside Blender by controlling some parameters for the function. So it cannot be just some static data from a file – the data has to be generated on the fly inside Blender (I'm thinking of using some Python scripting) and change in accord with the current animation frame.
The function is quite complicated and the formula can change depending on the selected parameters, so I guess scripting is the only option. As long as I can use math libraries from Python, I guess I can handle the math part. I just hope that Blender is able to handle the rendering part for me, by passing the coordinates of each point in space through my function and generating the voxel data.
Is this possible to do in Blender at all? Or should I use something else?
After a quick look through Blender's Python API I found these classes:
which seem to be somewhat related to the problem I'm trying to solve. Am I right?
If this could be used to set the voxel values on the fly with a custom math function (by setting the
image.pixels property, I guess?), then what's left is the colors and changing with the animation. Any ideas of how this could be done?
OK I think I figured out how to handle the voxel colours: turns out I can plug a texture node as the colour. So the only problem now is how to generate this texture procedurally from my custom function in the script that returns an RGB value for the given XYZ coordinates, kinda like the built-in procedural textures (e.g. Voronoi, Noise, Checker etc.) do.