codecamp

three.js WebGLProgram

发送到顶点着色器和片元着色器的GLSL程序的构造函数, 包含默认的变量(uniforms)和属性

内置的变量(uniforms)和属性

顶点着色器(无条件的):

// = 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;

注意,可以通过以下方式计算顶点着色器中顶点的位置:

gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );

或者也可以这样:

gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4( position, 1.0 );

顶点着色器(有条件的):

#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
#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
#ifdef USE_SKINNING
	attribute vec4 skinIndex;
	attribute vec4 skinWeight;
#endif

片元着色器:

uniform mat4 viewMatrix;
uniform vec3 cameraPosition;

构造器

WebGLProgram( renderer : WebGLRenderer, cacheKey : String, parameters : Object )

参数详见WebGLRenderer.

属性

.name : String

相应着色器程序的名称。

.id : String

该实例的 id 标识。

.cacheKey : String

启用这个 key 之后,能够实现单个 WebGLProgram 不同材料的可重用性。

.usedTimes : Integer

此实例用于渲染渲染项的次数。

.program : Object

实际的着色器程序。

.vertexShader : WebGLShader

顶点着色器。

.fragmentShader : WebGLShader

片元着色器。

方法

.getUniforms () : Object

返回所有活动态的变量(uniform)位置的name-value映射

.getAttributes () : Object

返回所有活动态的顶点属性位置的name-value映射

.destroy () : undefined

销毁 WebGLProgram 的实例。

源码

src/renderers/webgl/WebGLProgram.js


开发者参考
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

参考

核心 / BufferAttributes

渲染器 / WebXR

开发者参考

WebGL渲染器

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }