Correcting the wrong shadow shadow selection

Hi, I am learning raytracing algorithm and I am stuck in monte carlo algorithm. While rendering without highlighting the area, my output pin was correct, but when I added the implementation of the light region to the source code to create a soft shadow, I ran into a problem.

Below is the reverse image.

enter image description here

When I moved the blue sphere down, the problem continues (note that the artifact continues when the sphere follows the white dashed line). Note that this sphere and arealight are the same z offset. When I bring the blue sphere to the screen, the artifact disappeared. I think the problem is caused by a uniform sampling scheme or a sampling function, but not sure.

Here is the function:

template <typename T>
CVector3<T> UConeSample(T u1, T u2, T costhetamax,
const CVector3<T>& x, const CVector3<T>& y, const CVector3<T>& z) {
   T costheta = Math::Lerp(u1, costhetamax, T(1));
   T sintheta = sqrtf(T(1) - costheta*costheta);
   T phi = u2 * T(2) * T(M_PI);

   return cosf(phi) * sintheta * x +
          sinf(phi) * sintheta * y +
          costheta * z;
}

float u1, u2 van Der Corput.

CPoint3<float> CSphere::Sample(const CLightSample& ls, const CPoint3<float>& p, CVector3<float> *n) const {
   // translate object to world space
   CPoint3<float> pCentre = o2w(CPoint3<float>(0.0f));
   CVector3<float> wc = Vector::Normalize(pCentre - p);
   CVector3<float> wcx, wcy;
   //create local coordinate system from wc for uniform sample cone
   Vector::CoordinateSystem(wc, &wcx, &wcy);

   //check if inside, epsilon val. this is true?
   if (Point::DistSquare(p, pCentre) - radius*radius < 1e-4f)
      return Sample(ls, n);

   // Else outside evaluate cosinus theta value
   float sinthetamax2 = radius * radius / Point::DistSquare(p, pCentre);
   float costhetamax = sqrtf(Math::Max(0.0f, 1.0f - sinthetamax2));

   // Surface properties
   CSurfaceProps dg_sphere;
   float thit, ray_epsilon;
   CPoint3<float> ps;

   //create ray direction from sampled point then send ray to sphere
   CRay ray(p, Vector::UConeSample(ls.u1, ls.u2, costhetamax, wcx, wcy, wc), 1e-3f);
   // Check intersection against sphere, fill surface properties and calculate hit point
   if (!Intersect(ray, &thit, &ray_epsilon, &dg_sphere))
      thit = Vector::Dot(pCentre - p, Vector::Normalize(ray.d));

   // Evaluate surface normal
   ps = ray(thit);
   *n = CVector3<float>(Vector::Normalize(ps - pCentre));

   //return sample point
   return ps;
}

- ? .

+4
1

.

RNG ( "Mersenne Twister" ) .

enter image description here

, . , .

+1

Source: https://habr.com/ru/post/1616213/


All Articles