添加着色器代码。

This commit is contained in:
tengge1 2019-03-14 19:48:51 +08:00
parent 3afc2ea1d0
commit bd2d3801ef
3 changed files with 22 additions and 0 deletions

View File

@ -1,4 +1,7 @@
import applyMatrix4 from './vec3/applyMatrix4.glsl';
import lengthSq from './vec3/lengthSq.glsl';
import angleTo from './vec3/angleTo.glsl';
import makeOrthographic from './mat4/makeOrthographic.glsl';
import makePerspective from './mat4/makePerspective.glsl';
import makePerspective2 from './mat4/makePerspective2.glsl';
@ -9,6 +12,8 @@ import decomposeMatrix from './mat4/decomposeMatrix.glsl';
Object.assign(THREE.ShaderChunk, {
// vec3
applyMatrix4: applyMatrix4,
lengthSq: lengthSq,
angleTo: angleTo,
// mat4
makeOrthographic: makeOrthographic,

View File

@ -0,0 +1,11 @@
#include <lengthSq>
/**
* 求两个向量之间的夹角
*/
float angleTo(vec3 v1, vec3 v2) {
float theta = dot(v1, v2) / sqrt(lengthSq(v1) * lengthSq(v2) );
// clamp, to handle numerical problems
return acos(clamp(theta, -1.0, 1.0));
}

View File

@ -0,0 +1,6 @@
/**
* 计算vec3长度的平方
*/
float lengthSq(vec3 v) {
return v.x * v.x + v.y * v.y + v.z * v.z;
}