[ts][pixi] Fix parent alpha not working for dark tint. Aligned DarkTintMaterial shader with the Batcher one.

This commit is contained in:
Davide Tantillo 2024-06-17 17:40:47 +02:00
parent da8131e0e1
commit 64fe74e91c
3 changed files with 8 additions and 13 deletions

View File

@ -191,11 +191,9 @@ export class DarkTintMaterial extends Shader {
public update(): void { public update(): void {
if (this._colorDirty) { if (this._colorDirty) {
this._colorDirty = false; this._colorDirty = false;
const baseTexture = this.texture.baseTexture; const missingAlphaInPMAColor = this._alpha / this._tintColor.alpha;
const applyToChannels = baseTexture.alphaMode as unknown as boolean; Color.shared.setValue(this._tintColor).premultiply(missingAlphaInPMAColor, true).premultiply(this._alpha, false).toArray(this.uniforms.uColor);
Color.shared.setValue(this._darkTintColor).premultiply(missingAlphaInPMAColor, true).premultiply(1, false).toArray(this.uniforms.uDarkColor);
Color.shared.setValue(this._tintColor).premultiply(this._alpha, applyToChannels).toArray(this.uniforms.uColor);
Color.shared.setValue(this._darkTintColor).premultiply(this._alpha, applyToChannels).toArray(this.uniforms.uDarkColor);
} }
if (this.uvMatrix.update()) { if (this.uvMatrix.update()) {
this.uniforms.uTextureMatrix = this.uvMatrix.mapCoord; this.uniforms.uTextureMatrix = this.uvMatrix.mapCoord;

View File

@ -43,6 +43,7 @@ export interface IDarkTintElement {
_tintRGB: number; _tintRGB: number;
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
_darkTintRGB: number; _darkTintRGB: number;
alpha: number;
blendMode: BLEND_MODES; blendMode: BLEND_MODES;
} }

View File

@ -98,14 +98,10 @@ export class DarkTintRenderer extends BatchRenderer {
const indicies = element.indices; const indicies = element.indices;
const vertexData = element.vertexData; const vertexData = element.vertexData;
const textureId = element._texture.baseTexture._batchLocation; const textureId = element._texture.baseTexture._batchLocation;
const alpha = Math.min(element.worldAlpha, 1.0); const worldAlpha = Math.min(element.worldAlpha, 1.0);
const missingAlphaInPMAColor = worldAlpha / element.alpha;
const alphaInt = Math.round(alpha * 255) & 0xFF; const argb = Color.shared.setValue(element._tintRGB).premultiply(missingAlphaInPMAColor, true).toPremultiplied(worldAlpha, false);
const tintRGB = element._tintRGB & 0xFFFFFF; const darkargb = Color.shared.setValue(element._darkTintRGB).premultiply(missingAlphaInPMAColor, true).toPremultiplied(1, false);
const argb = (alphaInt << 24) | tintRGB;
const darkTintRGB = element._darkTintRGB & 0xFFFFFF;
const darkargb = (0xFF << 24) | darkTintRGB;
// lets not worry about tint! for now.. // lets not worry about tint! for now..
for (let i = 0; i < vertexData.length; i += 2) { for (let i = 0; i < vertexData.length; i += 2) {