Skip to content

Commit

Permalink
Added overlay blend mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mflerackers committed Feb 1, 2025
1 parent a18a138 commit 3c6f0f8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions examples/blend.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ onDraw(() => {
pos: vec2(250, 200),
blend: BlendMode.Screen,
});
drawSprite({
sprite: "bean",
pos: vec2(300, 200),
blend: BlendMode.Overlay,
});

drawCircle({
radius: 25,
Expand All @@ -55,6 +60,12 @@ onDraw(() => {
color: rgb(128, 128, 128),
blend: BlendMode.Screen,
});
drawCircle({
radius: 25,
pos: vec2(325, 300),
color: rgb(128, 128, 128),
blend: BlendMode.Overlay,
});
});

add([
Expand All @@ -77,3 +88,8 @@ add([
pos(250, 400),
blend(BlendMode.Screen),
]);
add([
sprite("bean"),
pos(300, 400),
blend(BlendMode.Overlay),
]);
11 changes: 9 additions & 2 deletions src/gfx/gfx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class BatchRenderer {
&& !deepEq(this.curUniform, uniform))
|| blend !== this.curBlend
|| this.vqueue.length + verts.length * this.stride
> this.maxVertices
> this.maxVertices
|| this.iqueue.length + indices.length > this.maxIndices
) {
this.flush(width, height);
Expand Down Expand Up @@ -217,12 +217,19 @@ export class BatchRenderer {
break;
case BlendMode.Screen:
gl.blendFuncSeparate(
gl.ONE_MINUS_DST_COLOR,
gl.ONE,
gl.ONE_MINUS_SRC_COLOR,
gl.ONE,
gl.ONE_MINUS_SRC_ALPHA,
);
break;
case BlendMode.Overlay:
gl.blendFuncSeparate(
gl.DST_COLOR,
gl.ONE_MINUS_SRC_ALPHA,
gl.ONE,
gl.ONE_MINUS_SRC_ALPHA
);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6575,6 +6575,7 @@ export enum BlendMode {
Add = 1,
Multiply = 2,
Screen = 3,
Overlay = 4,
}

export interface Attributes {
Expand Down

0 comments on commit 3c6f0f8

Please sign in to comment.