diff --git a/README.md b/README.md index 0ac4b98..c05750c 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,11 @@ var particleEmitter = new ShaderParticleEmitter({ // [OPTIONAL] Particle end size. sizeEnd: 10, + // [OPTIONAL] Particle start rotation. + particleRotation: 0 + + // [OPTIONAL] Particle rotation variance ( in radians ). + particleRotationSpread: 0 // [OPTIONAL] Particle start colour. colorStart: new THREE.Color( 'white' ), @@ -253,4 +258,4 @@ See the [issues page](https://github.com/squarefeet/ShaderParticleEngine/issues) Thanks ====== -Huge thanks are extended to [Stemkoski](http://stemkoski.github.io/Three.js/) for his initial particle engine, and to [Mr Doob, AlteredQualia, et. al](https://github.com/mrdoob/three.js/graphs/contributors) for their awesome work on [THREE.js](http://threejs.org/). \ No newline at end of file +Huge thanks are extended to [Stemkoski](http://stemkoski.github.io/Three.js/) for his initial particle engine, and to [Mr Doob, AlteredQualia, et. al](https://github.com/mrdoob/three.js/graphs/contributors) for their awesome work on [THREE.js](http://threejs.org/). diff --git a/build/ShaderParticles.js b/build/ShaderParticles.js index 03b7b49..88ad398 100644 --- a/build/ShaderParticles.js +++ b/build/ShaderParticles.js @@ -316,6 +316,7 @@ ShaderParticleGroup.prototype = { opacity[i] = emitter.opacityStart; opacityMiddle[i] = emitter.opacityMiddle; opacityEnd[i] = emitter.opacityEnd; + rotation[i] = that._randomFloat( emitter.particleRotation, emitter.particleRotationSpread ); } // Cache properties on the emitter so we can access @@ -505,6 +506,7 @@ ShaderParticleGroup.shaders = { 'attribute vec3 customColor;', 'attribute vec3 customColorEnd;', + 'attribute float rotation;', 'attribute float opacity;', 'attribute float opacityMiddle;', 'attribute float opacityEnd;', @@ -517,6 +519,7 @@ ShaderParticleGroup.shaders = { 'attribute float sizeEnd;', 'varying vec4 vColor;', + 'varying float vRotation;', // Linearly lerp a float 'float Lerp( float start, float end, float amount ) {', @@ -552,6 +555,8 @@ ShaderParticleGroup.shaders = { 'void main() {', + 'vRotation = rotation;', + 'float positionInTime = (age / duration);', 'float halfDuration = (duration / 2.0);', @@ -610,10 +615,11 @@ ShaderParticleGroup.shaders = { 'uniform int colorize;', 'varying vec4 vColor;', + 'varying float vRotation;', 'void main() {', - 'float c = cos(0.0);', - 'float s = sin(0.0);', + 'float c = cos( vRotation );', + 'float s = sin( vRotation );', 'vec2 rotatedUV = vec2(c * (gl_PointCoord.x - 0.5) + s * (gl_PointCoord.y - 0.5) + 0.5,', 'c * (gl_PointCoord.y - 0.5) - s * (gl_PointCoord.x - 0.5) + 0.5);', diff --git a/src/ShaderParticleEmitter.js b/src/ShaderParticleEmitter.js index 74fab71..57f8fc1 100644 --- a/src/ShaderParticleEmitter.js +++ b/src/ShaderParticleEmitter.js @@ -42,6 +42,9 @@ function ShaderParticleEmitter( options ) { that.colorEnd = options.colorEnd instanceof THREE.Color ? options.colorEnd : new THREE.Color( 'blue' ); that.colorSpread = options.colorSpread instanceof THREE.Vector3 ? options.colorSpread : new THREE.Vector3(); + that.particleRotation = parseFloat( typeof options.particleRotation === 'number' ? options.particleRotation : 0, 10 ); + that.particleRotationSpread = parseFloat( typeof options.particleRotationSpread === 'number' ? options.particleRotationSpread : 0, 10 ); + that.opacityStart = parseFloat( typeof options.opacityStart !== 'undefined' ? options.opacityStart : 1, 10 ); that.opacityEnd = parseFloat( typeof options.opacityEnd === 'number' ? options.opacityEnd : 0, 10 ); that.opacityMiddle = parseFloat(