提交 a1dae33e 编写于 作者: M Mr.doob

Updated builds.

上级 1900b262
...@@ -36176,7 +36176,7 @@ THREE.ShadowMapPlugin.__projector = new THREE.Projector(); ...@@ -36176,7 +36176,7 @@ THREE.ShadowMapPlugin.__projector = new THREE.Projector();
THREE.SpritePlugin = function () { THREE.SpritePlugin = function () {
var _gl, _renderer, _precision; var _gl, _renderer, _texture;
var vertices, faces, vertexBuffer, elementBuffer; var vertices, faces, vertexBuffer, elementBuffer;
var program, attributes, uniforms; var program, attributes, uniforms;
...@@ -36186,8 +36186,6 @@ THREE.SpritePlugin = function () { ...@@ -36186,8 +36186,6 @@ THREE.SpritePlugin = function () {
_gl = renderer.context; _gl = renderer.context;
_renderer = renderer; _renderer = renderer;
_precision = renderer.getPrecision();
vertices = new Float32Array( [ vertices = new Float32Array( [
- 0.5, - 0.5, 0, 0, - 0.5, - 0.5, 0, 0,
0.5, - 0.5, 1, 0, 0.5, - 0.5, 1, 0,
...@@ -36209,7 +36207,7 @@ THREE.SpritePlugin = function () { ...@@ -36209,7 +36207,7 @@ THREE.SpritePlugin = function () {
_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, elementBuffer ); _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
_gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, faces, _gl.STATIC_DRAW ); _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, faces, _gl.STATIC_DRAW );
program = createProgram( THREE.ShaderSprite[ 'sprite' ], _precision ); program = createProgram();
attributes = { attributes = {
position: _gl.getAttribLocation ( program, 'position' ), position: _gl.getAttribLocation ( program, 'position' ),
...@@ -36231,15 +36229,26 @@ THREE.SpritePlugin = function () { ...@@ -36231,15 +36229,26 @@ THREE.SpritePlugin = function () {
modelViewMatrix: _gl.getUniformLocation( program, 'modelViewMatrix' ), modelViewMatrix: _gl.getUniformLocation( program, 'modelViewMatrix' ),
projectionMatrix: _gl.getUniformLocation( program, 'projectionMatrix' ), projectionMatrix: _gl.getUniformLocation( program, 'projectionMatrix' ),
fogType: _gl.getUniformLocation( program, 'fogType' ), fogType: _gl.getUniformLocation( program, 'fogType' ),
fogDensity: _gl.getUniformLocation( program, 'fogDensity' ), fogDensity: _gl.getUniformLocation( program, 'fogDensity' ),
fogNear: _gl.getUniformLocation( program, 'fogNear' ), fogNear: _gl.getUniformLocation( program, 'fogNear' ),
fogFar: _gl.getUniformLocation( program, 'fogFar' ), fogFar: _gl.getUniformLocation( program, 'fogFar' ),
fogColor: _gl.getUniformLocation( program, 'fogColor' ), fogColor: _gl.getUniformLocation( program, 'fogColor' ),
alphaTest: _gl.getUniformLocation( program, 'alphaTest' ) alphaTest: _gl.getUniformLocation( program, 'alphaTest' )
}; };
var canvas = document.createElement( 'canvas' );
canvas.width = 8;
canvas.height = 8;
var context = canvas.getContext( '2d' );
context.fillStyle = '#ffffff';
context.fillRect( 0, 0, canvas.width, canvas.height );
_texture = new THREE.Texture( canvas );
_texture.needsUpdate = true;
}; };
this.render = function ( scene, camera, viewportWidth, viewportHeight ) { this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
...@@ -36332,54 +36341,60 @@ THREE.SpritePlugin = function () { ...@@ -36332,54 +36341,60 @@ THREE.SpritePlugin = function () {
for( i = 0; i < nSprites; i ++ ) { for( i = 0; i < nSprites; i ++ ) {
sprite = sprites[ i ]; sprite = sprites[ i ];
if ( sprite.visible === false ) continue;
material = sprite.material; material = sprite.material;
if ( ! sprite.visible || material.opacity === 0 ) continue; _gl.uniform1f( uniforms.alphaTest, material.alphaTest );
_gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements );
if ( material.map && material.map.image && material.map.image.width ) { scale[ 0 ] = sprite.scale.x;
scale[ 1 ] = sprite.scale.y;
_gl.uniform1f( uniforms.alphaTest, material.alphaTest ); if ( scene.fog && material.fog ) {
_gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements );
scale[ 0 ] = sprite.scale.x; fogType = sceneFogType;
scale[ 1 ] = sprite.scale.y;
if ( scene.fog && material.fog ) { } else {
fogType = sceneFogType; fogType = 0;
} else { }
fogType = 0; if ( oldFogType !== fogType ) {
} _gl.uniform1i( uniforms.fogType, fogType );
oldFogType = fogType;
if ( oldFogType !== fogType ) { }
_gl.uniform1i( uniforms.fogType, fogType ); _gl.uniform2f( uniforms.uvScale, material.uvScale.x, material.uvScale.y );
oldFogType = fogType; _gl.uniform2f( uniforms.uvOffset, material.uvOffset.x, material.uvOffset.y );
} _gl.uniform1f( uniforms.opacity, material.opacity );
_gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
_gl.uniform2f( uniforms.uvScale, material.uvScale.x, material.uvScale.y ); _gl.uniform1f( uniforms.rotation, material.rotation );
_gl.uniform2f( uniforms.uvOffset, material.uvOffset.x, material.uvOffset.y ); _gl.uniform2fv( uniforms.scale, scale );
_gl.uniform2f( uniforms.halfViewport, halfViewportWidth, halfViewportHeight );
_gl.uniform1f( uniforms.opacity, material.opacity ); _renderer.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
_gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b ); _renderer.setDepthTest( material.depthTest );
_renderer.setDepthWrite( material.depthWrite );
_gl.uniform1f( uniforms.rotation, material.rotation ); if ( material.map && material.map.image && material.map.image.width ) {
_gl.uniform2fv( uniforms.scale, scale );
_gl.uniform2f( uniforms.halfViewport, halfViewportWidth, halfViewportHeight );
_renderer.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
_renderer.setDepthTest( material.depthTest );
_renderer.setDepthWrite( material.depthWrite );
_renderer.setTexture( material.map, 0 ); _renderer.setTexture( material.map, 0 );
_gl.drawElements( _gl.TRIANGLES, 6, _gl.UNSIGNED_SHORT, 0 ); } else {
_renderer.setTexture( _texture, 0 );
} }
_gl.drawElements( _gl.TRIANGLES, 6, _gl.UNSIGNED_SHORT, 0 );
} }
// restore gl // restore gl
...@@ -36388,23 +36403,107 @@ THREE.SpritePlugin = function () { ...@@ -36388,23 +36403,107 @@ THREE.SpritePlugin = function () {
}; };
function createProgram ( shader, precision ) { function createProgram () {
var program = _gl.createProgram(); var program = _gl.createProgram();
var fragmentShader = _gl.createShader( _gl.FRAGMENT_SHADER );
var vertexShader = _gl.createShader( _gl.VERTEX_SHADER ); var vertexShader = _gl.createShader( _gl.VERTEX_SHADER );
var fragmentShader = _gl.createShader( _gl.FRAGMENT_SHADER );
var prefix = 'precision ' + precision + ' float;\n'; _gl.shaderSource( vertexShader, [
_gl.shaderSource( fragmentShader, prefix + shader.fragmentShader ); 'precision ' + _renderer.getPrecision() + ' float;',
_gl.shaderSource( vertexShader, prefix + shader.vertexShader );
'uniform mat4 modelViewMatrix;',
'uniform mat4 projectionMatrix;',
'uniform float rotation;',
'uniform vec2 scale;',
'uniform vec2 uvOffset;',
'uniform vec2 uvScale;',
'uniform vec2 halfViewport;',
'attribute vec2 position;',
'attribute vec2 uv;',
'varying vec2 vUV;',
'void main() {',
'vUV = uvOffset + uv * uvScale;',
'vec2 alignedPosition = position * scale;',
'vec2 rotatedPosition;',
'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
'vec4 finalPosition;',
'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
'finalPosition.xy += rotatedPosition;',
'finalPosition = projectionMatrix * finalPosition;',
'gl_Position = finalPosition;',
'}'
].join( '\n' ) );
_gl.shaderSource( fragmentShader, [
'precision ' + _renderer.getPrecision() + ' float;',
'uniform vec3 color;',
'uniform sampler2D map;',
'uniform float opacity;',
'uniform int fogType;',
'uniform vec3 fogColor;',
'uniform float fogDensity;',
'uniform float fogNear;',
'uniform float fogFar;',
'uniform float alphaTest;',
'varying vec2 vUV;',
'void main() {',
'vec4 texture = texture2D( map, vUV );',
'if ( texture.a < alphaTest ) discard;',
'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
'if ( fogType > 0 ) {',
'float depth = gl_FragCoord.z / gl_FragCoord.w;',
'float fogFactor = 0.0;',
'if ( fogType == 1 ) {',
'fogFactor = smoothstep( fogNear, fogFar, depth );',
'} else {',
'const float LOG2 = 1.442695;',
'float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
'}',
'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
'}',
'}'
].join( '\n' ) );
_gl.compileShader( fragmentShader );
_gl.compileShader( vertexShader ); _gl.compileShader( vertexShader );
_gl.compileShader( fragmentShader );
_gl.attachShader( program, fragmentShader );
_gl.attachShader( program, vertexShader ); _gl.attachShader( program, vertexShader );
_gl.attachShader( program, fragmentShader );
_gl.linkProgram( program ); _gl.linkProgram( program );
...@@ -36815,102 +36914,3 @@ THREE.ShaderFlares = { ...@@ -36815,102 +36914,3 @@ THREE.ShaderFlares = {
}; };
/**
* @author mikael emtinger / http://gomo.se/
* @author alteredq / http://alteredqualia.com/
*
*/
THREE.ShaderSprite = {
'sprite': {
vertexShader: [
"uniform mat4 modelViewMatrix;",
"uniform mat4 projectionMatrix;",
"uniform float rotation;",
"uniform vec2 scale;",
"uniform vec2 uvOffset;",
"uniform vec2 uvScale;",
"uniform vec2 halfViewport;",
"attribute vec2 position;",
"attribute vec2 uv;",
"varying vec2 vUV;",
"void main() {",
"vUV = uvOffset + uv * uvScale;",
"vec2 alignedPosition = position * scale;",
"vec2 rotatedPosition;",
"rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;",
"rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;",
"vec4 finalPosition;",
"finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );",
"finalPosition.xy += rotatedPosition;",
"finalPosition = projectionMatrix * finalPosition;",
"gl_Position = finalPosition;",
"}"
].join( "\n" ),
fragmentShader: [
"uniform vec3 color;",
"uniform sampler2D map;",
"uniform float opacity;",
"uniform int fogType;",
"uniform vec3 fogColor;",
"uniform float fogDensity;",
"uniform float fogNear;",
"uniform float fogFar;",
"uniform float alphaTest;",
"varying vec2 vUV;",
"void main() {",
"vec4 texture = texture2D( map, vUV );",
"if ( texture.a < alphaTest ) discard;",
"gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );",
"if ( fogType > 0 ) {",
"float depth = gl_FragCoord.z / gl_FragCoord.w;",
"float fogFactor = 0.0;",
"if ( fogType == 1 ) {",
"fogFactor = smoothstep( fogNear, fogFar, depth );",
"} else {",
"const float LOG2 = 1.442695;",
"float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );",
"fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );",
"}",
"gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );",
"}",
"}"
].join( "\n" )
}
};
因为 它太大了无法显示 source diff 。你可以改为 查看blob
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册