Skip to content

Commit

Permalink
Fix: graphics tint using mix instead of multiply (#10481)
Browse files Browse the repository at this point in the history
* fixes bug where graphics blend mode was not being set correctly for large graphics

* fix tint graphics tint

* Update tests/visual/scenes/graphics/graphics-blend.scene.ts

* remove function

* Update tests/visual/scenes/graphics/graphics-tint.scene.ts

* fix test

---------

Co-authored-by: Matt Karl <matt@mattkarl.com>
Co-authored-by: Zyie <24736175+Zyie@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 30, 2024
1 parent 1b6a8ef commit ced0b62
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/scene/container/utils/mixColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ export function mixStandardAnd32BitColors(localColorRGB: number, localAlpha: num

return sharedBGRColor + (globalAlpha << 24);
}

4 changes: 2 additions & 2 deletions src/scene/graphics/shared/BatchableGraphics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mixColors } from '../../container/utils/mixColors';
import { multiplyHexColors } from '../../container/utils/multiplyHexColors';

import type { Batch, BatchableObject, Batcher } from '../../../rendering/batcher/shared/Batcher';
import type { IndexBufferArray } from '../../../rendering/renderers/shared/geometry/Geometry';
Expand Down Expand Up @@ -70,7 +70,7 @@ export class BatchableGraphics implements BatchableObject

if (this.applyTransform)
{
const argb = mixColors(bgr, graphics.groupColor)
const argb = multiplyHexColors(bgr, graphics.groupColor)
+ ((this.alpha * graphics.groupAlpha * 255) << 24);

const wt = graphics.groupTransform;
Expand Down
17 changes: 17 additions & 0 deletions tests/visual/scenes/graphics/graphics-tint.scene.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Graphics } from '../../../../src/scene/graphics/shared/Graphics';

import type { Container } from '../../../../src/scene/container/Container';
import type { TestScene } from '../../types';

export const scene: TestScene = {
it: 'should set tint of graphics correctly',
create: async (scene: Container) =>
{
const rect = new Graphics().rect(0, 0, 100, 100).fill('black');

// should remain black!
rect.tint = 0xff0000;

scene.addChild(rect);
},
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/visual/snapshots/shared-context-scene-ts-webgl1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/visual/snapshots/shared-context-scene-ts-webgl2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/visual/snapshots/shared-context-scene-ts-webgpu.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ced0b62

Please sign in to comment.