发送到顶点着色器和片元着色器的GLSL程序的构造函数, 包含默认的变量(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 Geometry and 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_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;


[name]( [param:WebGLRenderer renderer], [param:String cacheKey], [param:Object parameters] )

参数详见[page:WebGLRenderer WebGLRenderer].


[property:String name]

The name of the respective shader program.

[property:String id]

The identifier of this instance.

[property:String cacheKey]

This key enables the reusability of a single [name] for different materials.

[property:Integer usedTimes]

How many times this instance is used for rendering render items.

[property:Object program]

The actual shader program.

[property:WebGLShader vertexShader]

An instance of [page:WebGLShader] representing the vertex shader.

[property:WebGLShader fragmentShader]

An instance of [page:WebGLShader] representing the frament shader.


[method:Object getUniforms]()


[method:Object getAttributes]()


[method:null destroy]()

Destroys an instance of [name].


[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]