Three.js shader内置矩阵注入

common matrices (公共矩阵)
three.js 在WebGLRender中setProgram函数注入

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;
相关推荐
非优秀程序员7 小时前
第10章 千团出世|《互联网产品恩仇录》
前端
非优秀程序员7 小时前
第11章 小高在对面|《互联网产品恩仇录》
前端
非优秀程序员7 小时前
第14章 只剩美团|《互联网产品恩仇录》
前端
非优秀程序员7 小时前
第09章 老乡何必为难老乡|《互联网产品恩仇录》
前端
非优秀程序员7 小时前
第07章 孙德良的阳谋|《互联网产品恩仇录》
javascript·后端
非优秀程序员7 小时前
第03章 三大门户,烽烟起于瀛海威|《互联网产品恩仇录》
前端
程序员大阳11 小时前
HTML+CSS+JS对话式实战(5)-活动管理页之查看报名名单的实现
javascript·css·html·查看报名名单
曦樂~11 小时前
【Web Development】02 CSS
前端·css
风骏时光牛马12 小时前
后端服务接口开发与数据逻辑处理
前端
东鹏特饮12 小时前
经典打砖块(Breakout)游戏
前端·css·css3