# Controlling volume density

How can I control the volume density values at different locations in a mesh with volume shaders?

I know that noise textures can be plugged in to the density factor slot of a volume shader (producing a sponge-like effect as in the example below) for instance, but what other ways are there to control the density pattern inside a mesh? Are there ways to achieve more controlled/less random patterns?

• You can use any texture you want.. What kind of pattern do you have in mind? – gandalf3 Mar 29 '14 at 1:14

Yes, you can use any set of 3D values (e.g. procedural texture) you want (note that this means you can't use image textures. This is because you need the texture to be defined in 3D, and of course a image texture is 2D.
See the wiki for a list of cycles textures with descriptions.

The density is controlled by the value (brightness) of the texture.
Consider this node setup:

Where the texture is white (1), the density will be 1. Where it is black (0), the density will be 0.

Because a density of 1 is still very faint, I have added a multiply node to scale the white portions of the texture to 20 instead of 1:

As an example for non-procedural texture information, this setup will make the density based on the global X location of the object (with some math nodes to avoid volumes with negative density):

• I have used the other procedural textures with volume shaders as well. What I mean to ask is, are we 'limited' to the current selection of procedural textures, or are there other ways to define the volume density at different points inside a mesh? Is there a way to make the density at a point a function of its local or global coordinates, for instance (set the density equal to the tangent of the local x coordinate at that point)? Are there ways to switch to different volume shader subtrees if the z coordinate is between 1 and 3 blender units away from the local object origin? And how... – Qutorial Mar 29 '14 at 13:21
• @Qutorial You don't have to use procidural textures, anything that returns a value will work. – gandalf3 Mar 29 '14 at 21:54
• Is there a rule of thumb or list of what's compatible with the density input (what sockets will output a density field/values in 3 dimensions)? – Qutorial Oct 3 '15 at 3:55
• @Qutorial In general everything works, but things which are inherently 2D don't give you very obviously useful results (no doubt you could find some creative use for them). Experiment and see what happens :) – gandalf3 Oct 3 '15 at 6:29