cemyuksel / cyCodeBase

An open source programming resource intended for graphics programmers.
MIT License
271 stars 60 forks source link

Example of adaptive weightFunction? #10

Closed alecjacobson closed 4 years ago

alecjacobson commented 4 years ago

I'm loving the blue noise sampler on surfaces in 3D. In the default "uniform importance" mode it's working great! Thanks for sharing this great implementation of a great algorithm.

I'm struggling to get the weightFunction working correctly for adaptive importance. Wondering if you could give some pointers?

For example, I'm trying to create sampling of this rectangle with more samples toward the center and decreasing "smoothly" toward the edges.

I tried using this as my weightFunction:

  const auto weight = 
    [d_min, alpha](
    PointType const & p0, 
    PointType const & p1, 
    FType d2, 
    FType d_max)
  {
    FType d = cy::Sqrt(d2)*(3.0-2.0*(1.0-p0.Length()));
    return std::pow( FType(1) - d/d_max, alpha );
  };

But the result is clumpy:

image
cemyuksel commented 4 years ago

Your weight function seems fine to me. It might be related to the bounds of p0.Length(). It should not be greater than 1. You may need to scale it accordingly.