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.

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 {
CPoint3<float> pCentre = o2w(CPoint3<float>(0.0f));
CVector3<float> wc = Vector::Normalize(pCentre - p);
CVector3<float> wcx, wcy;
Vector::CoordinateSystem(wc, &wcx, &wcy);
if (Point::DistSquare(p, pCentre) - radius*radius < 1e-4f)
return Sample(ls, n);
float sinthetamax2 = radius * radius / Point::DistSquare(p, pCentre);
float costhetamax = sqrtf(Math::Max(0.0f, 1.0f - sinthetamax2));
CSurfaceProps dg_sphere;
float thit, ray_epsilon;
CPoint3<float> ps;
CRay ray(p, Vector::UConeSample(ls.u1, ls.u2, costhetamax, wcx, wcy, wc), 1e-3f);
if (!Intersect(ray, &thit, &ray_epsilon, &dg_sphere))
thit = Vector::Dot(pCentre - p, Vector::Normalize(ray.d));
ps = ray(thit);
*n = CVector3<float>(Vector::Normalize(ps - pCentre));
return ps;
}
- ? .