7
$\begingroup$

I have a function which assigns to "every" point in space (x,y,z) a scalar value d. I want to, somehow, visualize this function using Blender. This could be done with interpreting the value d as some kind of density and rendering coloured glass which absorbs more light at higher density values and seems transparent at lower density values.

I found the material type Volume to be in the proximity of what I am looking for but I do not know how to control the density at the points in space.

Has anyone an idea how to do this? Some solution with python is desirable.

$\endgroup$
  • $\begingroup$ I would use the ´d´ as the Z value on a plane; That doesn't seem to be what yo want, however. You could take a look at generating 3D textures, and applying the as the density of the Volume absorption - this how smoke works currently. $\endgroup$ – someonewithpc Dec 1 '14 at 11:44
  • $\begingroup$ Related questions: How Does Blender Voxel Data Work? | Setting Voxel Coordinates $\endgroup$ – pink vertex Dec 1 '14 at 14:16
  • $\begingroup$ Link to the wiki: Voxel Data Texture $\endgroup$ – pink vertex Dec 1 '14 at 14:23
  • $\begingroup$ I might recommend a contour view (again you would need the voxels to create this), depending on your needs the countour location would be controllable with animation, multiple pictures, or user controls. $\endgroup$ – D.J.Duff Dec 2 '14 at 9:39
7
$\begingroup$

Bender uses python for the user interface and it can also automate many tasks that manipulate blenders data. However when you want to customise a material python isn't much help.

If you want to use blender internal render engine you will find that there is some support for external voxel data.

For cycles, I think your best option would be an OSL shader.

I made a quick sample script as a starting point for you -

float myFunc(float x, float y, float z)
{
    return 1.5;
}

shader MyVolShader(
    color   BaseColour = color(1.0,0.0,0.0),
    output closure color Volume = 0)
{
    // P is the current point
    // P[0] == x
    // P[1] == y
    // P[2] == z
    Volume = (BaseColour * myFunc(P[0], P[1], P[2])) * absorption();
}

You then fillin myFunc using your algorithm, and the final colour as desired.

If you want volume scattering, swap absorption() with henyey_greenstein(0.0) in the final calculation (or add them together).

The OSL Language reference should be helpful.

I have a collection of OSL scripts here but none that use volume yet.

| improve this answer | |
$\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.