c – 光线跟踪不正确的软阴影采样

c – 光线跟踪不正确的软阴影采样,第1张

概述您好我正在研究光线追踪算法,我坚持使用蒙特卡罗算法.虽然渲染没有区域光,但我的渲染输出是正确的但是当我将区域光实现添加到源代码以生成软阴影时,我遇到了问题. 这是前后输出图像. 当我向下移动蓝色球体时,问题仍在继续(注意当球体沿着白色虚线时,人工制品会继续). 注意这个球体和arealight是相同的z偏移量.当我把蓝色球体带到屏幕前面时,神器就消失了.我认为问题是由均匀采样锥或采样球功能引起的, 您好我正在研究光线追踪算法,我坚持使用蒙特卡罗算法.虽然渲染没有区域光,但我的渲染输出是正确的但是当我将区域光实现添加到源代码以生成软阴影时,我遇到了问题.

这是前后输出图像.

当我向下移动蓝色球体时,问题仍在继续(注意当球体沿着白色虚线时,人工制品会继续).
注意这个球体和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,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 “Random Number Generator”算法引起的(需要分布均匀的u1,u2:low discrepancy sampling).

光线跟踪需要更复杂的RNG(其中一个“The Mersenne Twister”伪随机数发生器)和良好的混洗算法.

我希望它会有所帮助.感谢所有发表评论的人.

总结

以上是内存溢出为你收集整理的c – 光线跟踪不正确的软阴影采样全部内容,希望文章能够帮你解决c – 光线跟踪不正确的软阴影采样所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1227920.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存