diff --git a/packages/mesh/src/Mesh.js b/packages/mesh/src/Mesh.js index 9c0ce09..b39f77d 100644 --- a/packages/mesh/src/Mesh.js +++ b/packages/mesh/src/Mesh.js @@ -1,7 +1,7 @@ import RawMesh from './RawMesh'; import { Geometry, Program, Shader } from '@pixi/core'; import { BLEND_MODES } from '@pixi/constants'; -import { hex2rgb } from '@pixi/utils'; +import { hex2rgb, premultiplyRgba } from '@pixi/utils'; import vertex from './webgl/mesh.vert'; import fragment from './webgl/mesh.frag'; @@ -38,9 +38,9 @@ geometry.getAttribute('aVertexPosition').static = false; const uniforms = { - uSampler2: texture, + uSampler: texture, alpha: 1, - tint: new Float32Array([1, 1, 1]), + uColor: new Float32Array([1, 1, 1, 1]), }; super(geometry, new Shader(meshProgram, uniforms), null, drawMode); @@ -51,6 +51,7 @@ this.uniforms = uniforms; this.texture = texture; + this._tintRGB = new Float32Array([1, 1, 1]); this._tint = 0xFFFFFF; this.tint = 0xFFFFFF; @@ -78,7 +79,8 @@ set tint(value) { this._tint = value; - hex2rgb(this._tint, this.uniforms.tint); + + hex2rgb(this._tint, this._tintRGB); } /** @@ -116,7 +118,7 @@ } this._texture = value; - this.uniforms.uSampler2 = this.texture; + this.uniforms.uSampler = this.texture; if (value) { @@ -132,6 +134,13 @@ } } + _renderWebGL(renderer) + { + const baseTex = this._texture.baseTexture; + + premultiplyRgba(this._tintRGB, this.worldAlpha, this.uniforms.uColor, baseTex.premultiplyAlpha); + super._renderWebGL(renderer); + } /** * When the texture is updated, this event will fire to update the scale and frame * diff --git a/packages/mesh/src/Mesh.js b/packages/mesh/src/Mesh.js index 9c0ce09..b39f77d 100644 --- a/packages/mesh/src/Mesh.js +++ b/packages/mesh/src/Mesh.js @@ -1,7 +1,7 @@ import RawMesh from './RawMesh'; import { Geometry, Program, Shader } from '@pixi/core'; import { BLEND_MODES } from '@pixi/constants'; -import { hex2rgb } from '@pixi/utils'; +import { hex2rgb, premultiplyRgba } from '@pixi/utils'; import vertex from './webgl/mesh.vert'; import fragment from './webgl/mesh.frag'; @@ -38,9 +38,9 @@ geometry.getAttribute('aVertexPosition').static = false; const uniforms = { - uSampler2: texture, + uSampler: texture, alpha: 1, - tint: new Float32Array([1, 1, 1]), + uColor: new Float32Array([1, 1, 1, 1]), }; super(geometry, new Shader(meshProgram, uniforms), null, drawMode); @@ -51,6 +51,7 @@ this.uniforms = uniforms; this.texture = texture; + this._tintRGB = new Float32Array([1, 1, 1]); this._tint = 0xFFFFFF; this.tint = 0xFFFFFF; @@ -78,7 +79,8 @@ set tint(value) { this._tint = value; - hex2rgb(this._tint, this.uniforms.tint); + + hex2rgb(this._tint, this._tintRGB); } /** @@ -116,7 +118,7 @@ } this._texture = value; - this.uniforms.uSampler2 = this.texture; + this.uniforms.uSampler = this.texture; if (value) { @@ -132,6 +134,13 @@ } } + _renderWebGL(renderer) + { + const baseTex = this._texture.baseTexture; + + premultiplyRgba(this._tintRGB, this.worldAlpha, this.uniforms.uColor, baseTex.premultiplyAlpha); + super._renderWebGL(renderer); + } /** * When the texture is updated, this event will fire to update the scale and frame * diff --git a/packages/mesh/src/webgl/mesh.frag b/packages/mesh/src/webgl/mesh.frag index e6df86f..6096983 100644 --- a/packages/mesh/src/webgl/mesh.frag +++ b/packages/mesh/src/webgl/mesh.frag @@ -1,7 +1,7 @@ varying vec2 vTextureCoord; uniform vec4 uColor; -uniform sampler2D uSampler2; +uniform sampler2D uSampler; void main(void) {