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

Updated builds.

上级 150e168e
......@@ -3826,6 +3826,7 @@
/**
* @author alteredq / http://alteredqualia.com
* @author WestLangley / http://github.com/WestLangley
*/
function WebGLRenderTargetCube( width, height, options ) {
......@@ -3839,6 +3840,97 @@
WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
WebGLRenderTargetCube.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
this.texture.type = texture.type;
this.texture.format = texture.format;
this.texture.encoding = texture.encoding;
var scene = new THREE.Scene();
var shader = {
uniforms: {
tEquirect: { value: null },
},
vertexShader: [
"varying vec3 vWorldDirection;",
"vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
" return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
"}",
"void main() {",
" vWorldDirection = transformDirection( position, modelMatrix );",
" #include <begin_vertex>",
" #include <project_vertex>",
"}"
].join( '\n' ),
fragmentShader: [
"uniform sampler2D tEquirect;",
"varying vec3 vWorldDirection;",
"#define RECIPROCAL_PI 0.31830988618",
"#define RECIPROCAL_PI2 0.15915494",
"void main() {",
" vec3 direction = normalize( vWorldDirection );",
" vec2 sampleUV;",
" sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;",
" sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
" gl_FragColor = texture2D( tEquirect, sampleUV );",
"}"
].join( '\n' ),
};
var material = new THREE.ShaderMaterial( {
type: 'CubemapFromEquirect',
uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader,
side: THREE.BackSide,
blending: THREE.NoBlending
} );
material.uniforms.tEquirect.value = texture;
var mesh = new THREE.Mesh( new THREE.BoxBufferGeometry( 5, 5, 5 ), material );
scene.add( mesh );
var camera = new THREE.CubeCamera( 1, 10, 1 );
camera.renderTarget = this;
camera.renderTarget.texture.name = 'CubeCameraTexture';
camera.update( renderer, scene );
mesh.geometry.dispose();
mesh.material.dispose();
return this;
};
/**
* @author alteredq / http://alteredqualia.com/
*/
......@@ -6171,7 +6263,7 @@
var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif";
......@@ -17126,7 +17218,7 @@
}
function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures ) {
function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities ) {
var gl = renderer.context;
......@@ -17595,7 +17687,7 @@
if ( cachedUniforms === undefined ) {
cachedUniforms = new WebGLUniforms( gl, program, textures );
cachedUniforms = new WebGLUniforms( gl, program );
}
......@@ -17628,31 +17720,6 @@
};
// DEPRECATED
Object.defineProperties( this, {
uniforms: {
get: function () {
console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
return this.getUniforms();
}
},
attributes: {
get: function () {
console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
return this.getAttributes();
}
}
} );
//
this.name = shader.name;
......@@ -17671,7 +17738,7 @@
* @author mrdoob / http://mrdoob.com/
*/
function WebGLPrograms( renderer, extensions, capabilities, textures ) {
function WebGLPrograms( renderer, extensions, capabilities ) {
var programs = [];
......@@ -17945,7 +18012,7 @@
if ( program === undefined ) {
program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures );
program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities );
programs.push( program );
}
......@@ -22990,7 +23057,7 @@
geometries = new WebGLGeometries( _gl, attributes, info );
objects = new WebGLObjects( geometries, info );
morphtargets = new WebGLMorphtargets( _gl );
programCache = new WebGLPrograms( _this, extensions, capabilities, textures );
programCache = new WebGLPrograms( _this, extensions, capabilities );
renderLists = new WebGLRenderLists();
renderStates = new WebGLRenderStates();
......@@ -25823,9 +25890,18 @@
return function raycast( raycaster, intersects ) {
worldScale.setFromMatrixScale( this.matrixWorld );
viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld );
viewWorldMatrix.copy( raycaster._camera.matrixWorld );
this.modelViewMatrix.multiplyMatrices( raycaster._camera.matrixWorldInverse, this.matrixWorld );
mvPosition.setFromMatrixPosition( this.modelViewMatrix );
if ( raycaster._camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
worldScale.multiplyScalar( - mvPosition.z );
}
var rotation = this.material.rotation;
var sin, cos;
if ( rotation !== 0 ) {
......@@ -44503,11 +44579,13 @@
this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
this._camera = camera;
} else if ( ( camera && camera.isOrthographicCamera ) ) {
this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
this._camera = camera;
} else {
此差异已折叠。
......@@ -3820,6 +3820,7 @@ WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRend
/**
* @author alteredq / http://alteredqualia.com
* @author WestLangley / http://github.com/WestLangley
*/
function WebGLRenderTargetCube( width, height, options ) {
......@@ -3833,6 +3834,97 @@ WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
WebGLRenderTargetCube.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
this.texture.type = texture.type;
this.texture.format = texture.format;
this.texture.encoding = texture.encoding;
var scene = new THREE.Scene();
var shader = {
uniforms: {
tEquirect: { value: null },
},
vertexShader: [
"varying vec3 vWorldDirection;",
"vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
" return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
"}",
"void main() {",
" vWorldDirection = transformDirection( position, modelMatrix );",
" #include <begin_vertex>",
" #include <project_vertex>",
"}"
].join( '\n' ),
fragmentShader: [
"uniform sampler2D tEquirect;",
"varying vec3 vWorldDirection;",
"#define RECIPROCAL_PI 0.31830988618",
"#define RECIPROCAL_PI2 0.15915494",
"void main() {",
" vec3 direction = normalize( vWorldDirection );",
" vec2 sampleUV;",
" sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;",
" sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
" gl_FragColor = texture2D( tEquirect, sampleUV );",
"}"
].join( '\n' ),
};
var material = new THREE.ShaderMaterial( {
type: 'CubemapFromEquirect',
uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader,
side: THREE.BackSide,
blending: THREE.NoBlending
} );
material.uniforms.tEquirect.value = texture;
var mesh = new THREE.Mesh( new THREE.BoxBufferGeometry( 5, 5, 5 ), material );
scene.add( mesh );
var camera = new THREE.CubeCamera( 1, 10, 1 );
camera.renderTarget = this;
camera.renderTarget.texture.name = 'CubeCameraTexture';
camera.update( renderer, scene );
mesh.geometry.dispose();
mesh.material.dispose();
return this;
};
/**
* @author alteredq / http://alteredqualia.com/
*/
......@@ -6165,7 +6257,7 @@ var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n
var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif";
......@@ -17120,7 +17212,7 @@ function unrollLoops( string ) {
}
function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures ) {
function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities ) {
var gl = renderer.context;
......@@ -17589,7 +17681,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
if ( cachedUniforms === undefined ) {
cachedUniforms = new WebGLUniforms( gl, program, textures );
cachedUniforms = new WebGLUniforms( gl, program );
}
......@@ -17622,31 +17714,6 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
};
// DEPRECATED
Object.defineProperties( this, {
uniforms: {
get: function () {
console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
return this.getUniforms();
}
},
attributes: {
get: function () {
console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
return this.getAttributes();
}
}
} );
//
this.name = shader.name;
......@@ -17665,7 +17732,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters,
* @author mrdoob / http://mrdoob.com/
*/
function WebGLPrograms( renderer, extensions, capabilities, textures ) {
function WebGLPrograms( renderer, extensions, capabilities ) {
var programs = [];
......@@ -17939,7 +18006,7 @@ function WebGLPrograms( renderer, extensions, capabilities, textures ) {
if ( program === undefined ) {
program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures );
program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities );
programs.push( program );
}
......@@ -22984,7 +23051,7 @@ function WebGLRenderer( parameters ) {
geometries = new WebGLGeometries( _gl, attributes, info );
objects = new WebGLObjects( geometries, info );
morphtargets = new WebGLMorphtargets( _gl );
programCache = new WebGLPrograms( _this, extensions, capabilities, textures );
programCache = new WebGLPrograms( _this, extensions, capabilities );
renderLists = new WebGLRenderLists();
renderStates = new WebGLRenderStates();
......@@ -25817,9 +25884,18 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
return function raycast( raycaster, intersects ) {
worldScale.setFromMatrixScale( this.matrixWorld );
viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld );
viewWorldMatrix.copy( raycaster._camera.matrixWorld );
this.modelViewMatrix.multiplyMatrices( raycaster._camera.matrixWorldInverse, this.matrixWorld );
mvPosition.setFromMatrixPosition( this.modelViewMatrix );
if ( raycaster._camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
worldScale.multiplyScalar( - mvPosition.z );
}
var rotation = this.material.rotation;
var sin, cos;
if ( rotation !== 0 ) {
......@@ -44497,11 +44573,13 @@ Object.assign( Raycaster.prototype, {
this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
this._camera = camera;
} else if ( ( camera && camera.isOrthographicCamera ) ) {
this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
this._camera = camera;
} else {
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册