[Bf-cycles] Need help with shaders

Brecht Van Lommel brechtvanlommel at pandora.be
Mon Sep 26 14:56:06 CEST 2011


Hi,

On Sun, Sep 25, 2011 at 2:56 AM, storm <kartochka22 at yandex.ru> wrote:
> 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?

If you look at the glossy node, it has a roughness input for example.
There's currently an assumption that there are only two such inputs,
and they are stored in ShaderClosure.data0 and data1 (in latest svn,
the variable name changed).

However, I think the way this should be implemented is a bit
different, more like surface shading. There you would make a mix
between a Transparent closure and a Diffuse BSDF closure, and the same
thing can be done for volumes. I think the then you would get: density
= (1 - transparent_closure_weight).

The way the mix shader node currently works is that it will each time
pick either the Transparent or Diffuse BSDF. In case of the former
you'd evaluate exp(-sigma_t*density*step_distance) and have the ray
pass straight on, in the other case you'd sample the Diffuse BSDF.
There's some subtle issues to work out to get correct mixing and
adding in all cases, but I think in this simple setup with one mix
shader node it would work.

> 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).

I agree there should be flags to detect these cases. There isn't any
system yet to store such flags, but it's need it for some other
purposes too, will add this soon. I think practical rendering of
inhomogeneous volumes is possible, but not unbiased and with full
global illumination. It's good to have a reference implementation of
the full thing though.

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

I think if the volume is homogenous or not could be a material/world
setting (or automatically figured out somehow from the node setup, not
sure). The nodes that I imagine you would have are Transparent Volume,
Isotropic Volume, Anisotropic Volume. I can add such nodes (without
the kernel implementation) in the next few days if you want.

Anyway, if you want to get something working right away, I think you
can just use Transparent and Diffuse BSDF nodes as volume transparency
and isotropic scattering respectively.

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

An input like this might be needed, but perhaps only for computing the
normal for using BSDF's in volumes. There you need to differentiate
the density to compute a normal. Something similar happens for bump
mapping, where it first computes the normal from the displacement
input and then evaluates the surface shader. But that can be ignored
for now, you can use phase functions without a normal.

Brecht.


More information about the Bf-cycles mailing list