klren0312 / daliy_knowledge

知识积累,正确使用方式是watch
21 stars 4 forks source link

threejs shader内置变量 #708

Open klren0312 opened 1 year ago

klren0312 commented 1 year ago

顶点着色器

// = object.matrixWorld
uniform mat4 modelMatrix;

// = camera.matrixWorldInverse * object.matrixWorld
uniform mat4 modelViewMatrix;

// = camera.projectionMatrix
uniform mat4 projectionMatrix;

// = camera.matrixWorldInverse
uniform mat4 viewMatrix;

// = inverse transpose of modelViewMatrix
uniform mat3 normalMatrix;

// = camera position in world space
uniform vec3 cameraPosition;

// default vertex attributes provided by BufferGeometry
attribute vec3 position;
attribute vec3 normal;
attribute vec2 uv;

片元着色器

uniform mat4 viewMatrix;
uniform vec3 cameraPosition;

参考资料

https://threejs.org/docs/index.html#api/zh/renderers/webgl/WebGLProgram