diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 0e95c05..3cd5263 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -95,6 +95,15 @@ */ this.shader = null; + + /** + * The tint applied to the mesh. This is a [r,g,b] value. A value of [1,1,1] will remove any tint effect. + * + * @member {number} + * @memberof PIXI.mesh.Mesh# + */ + this.tintRgb = new Float32Array([1, 1, 1]); + this._glDatas = []; } @@ -137,6 +146,21 @@ } } } + }, + /** + * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. + * + * @member {number} + * @memberof PIXI.mesh.Mesh# + * @default 0xFFFFFF + */ + tint: { + get: function() { + return core.utils.rgb2hex(this.tintRgb); + }, + set: function(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } } }); @@ -198,10 +222,10 @@ glData.shader.uniforms.translationMatrix = this.worldTransform.toArray(true); glData.shader.uniforms.alpha = this.worldAlpha; + glData.shader.uniforms.tint = this.tintRgb; var drawMode = this.drawMode === Mesh.DRAW_MODES.TRIANGLE_MESH ? gl.TRIANGLE_STRIP : gl.TRIANGLES; - glData.vao.bind() .draw(drawMode, this.indices.length) .unbind(); diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 0e95c05..3cd5263 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -95,6 +95,15 @@ */ this.shader = null; + + /** + * The tint applied to the mesh. This is a [r,g,b] value. A value of [1,1,1] will remove any tint effect. + * + * @member {number} + * @memberof PIXI.mesh.Mesh# + */ + this.tintRgb = new Float32Array([1, 1, 1]); + this._glDatas = []; } @@ -137,6 +146,21 @@ } } } + }, + /** + * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. + * + * @member {number} + * @memberof PIXI.mesh.Mesh# + * @default 0xFFFFFF + */ + tint: { + get: function() { + return core.utils.rgb2hex(this.tintRgb); + }, + set: function(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } } }); @@ -198,10 +222,10 @@ glData.shader.uniforms.translationMatrix = this.worldTransform.toArray(true); glData.shader.uniforms.alpha = this.worldAlpha; + glData.shader.uniforms.tint = this.tintRgb; var drawMode = this.drawMode === Mesh.DRAW_MODES.TRIANGLE_MESH ? gl.TRIANGLE_STRIP : gl.TRIANGLES; - glData.vao.bind() .draw(drawMode, this.indices.length) .unbind(); diff --git a/src/mesh/webgl/MeshShader.js b/src/mesh/webgl/MeshShader.js index 3ea61c3..0acda45 100644 --- a/src/mesh/webgl/MeshShader.js +++ b/src/mesh/webgl/MeshShader.js @@ -28,11 +28,12 @@ [ 'varying vec2 vTextureCoord;', 'uniform float alpha;', + 'uniform vec3 tint;', 'uniform sampler2D uSampler;', 'void main(void){', - ' gl_FragColor = texture2D(uSampler, vTextureCoord) * alpha ;', + ' gl_FragColor = texture2D(uSampler, vTextureCoord) * vec4(tint * alpha, alpha);', // ' gl_FragColor = vec4(1.0);', '}' ].join('\n')