Three.js shader内置矩阵注入

common matrices (公共矩阵)
three.jsWebGLRendersetProgram函数注入

javascript 复制代码
p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
javascript 复制代码
// = 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;
javascript 复制代码
// default vertex attributes provided by BufferGeometry
attribute vec3 position;
attribute vec3 normal;
attribute vec2 uv;
javascript 复制代码
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
javascript 复制代码
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4( position, 1.0 );
javascript 复制代码
#ifdef USE_TANGENT
	attribute vec4 tangent;
#endif
#if defined( USE_COLOR_ALPHA )
	// vertex color attribute with alpha
	attribute vec4 color;
#elif defined( USE_COLOR )
	// vertex color attribute
	attribute vec3 color;
#endif
javascript 复制代码
#ifdef USE_MORPHTARGETS

	attribute vec3 morphTarget0;
	attribute vec3 morphTarget1;
	attribute vec3 morphTarget2;
	attribute vec3 morphTarget3;

	#ifdef USE_MORPHNORMALS

		attribute vec3 morphNormal0;
		attribute vec3 morphNormal1;
		attribute vec3 morphNormal2;
		attribute vec3 morphNormal3;

	#else

		attribute vec3 morphTarget4;
		attribute vec3 morphTarget5;
		attribute vec3 morphTarget6;
		attribute vec3 morphTarget7;

	#endif
#endif
javascript 复制代码
#ifdef USE_SKINNING
	attribute vec4 skinIndex;
	attribute vec4 skinWeight;
#endif
javascript 复制代码
#ifdef USE_INSTANCING
	// Note that modelViewMatrix is not set when rendering an instanced model,
	// but can be calculated from viewMatrix * modelMatrix.
	//
	// Basic Usage:
	//   gl_Position = projectionMatrix * viewMatrix * modelMatrix * instanceMatrix * vec4(position, 1.0);
	attribute mat4 instanceMatrix;
#endif
javascript 复制代码
uniform mat4 viewMatrix;
uniform vec3 cameraPosition;
相关推荐
WYiQIU1 天前
11月面了7.8家前端岗,兄弟们12月我先躺为敬...
前端·vue.js·react.js·面试·前端框架·飞书
谢尔登1 天前
简单聊聊webpack摇树的原理
运维·前端·webpack
娃哈哈哈哈呀1 天前
formData 传参 如何传数组
前端·javascript·vue.js
zhu_zhu_xia1 天前
vue3+vite打包出现内存溢出问题
前端·vue
tsumikistep1 天前
【前后端】接口文档与导入
前端·后端·python·硬件架构
行走的陀螺仪1 天前
.vscode 文件夹配置详解
前端·ide·vscode·编辑器·开发实践
2503_928411561 天前
11.24 Vue-组件2
前端·javascript·vue.js
Bigger1 天前
🎨 用一次就爱上的图标定制体验:CustomIcons 实战
前端·react.js·icon
谢尔登1 天前
原来Webpack在大厂中这样进行性能优化!
前端·webpack·性能优化
g***B7381 天前
JavaScript在Node.js中的模块系统
开发语言·javascript·node.js