如何解决光线追踪软阴影
我在使用光线追踪软阴影时遇到了问题。我正在尝试计算从一个交点到一个光球上的随机点的向量,它似乎可以工作,但看起来很奇怪。
在光源和交点之间明显没有障碍物的区域中,我仍然出现黑色像素。帧之间的混合最终摆脱了这些,但在我看来这似乎是不正确的。
这是我用来计算向量的代码,请问我哪里出错了?
附言您可以在此处看到跟踪器:https://andrewbrg.github.io/dist/
// For performance we will reduce the number of shadow rays
// on reflections down based on the tracing depth
const sRayCount = _depth > 0 ? 1 : shadowRayCount;
const sRayDivisor = (1 / sRayCount);
// Transform the light vector into a number of vectors onto a disk
const ptRadius = lights[i][8] * Math.sqrt(Math.random());
const ptAngle = Math.random() * 2.0 * Math.PI;
const diskPt = [
ptRadius * Math.cos(ptAngle),ptRadius * Math.sin(ptAngle)
];
const crossTan = vCross(toLightVecUnit[0],toLightVecUnit[1],toLightVecUnit[2],1,0);
const lightTan = vUnit(crossTan[0],crossTan[1],crossTan[2]);
const crossBiTan = vCross(lightTan[0],lightTan[1],lightTan[2],toLightVecUnit[0],toLightVecUnit[2])
const lightBiTan = vUnit(crossBiTan[0],crossBiTan[1],crossBiTan[2]);
toLightVec = [
toLightVecUnit[0] + lightTan[0] * diskPt[0] + lightBiTan[0] * diskPt[1],toLightVecUnit[1] + lightTan[1] * diskPt[0] + lightBiTan[1] * diskPt[1],toLightVecUnit[2] + lightTan[2] * diskPt[0] + lightBiTan[2] * diskPt[1]
];
toLightVecUnit = vUnit(toLightVec[0],toLightVec[1],toLightVec[2]);
for (let j = 0; j < sRayCount; j++) {
....
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。