Skip to content

Commit

Permalink
fix(graphics): set alpha on context to false to improve blending
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaisthorpe committed Sep 16, 2024
1 parent 8689535 commit 227102f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-sheep-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tedengine/ted': patch
---

Set alpha to false on webgl2 context to improve blending
57 changes: 56 additions & 1 deletion apps/docs/src/examples/2d/animated-sprite-component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asteroidTexture from '@assets/person.png';
import { vec3 } from 'gl-matrix';
import { vec3, vec4 } from 'gl-matrix';
import type { TResourcePackConfig } from '@tedengine/ted';
import {
TGameState,
Expand Down Expand Up @@ -41,6 +41,61 @@ class Sprite extends TActor {
},
);
sprite.applyTexture(engine, asteroidTexture);
sprite.colorFilter = vec4.fromValues(0, 0, 0, 0.5);

const filterSection = engine.debugPanel.addSection('Color Filter', true);
filterSection.addInput(
'Red',
'range',
'1',
(value) => {
sprite.colorFilter[0] = parseFloat(value);
},
{
min: 0,
max: 1,
step: 0.01,
},
);
filterSection.addInput(
'Green',
'range',
'1',
(value) => {
sprite.colorFilter[1] = parseFloat(value);
},
{
min: 0,
max: 1,
step: 0.01,
},
);
filterSection.addInput(
'Blue',
'range',
'1',
(value) => {
sprite.colorFilter[2] = parseFloat(value);
},
{
min: 0,
max: 1,
step: 0.01,
},
);
filterSection.addInput(
'Alpha',
'range',
'1',
(value) => {
sprite.colorFilter[3] = parseFloat(value);
},
{
min: 0,
max: 1,
step: 0.01,
},
);

this.rootComponent.transform.translation = vec3.fromValues(0, 0, -3);

Expand Down
4 changes: 3 additions & 1 deletion packages/ted/src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ export default class TRenderer {
}

public context(): WebGL2RenderingContext {
return this.canvas.getContext('webgl2')!;
return this.canvas.getContext('webgl2', {
alpha: false,
})!;
}

public render(frameParams: TFrameParams) {
Expand Down

0 comments on commit 227102f

Please sign in to comment.