Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: graphics tint using mix instead of multiply #10481

Merged
merged 6 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}

2 changes: 2 additions & 0 deletions src/scene/graphics/gl/GlGraphicsAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export class GlGraphicsAdaptor implements GraphicsAdaptor
// WebGL specific..
shader.groups[0] = renderer.globalUniforms.bindGroup;

renderer.state.set(graphicsPipe.state);

renderer.shader.bind(shader);

renderer.geometry.bind(geometry, shader.glProgram);
Expand Down
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
18 changes: 18 additions & 0 deletions tests/visual/scenes/graphics/graphics-blend.scene.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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 blend of graphics correctly',
create: async (scene: Container) =>
{
const rect = new Graphics().rect(0, 0, 100, 100).fill('red');

rect.context.batchMode = 'no-batch';

rect.blendMode = 'erase';

scene.addChild(rect);
},
};
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.
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.