[Bf-cycles] Need help with shaders

storm kartochka22 at yandex.ru
Sun Sep 25 02:56:02 CEST 2011

Hi all, I stuck at problem that was not look as hard from the beginning
but now I realize that it prevent me to share first half- working
volumetric patch.

TL;DR: please create proper particle density node with ability to fast
detect 3 cases from device inner loop and evaluate scalar density, keep
all "Diffuse BSDF" logic same.

I cannot get particle density info from shaders. For now I just
copy-paste and rename diffuse BSDF closure, and use Color red component
as density, hard coding phase function pdf to stop Color modify it. It
is enough for my experiments but suxx for wide testing.

How to add extra data stream to closure? Any closure have only 1 data
stream, weight. If we already have Color as attenuation factor in
diffuse bsdf node, how to add another one (density)? How to evaluate it?

For optimization we need to get 3 cases that must be checked after any
ray intersection test before we hit background or triangle:

	1. volumetric turned off or constant zero particle density in
homogeneous media (vacuum, air), fast skip any media code, use good old
render steps. (unbiased, fastest)

	2. homogeneous media with particle density > 0 (constant mist, fog),
use well known fast sampling step = -log(random)/sigma (unbiased, fast
and optimal from MontrCarlo solver point of view)

	3. inhomogeneous media where particle density can vary around volume
(clouds, smokes ). Slowest, in general almost unusable in practice with
current hardware except some corner cases (tiny hull around surfaces
like short fur or planet glowing atmosphere from far distance camera, or
data with known max density that vary little from max value, Woodcock
alg.) (unbiased, extremely slow).

In my experiments density shader evaluation take ~70% of all time, so we
really need to distinguish 3 cases as fast as possible, maybe add shader
bitfield flag to kernel shader texture?

>From artists point of view there is Volume shader input slot in
property, so to provide clean and intuitive GUI we must detect that it
empty or some shader plugged, and what class of media data it provide.

I lost in all that triple svm/osl/native node system, it too complex for

Maybe create 3 different closures? Null phase function, Homogeneous
phase function, Phase function? And code them to set ShaderData flag to
return state?

Or create extra input, now we have Surface, Volume, Displacement. Add
something like Volume particle Density before Displacement?

More information about the Bf-cycles mailing list