cemyuksel / cyCodeBase

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

points accumulated at borders when using adaptive sampling #12

Closed xarthurx closed 2 years ago

xarthurx commented 3 years ago

Similar to issue https://github.com/cemyuksel/cyCodeBase/issues/10 I'm trying to explore the adaptive sampling method using an image-based density function.

When using a smoothly changing density, the results looks cool. image image

However, when using an image with a sudden change of the density value, the points seems to accumulated at the edges: image image image

The current weight function is like this:

    auto wtfunc = [&](const cy::Point3f& p0, const cy::Point3f& p1, float dist2, float d_max) {
      auto d_init = cy::Sqrt(dist2);    // Euclid dist
      auto d = d_init *1 / (1 + den(p0));  // with weight
      return std::pow(1.0 - d / d_max, 8);
    };

where the den(p0) will get the grayscale value (0,1) of the image.

I've tested several different forms of weight function, but this issue seems to persist.

cemyuksel commented 3 years ago

Thanks for the comments. These are nice experiments, clearly showing the issue.

There are two problems here:

  1. Samples are too densely packed together near one side of the discontinuity.
  2. There is a region with no samples on the other side of the discontinuity.

The reason is that the concept of sample density is somewhat ill-defined near discontinuities. Density is defined as the number of samples per area. If you have no samples on one side of the discontinuity, you will have more samples to compensate for it on the other side. Similarly, if you have too many samples on one side, you won't have any on the other side.

That said, in my tests (years ago) I could avoid these problems using a different density function. Using your notation, it would look like something like this: auto d = d_init * ( 3 - 2*den(p0) ); I don't remember much about how I came up with this. See my Sample Elimination paper (Sec. 5.2) for more details.