我有一个相机动画,我会将移动角度传递给2d精灵着色器。我猜我应该将这2个矢量投影到相机然后计算角度,但它不起作用。
let prevCameraVector = null;
function tick() {
if(prevCameraVector && !prevCameraVector.equals(camera.position)) {
let vector1 = prevCameraVector;
let vector2 = new THREE.Vector3(camera.position.x, camera.position.y, camera.position.z);
vector1.project(camera);
vector2.project(camera);
let angle = vector1.angleTo(vector2);
uniforms.uRotate.value = angle;
}
prevCameraVector = new THREE.Vector3(camera.position.x, camera.position.y, camera.position.z);
}
答案 0 :(得分:0)
我找到了一个运动模糊的例子并采用了该算法。它现在有效。 http://www.zeropointnine.com/blog/motion-blur-shader/
let prevCameraVector = null;
function tick() {
if (prevCameraVector && !prevCameraVector.equals(camera.position)) {
let vector1 = prevCameraVector;
let vector2 = new THREE.Vector3(camera.position.x, camera.position.y, camera.position.z);
vector1.project(this.camera);
vector2.project(this.camera);
vector2.sub(vector1);
vector2.y *= window.innerWidth / window.innerHeight;
let angle = Math.atan2(vector2.x, vector2.y);
uniforms.uRotate.value = angle;
}
prevCameraVector = new THREE.Vector3(camera.position.x, camera.position.y, camera.position.z);
}