diff --git a/docs/api/objects/PointCloud.html b/docs/api/objects/PointCloud.html index 8195ba4f3c992cd8acfe3db047180e5141e7189b..6dcfa9f0ea5e9b85bafd9a9c82a29acfa4a5496a 100644 --- a/docs/api/objects/PointCloud.html +++ b/docs/api/objects/PointCloud.html @@ -16,7 +16,6 @@

Constructor

-

[name]( [page:Geometry geometry], [page:Material material] )

@@ -24,6 +23,7 @@ material — An instance of [page:Material] (optional).
+

Properties

[property:Geometry geometry]

@@ -34,10 +34,6 @@
An instance of [page:Material], defining the object's appearance. Default is a [page:PointCloudMaterial] with randomised colour.
-

[property:boolean sortParticles]

-
- When set, then the particles should be depth sorted (from far to near), based on camera, in the renderer every frame. -

Methods

@@ -46,8 +42,10 @@ This creates a clone of the particle system. +

Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] + diff --git a/examples/webgl_custom_attributes_particles.html b/examples/webgl_custom_attributes_particles.html index b710f3908f454e21d38152a2692c8462163f252c..8a25a2116f32a10ad055ed7d63486c9e98c21748 100644 --- a/examples/webgl_custom_attributes_particles.html +++ b/examples/webgl_custom_attributes_particles.html @@ -148,9 +148,6 @@ sphere = new THREE.PointCloud( geometry, shaderMaterial ); - sphere.dynamic = true; - //sphere.sortParticles = true; - var vertices = sphere.geometry.vertices; var values_size = attributes.size.value; var values_color = attributes.customColor.value; diff --git a/examples/webgl_custom_attributes_particles2.html b/examples/webgl_custom_attributes_particles2.html index 92d239cd2ebda5d31b5ec59b89f1d3cd6a1a738e..92ccb55dd4669d6b45e624144fc03c6ee94aa096 100644 --- a/examples/webgl_custom_attributes_particles2.html +++ b/examples/webgl_custom_attributes_particles2.html @@ -67,8 +67,11 @@ void main() { - gl_FragColor = vec4( color * vColor, 1.0 ); - gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord ); + vec4 color = vec4( color * vColor, 1.0 ) * texture2D( texture, gl_PointCoord ); + + if ( color.w < 0.5 ) discard; + + gl_FragColor = color; } @@ -136,9 +139,6 @@ sphere = new THREE.PointCloud( geometry, shaderMaterial ); - sphere.dynamic = true; - sphere.sortParticles = true; - var vertices = sphere.geometry.vertices; var values_size = attributes.size.value; var values_color = attributes.ca.value; diff --git a/examples/webgl_particles_billboards.html b/examples/webgl_particles_billboards.html index aac4896ee400158601077f495b9f4b1ea38e3ca1..7bc4b7259b7051ebc3f2f6636b72b6654924e19f 100644 --- a/examples/webgl_particles_billboards.html +++ b/examples/webgl_particles_billboards.html @@ -81,11 +81,10 @@ } - material = new THREE.PointCloudMaterial( { size: 35, sizeAttenuation: false, map: sprite, transparent: true } ); + material = new THREE.PointCloudMaterial( { size: 35, sizeAttenuation: false, map: sprite, alphaTest: 0.5, transparent: true } ); material.color.setHSL( 1.0, 0.3, 0.7 ); particles = new THREE.PointCloud( geometry, material ); - particles.sortParticles = true; scene.add( particles ); // diff --git a/examples/webgl_particles_billboards_colors.html b/examples/webgl_particles_billboards_colors.html index 621cd5ec82231c4017ad0841a839db7998c1ff93..0f6c5fc993f8d3862188824e13211bfbf05245cc 100644 --- a/examples/webgl_particles_billboards_colors.html +++ b/examples/webgl_particles_billboards_colors.html @@ -86,12 +86,10 @@ geometry.colors = colors; - material = new THREE.PointCloudMaterial( { size: 85, map: sprite, vertexColors: THREE.VertexColors, transparent: true } ); + material = new THREE.PointCloudMaterial( { size: 85, map: sprite, vertexColors: THREE.VertexColors, alphaTest: 0.5, transparent: true } ); material.color.setHSL( 1.0, 0.2, 0.7 ); particles = new THREE.PointCloud( geometry, material ); - particles.sortParticles = true; - scene.add( particles ); // diff --git a/examples/webgl_particles_shapes.html b/examples/webgl_particles_shapes.html index d1cff0b78427249eec981241bae2341343985e54..46c405d4c45c267d467ae041ba8210260eed7f08 100644 --- a/examples/webgl_particles_shapes.html +++ b/examples/webgl_particles_shapes.html @@ -346,9 +346,6 @@ particleCloud = new THREE.PointCloud( particles, shaderMaterial ); - particleCloud.dynamic = true; - // particleCloud.sortParticles = true; - var vertices = particleCloud.geometry.vertices; var values_size = attributes.size.value; var values_color = attributes.pcolor.value; diff --git a/src/objects/PointCloud.js b/src/objects/PointCloud.js index c2ffead00a77e065e50041d8d486a6c8ebed8440..9a14a6b010f3a34cc1935ed10d803c7ef659da6f 100644 --- a/src/objects/PointCloud.js +++ b/src/objects/PointCloud.js @@ -11,8 +11,6 @@ THREE.PointCloud = function ( geometry, material ) { this.geometry = geometry !== undefined ? geometry : new THREE.Geometry(); this.material = material !== undefined ? material : new THREE.PointCloudMaterial( { color: Math.random() * 0xffffff } ); - this.sortParticles = false; - }; THREE.PointCloud.prototype = Object.create( THREE.Object3D.prototype ); @@ -149,8 +147,6 @@ THREE.PointCloud.prototype.clone = function ( object ) { if ( object === undefined ) object = new THREE.PointCloud( this.geometry, this.material ); - object.sortParticles = this.sortParticles; - THREE.Object3D.prototype.clone.call( this, object ); return object; diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 9fed6cd20d364c874ab8ed0402f1600e1111377d..5bc7b34563e646062e4bad678a45cf6152a2414c 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -1202,28 +1202,12 @@ THREE.WebGLRenderer = function ( parameters ) { a, ca, cal, value, customAttribute; - if ( object.sortParticles ) { - - _projScreenMatrixPS.copy( _projScreenMatrix ); - _projScreenMatrixPS.multiply( object.matrixWorld ); + if ( dirtyVertices ) { for ( v = 0; v < vl; v ++ ) { vertex = vertices[ v ]; - _vector3.copy( vertex ); - _vector3.applyProjection( _projScreenMatrixPS ); - - sortArray[ v ] = [ _vector3.z, v ]; - - } - - sortArray.sort( numericalSort ); - - for ( v = 0; v < vl; v ++ ) { - - vertex = vertices[ sortArray[ v ][ 1 ] ]; - offset = v * 3; vertexArray[ offset ] = vertex.x; @@ -1232,11 +1216,18 @@ THREE.WebGLRenderer = function ( parameters ) { } + _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglVertexBuffer ); + _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint ); + + } + + if ( dirtyColors ) { + for ( c = 0; c < cl; c ++ ) { - offset = c * 3; + color = colors[ c ]; - color = colors[ sortArray[ c ][ 1 ] ]; + offset = c * 3; colorArray[ offset ] = color.r; colorArray[ offset + 1 ] = color.g; @@ -1244,25 +1235,28 @@ THREE.WebGLRenderer = function ( parameters ) { } - if ( customAttributes ) { + _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglColorBuffer ); + _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint ); - for ( i = 0, il = customAttributes.length; i < il; i ++ ) { + } - customAttribute = customAttributes[ i ]; + if ( customAttributes ) { - if ( ! ( customAttribute.boundTo === undefined || customAttribute.boundTo === 'vertices' ) ) continue; + for ( i = 0, il = customAttributes.length; i < il; i ++ ) { - offset = 0; + customAttribute = customAttributes[ i ]; + + if ( customAttribute.needsUpdate && ( customAttribute.boundTo === undefined || customAttribute.boundTo === 'vertices' ) ) { cal = customAttribute.value.length; + offset = 0; + if ( customAttribute.size === 1 ) { for ( ca = 0; ca < cal; ca ++ ) { - index = sortArray[ ca ][ 1 ]; - - customAttribute.array[ ca ] = customAttribute.value[ index ]; + customAttribute.array[ ca ] = customAttribute.value[ ca ]; } @@ -1270,9 +1264,7 @@ THREE.WebGLRenderer = function ( parameters ) { for ( ca = 0; ca < cal; ca ++ ) { - index = sortArray[ ca ][ 1 ]; - - value = customAttribute.value[ index ]; + value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x; customAttribute.array[ offset + 1 ] = value.y; @@ -1287,11 +1279,9 @@ THREE.WebGLRenderer = function ( parameters ) { for ( ca = 0; ca < cal; ca ++ ) { - index = sortArray[ ca ][ 1 ]; - - value = customAttribute.value[ index ]; + value = customAttribute.value[ ca ]; - customAttribute.array[ offset ] = value.r; + customAttribute.array[ offset ] = value.r; customAttribute.array[ offset + 1 ] = value.g; customAttribute.array[ offset + 2 ] = value.b; @@ -1303,9 +1293,7 @@ THREE.WebGLRenderer = function ( parameters ) { for ( ca = 0; ca < cal; ca ++ ) { - index = sortArray[ ca ][ 1 ]; - - value = customAttribute.value[ index ]; + value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x; customAttribute.array[ offset + 1 ] = value.y; @@ -1321,9 +1309,7 @@ THREE.WebGLRenderer = function ( parameters ) { for ( ca = 0; ca < cal; ca ++ ) { - index = sortArray[ ca ][ 1 ]; - - value = customAttribute.value[ index ]; + value = customAttribute.value[ ca ]; customAttribute.array[ offset ] = value.x; customAttribute.array[ offset + 1 ] = value.y; @@ -1338,160 +1324,10 @@ THREE.WebGLRenderer = function ( parameters ) { } - } - - } else { - - if ( dirtyVertices ) { - - for ( v = 0; v < vl; v ++ ) { - - vertex = vertices[ v ]; - - offset = v * 3; - - vertexArray[ offset ] = vertex.x; - vertexArray[ offset + 1 ] = vertex.y; - vertexArray[ offset + 2 ] = vertex.z; - - } - - } - - if ( dirtyColors ) { - - for ( c = 0; c < cl; c ++ ) { - - color = colors[ c ]; - - offset = c * 3; - - colorArray[ offset ] = color.r; - colorArray[ offset + 1 ] = color.g; - colorArray[ offset + 2 ] = color.b; - - } - - } - - if ( customAttributes ) { - - for ( i = 0, il = customAttributes.length; i < il; i ++ ) { - - customAttribute = customAttributes[ i ]; - - if ( customAttribute.needsUpdate && - ( customAttribute.boundTo === undefined || - customAttribute.boundTo === 'vertices' ) ) { - - cal = customAttribute.value.length; - - offset = 0; - - if ( customAttribute.size === 1 ) { - - for ( ca = 0; ca < cal; ca ++ ) { - - customAttribute.array[ ca ] = customAttribute.value[ ca ]; - - } - - } else if ( customAttribute.size === 2 ) { - - for ( ca = 0; ca < cal; ca ++ ) { - - value = customAttribute.value[ ca ]; - - customAttribute.array[ offset ] = value.x; - customAttribute.array[ offset + 1 ] = value.y; - - offset += 2; - - } - - } else if ( customAttribute.size === 3 ) { - - if ( customAttribute.type === 'c' ) { - - for ( ca = 0; ca < cal; ca ++ ) { - - value = customAttribute.value[ ca ]; - - customAttribute.array[ offset ] = value.r; - customAttribute.array[ offset + 1 ] = value.g; - customAttribute.array[ offset + 2 ] = value.b; - - offset += 3; - - } - - } else { - - for ( ca = 0; ca < cal; ca ++ ) { - - value = customAttribute.value[ ca ]; - - customAttribute.array[ offset ] = value.x; - customAttribute.array[ offset + 1 ] = value.y; - customAttribute.array[ offset + 2 ] = value.z; - - offset += 3; - - } - - } - - } else if ( customAttribute.size === 4 ) { - - for ( ca = 0; ca < cal; ca ++ ) { - - value = customAttribute.value[ ca ]; - - customAttribute.array[ offset ] = value.x; - customAttribute.array[ offset + 1 ] = value.y; - customAttribute.array[ offset + 2 ] = value.z; - customAttribute.array[ offset + 3 ] = value.w; - - offset += 4; - - } - - } - - } - - } - - } - - } - - if ( dirtyVertices || object.sortParticles ) { - - _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglVertexBuffer ); - _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint ); - - } - - if ( dirtyColors || object.sortParticles ) { - - _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglColorBuffer ); - _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint ); - - } - - if ( customAttributes ) { - - for ( i = 0, il = customAttributes.length; i < il; i ++ ) { - - customAttribute = customAttributes[ i ]; - - if ( customAttribute.needsUpdate || object.sortParticles ) { - - _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer ); - _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint ); + _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer ); + _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint ); - } + customAttribute.needsUpdate = false; } @@ -1582,9 +1418,7 @@ THREE.WebGLRenderer = function ( parameters ) { customAttribute = customAttributes[ i ]; - if ( customAttribute.needsUpdate && - ( customAttribute.boundTo === undefined || - customAttribute.boundTo === 'vertices' ) ) { + if ( customAttribute.needsUpdate && ( customAttribute.boundTo === undefined || customAttribute.boundTo === 'vertices' ) ) { offset = 0; @@ -1663,6 +1497,8 @@ THREE.WebGLRenderer = function ( parameters ) { _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer ); _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint ); + customAttribute.needsUpdate = false; + } } @@ -4137,7 +3973,7 @@ THREE.WebGLRenderer = function ( parameters ) { customAttributesDirty = material.attributes && areCustomAttributesDirty( material ); - if ( geometry.verticesNeedUpdate || geometry.colorsNeedUpdate || object.sortParticles || customAttributesDirty ) { + if ( geometry.verticesNeedUpdate || geometry.colorsNeedUpdate || customAttributesDirty ) { setParticleBuffers( geometry, _gl.DYNAMIC_DRAW, object );