diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 63f7791..6d98098 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -1,4 +1,5 @@ import * as core from '../core'; +import { hex2rgb } from '../core/utils'; /** * The ParticleContainer class is a really fast version of the Container built solely for speed, @@ -121,6 +122,18 @@ this.baseTexture = null; this.setProperties(properties); + + /** + * The tint applied to the container. + * This is a hex value. A value of 0xFFFFFF will remove any tint effect. + * + * @private + * @member {number} + * @default 0xFFFFFF + */ + this._tint = null; + this._tintRGB = []; + this.tint = 0xFFFFFF; } /** @@ -153,6 +166,24 @@ } /** + * The tint applied to the container. This is a hex value. + * A value of 0xFFFFFF will remove any tint effect. + ** IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. + * @member {number} + * @default 0xFFFFFF + */ + get tint() + { + return this._tint; + } + + set tint(value) // eslint-disable-line require-jsdoc + { + this._tint = value; + hex2rgb(value, this._tintRGB); + } + + /** * Renders the container using the WebGL renderer * * @private diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 63f7791..6d98098 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -1,4 +1,5 @@ import * as core from '../core'; +import { hex2rgb } from '../core/utils'; /** * The ParticleContainer class is a really fast version of the Container built solely for speed, @@ -121,6 +122,18 @@ this.baseTexture = null; this.setProperties(properties); + + /** + * The tint applied to the container. + * This is a hex value. A value of 0xFFFFFF will remove any tint effect. + * + * @private + * @member {number} + * @default 0xFFFFFF + */ + this._tint = null; + this._tintRGB = []; + this.tint = 0xFFFFFF; } /** @@ -153,6 +166,24 @@ } /** + * The tint applied to the container. This is a hex value. + * A value of 0xFFFFFF will remove any tint effect. + ** IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. + * @member {number} + * @default 0xFFFFFF + */ + get tint() + { + return this._tint; + } + + set tint(value) // eslint-disable-line require-jsdoc + { + this._tint = value; + hex2rgb(value, this._tintRGB); + } + + /** * Renders the container using the WebGL renderer * * @private diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index 1b4323b..16e0c9c 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -153,6 +153,7 @@ this.shader.uniforms.projectionMatrix = m.toArray(true); this.shader.uniforms.uAlpha = container.worldAlpha; + this.shader.uniforms.tint = container._tintRGB; // make sure the texture is bound.. const baseTexture = children[0]._texture.baseTexture; diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 63f7791..6d98098 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -1,4 +1,5 @@ import * as core from '../core'; +import { hex2rgb } from '../core/utils'; /** * The ParticleContainer class is a really fast version of the Container built solely for speed, @@ -121,6 +122,18 @@ this.baseTexture = null; this.setProperties(properties); + + /** + * The tint applied to the container. + * This is a hex value. A value of 0xFFFFFF will remove any tint effect. + * + * @private + * @member {number} + * @default 0xFFFFFF + */ + this._tint = null; + this._tintRGB = []; + this.tint = 0xFFFFFF; } /** @@ -153,6 +166,24 @@ } /** + * The tint applied to the container. This is a hex value. + * A value of 0xFFFFFF will remove any tint effect. + ** IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. + * @member {number} + * @default 0xFFFFFF + */ + get tint() + { + return this._tint; + } + + set tint(value) // eslint-disable-line require-jsdoc + { + this._tint = value; + hex2rgb(value, this._tintRGB); + } + + /** * Renders the container using the WebGL renderer * * @private diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index 1b4323b..16e0c9c 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -153,6 +153,7 @@ this.shader.uniforms.projectionMatrix = m.toArray(true); this.shader.uniforms.uAlpha = container.worldAlpha; + this.shader.uniforms.tint = container._tintRGB; // make sure the texture is bound.. const baseTexture = children[0]._texture.baseTexture; diff --git a/src/particles/webgl/ParticleShader.js b/src/particles/webgl/ParticleShader.js index 8c8b056..ebd80d9 100644 --- a/src/particles/webgl/ParticleShader.js +++ b/src/particles/webgl/ParticleShader.js @@ -49,9 +49,10 @@ 'uniform sampler2D uSampler;', 'uniform float uAlpha;', + 'uniform vec3 tint;', 'void main(void){', - ' vec4 color = texture2D(uSampler, vTextureCoord) * vColor * uAlpha;', + ' vec4 color = texture2D(uSampler, vTextureCoord) * vColor * vec4(tint * uAlpha, uAlpha);', ' if (color.a == 0.0) discard;', ' gl_FragColor = color;', '}',