簡體   English   中英

光線跟蹤不正確的軟陰影采樣

[英]Raytracing incorrect soft shadow sampling

您好我正在研究光線追蹤算法,我堅持使用蒙特卡羅算法。 雖然渲染沒有區域光,但我的渲染輸出是正確的但是當我將區域光實現添加到源代碼以生成軟陰影時,我遇到了問題。

這是前后輸出圖像。

在此輸入圖像描述

當我向下移動藍色球體時,問題仍在繼續(注意當球體沿着白色虛線時,人工制品會繼續)。 注意這個球體和arealight是相同的z偏移量。 當我把藍色球體帶到屏幕前面時,神器就消失了。 我認為問題是由均勻采樣錐或采樣球功能引起的,但不確定。

這是功能:

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;
}

我正在從van Der Corput序列生成隨機浮點u1,u2值。 這是球形采樣方法

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;
}

有沒有人有什么建議? 謝謝。

我解決了這個問題。

光線跟蹤需要更復雜的RNG(其中一個是“Mersenne Twister”偽隨機數生成器)和良好的混洗算法。

在此輸入圖像描述

我希望它會有所幫助。 感謝所有發表評論的人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM