Colored Density

Hello,

I’m working around coloring my render according to local density : High density zones would be red, and low density ones would be blue. I already do it in postproduction but i’m playing with krakatoa to understand the beast. And i’m not really sure i’ve understood some very basic aspect of the software : what density means…
How is calcultaed the density channel ? Here is how i understand it so far, which can be the complete opposite of how Krakatoa works :
All particles got a density of let say 1 when the render starts. Krakatoa accumulates the particles and raises the density channel value for each particles when they occupy the same pixel on the screen.
Or is there some king of interpolation to compute the local density of particles before the rendering ?
All come to one question : At what time in the render process is the density channel value computed.
If i add a KCM_density which take the log of the density, what is does exactly : takes the log of the particle density when accumulating it, therefore doing some sort of log(x) + log(x2) + log(x3) , or take the log o fthe whole thing, therefore computing a log(X) ?
And then, is there any mean to know the maximum value of the density channel for all particles ?

Best regards,

Pierre

There are two density aspects that play role in Krakatoa rendering:

  1. Per-particle Density value - this is the density channel value which defines how much density the single particle carries with it. It defaults to 1.0 when we don’t have a different explicit value, but it could be any value and could be modulated by the Opacity channel of a Standard Material, provided or modified by a KCM, scaled by the Visibility track and so on. The Density could be stored in a PRT file and could come into the scene with an arbitrary value.

  2. Spatial Density - this is the amount of particles in a unit volume. If you had 10 particles with Per-Particle Density of 0.1 with the same position, the final rendering would be the same as one particle with Per-Particle Density of 1.0.

So in theory, having 1000 particles with Per-Particle Density value of 10.0 could be thought of equivalent (but not equal) to having 10,000 particles with Density of 1.0 or 100,000 particles with Per-Particle Density of 0.1. If all these particles happened to be rendered inside a single pixel (or voxel in render mode), the accumulated result in the pixel or voxel would be the same, but if they are distributed in space, it is quite obvious that less particles with more Per-Particle Density will look a lot grainier than a many particles with less Per-Particle Density.

When Krakatoa accumulates particles into the frame buffer, it takes into account how much volume a pixel represents and is able to adjust the density internally to get a correct representation. This is why if you reduce the resolution of the output image, the same particle count could produce a different Additive rendering - a single pixel would not represent a lot more space behind it and more particles would fall inside of it and accumulate to a higher value. We take this into account when rendering Volumetrically though. We also take this into account when using the Iterative mode with Half or Quarter resolution - you can render a fraction of the particles with a lower resolution and we make sure the Density is scaled to produce a similar output. (See here software.primefocusworld.com/sof … output.php)

The Density value in the Main Controls (the one with the two spinners) is a global multiplier of the Per-Particle Density coming from the Density channels of the particles. If a particle does not provide an explicit Density channel, then we assume it 1.0. On the page I linked to above, you will see these images:


The top image contains 10 million particles, the bottom one contains 1 million particles, but with Density Exponent raised by 1 to produce 10x the per-particle density. While the second image is grainy, it is equivalent in resulting density from the per-particle and spatial densities.
When the image resolution is reduced significantly, the second image suddenly starts looking very similar to the first one:

because we lose the gaps between the particles and the accumulated density is REALLY the same.

In your case though, you are interested in the SPATIAL density of your stars. The Per-Particle Density could be thought of as the SIZE of the star (the smaller the star, the less influence it would have in the pixels it is rendered into, and will thus appear dimmer - we cannot draw a particle smaller or larger than a pixel, but a darker pixel generally looks like a smaller pixel).

We currently do not have a way to MEASURE the spatial density in numeric terms, the only thing we can do is render a small image with all stars in them in Additive mode and use the value in the resulting output to mask the color describing the spatial density. We MIGHT provide KCM operators in the future to find out nearby particles and count how many particles are in a certain radius around each particle, which then could be converted to a color value, but right now this is not planned for 1.6.0.

Sampling like that CAN be done using PFlow though. There are Box#3 suboperators that can measure local spatial density as well as the neighborhood min/max/average of a channel. It’s not fast, but it does work.

  • Chad

Thanks, very clear, as always !