[Bf-cycles] build with OSL support

storm kartochka22 at yandex.ru
Fri Nov 11 17:47:02 CET 2011

В Пт., 11/11/2011 в 12:56 +0100, Brecht Van Lommel пишет:
> Hi,
> On Thu, Nov 10, 2011 at 7:30 PM, storm <kartochka22 at yandex.ru> wrote:
> > Wrong, Diffuse uses uniform sampler, you need patch to make it
> > importance sampling.
> >
> > Patch just add function, you need to uncomment call to
> > sample_cos_hemisphere_importance() by hands in bsdf_diffuse.h to see
> > difference. No big changes on my test scenes, except it work worse in
> > the case distant light close to bumpy surface, long shadows from bumps
> > render with more noise, but it expected, as importance sampling fire
> > less rays in angles close to surface and more when we close to normal
> > direction.
> I'm pretty sure diffuse uses cosine weighted sampling? Because eval
> and pdf have the same value, they cancel out, and so it must be
> sampling exactly the cosine weighted distribution, otherwise it would
> be giving wrong results. The sample_cos_hemisphere_importance function
> you give here has a constant pdf, which seems to indicate it is
> uniform?

Hi, the opposite. Only perfect Importance sampling (Or primitive corner
case, uniform sampling of uniform pdf shape) have constant pdf.

Uniform sampling is simple and straightforward, we generate random
value, then weight PDF directly by given pdf function.

Perfect ideal Importance sampling is much harder, we need to sample more
per measurement area where given pdf is more. Only simple PDF can be
analytically inversed, other then diffuse or Phong lobe can be faked,
and have some intermediate "unperfect" importance sampling, it is better
then uniform but still have non constant PDF.

>As a side note, when comparing to pbrt or some other render engines,
>we do something a bit different, we include the cos(theta) factor
>already in the BSDF instead of multiplying by it afterwards in the

Eval have no relation with sampling. It used for absolutely different
events. Sampling generate primary integrator event, "What happened with
current photon (or importance particle in the case of backtrace) package
during another timeslice". Eval say "If you fire photon package in that
direction, it will be attenuated by that value because of some surface
property". In the case of ideal perfect importance sampling they MUST
have different values. Because PDF shape control density of rays, not
value of PDF. If thay have same values , we get brighter image in normal
direction in the case of diffuse material.

And trick with cos(theta) is the only reason that we need non uniform
sampling at all in diffuse sampler.

__device_inline void sample_cos_hemisphere(const float3 N,
        float randu, float randv, float3 *omega_in, float *pdf)
        // Default closure BSDF implementation: uniformly sample
        // cosine-weighted hemisphere above the point.
        to_unit_disk(&randu, &randv);
        float costheta = sqrtf(max(1.0f - randu * randu - randv * randv,
        float3 T, B;
        make_orthonormals(N, &T, &B);
        *omega_in = randu * T + randv * B + costheta * N;
        *pdf = costheta *M_1_PI_F;

It generate UNIFORM point on hemisphere "to_unit_disk", LATER calculate
cosinus (of uniform point ), linearly transform to respect input vector,
and asjust pdf. That called uniform sampling by definition.

More information about the Bf-cycles mailing list