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;
相关推荐
etcix6 小时前
dmenux.c: integrate dmenu project as one file
c语言·前端·算法
光影少年6 小时前
react16到react19更新及底层实现是什么以及区别
前端·react.js·前端框架
超人不会飛6 小时前
vue3 markdown组件|大模型应用专用
前端·vue.js·人工智能
じòぴé南冸じょうげん6 小时前
微信小程序如何进行分包处理?
前端·小程序
Jolyne_6 小时前
Table自定义单元格渲染分享
前端
加载中3616 小时前
pnpm时代包版本不一致问题还是否存在
前端·面试·npm
老马啊老马6 小时前
30 分钟搞定!Docker+Jenkins+Nginx + 腾讯云实现前端 CI/CD
前端
VillenK6 小时前
用插件的方式注入Vue组件
前端·vue.js
掘金安东尼6 小时前
Node.js 如何在 2025 年挤压 I/O 性能
前端·javascript·github