Skip to content

Commit 3738e3b

Browse files
authored
Merge pull request #7769 from processing/fix/webgl-alpha
Fix WebGL alpha blending
2 parents eac15d9 + 678d8e8 commit 3738e3b

File tree

7 files changed

+6
-6
lines changed
  • src/webgl/shaders
  • test/unit/visual
    • cases
    • screenshots/WebGL/Opacity
      • Basic colors have opacity applied correctly
      • Colors have opacity applied correctly when lights are used
      • Colors in shader hooks have opacity applied correctly
      • Colors in textures have opacity applied correctly
      • Colors in tinted textures have opacity applied correctly

7 files changed

+6
-6
lines changed

src/webgl/shaders/phong.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void main(void) {
4747
inputs.texCoord = vTexCoord;
4848
inputs.ambientLight = vAmbientColor;
4949
inputs.color = isTexture
50-
? TEXTURE(uSampler, vTexCoord) * uTint/255.
50+
? TEXTURE(uSampler, vTexCoord) * (vec4(uTint.rgb/255., 1.) * uTint.a/255.)
5151
: vColor;
5252
if (isTexture && inputs.color.a > 0.0) {
5353
// Textures come in with premultiplied alpha. Temporarily unpremultiply it

test/unit/visual/cases/webgl.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ visualSuite('WebGL', function() {
375375
visualTest('Basic colors have opacity applied correctly', (p5, screenshot) => {
376376
p5.createCanvas(50, 50, p5.WEBGL);
377377
p5.background(255);
378-
p5.fill(255, 0, 0, 100);
378+
p5.fill(255, 100, 100, 100);
379379
p5.circle(0, 0, 50);
380380
screenshot();
381381
});
@@ -384,7 +384,7 @@ visualSuite('WebGL', function() {
384384
p5.createCanvas(50, 50, p5.WEBGL);
385385
p5.background(255);
386386
p5.ambientLight(255);
387-
p5.fill(255, 0, 0, 100);
387+
p5.fill(255, 100, 100, 100);
388388
p5.circle(0, 0, 50);
389389
screenshot();
390390
});
@@ -393,7 +393,7 @@ visualSuite('WebGL', function() {
393393
p5.createCanvas(50, 50, p5.WEBGL);
394394
const myShader = p5.baseMaterialShader().modify({
395395
'Inputs getPixelInputs': `(Inputs inputs) {
396-
inputs.color = vec4(1., 0., 0., 100./255.);
396+
inputs.color = vec4(1., 0.4, 0.4, 100./255.);
397397
return inputs;
398398
}`
399399
})
@@ -406,7 +406,7 @@ visualSuite('WebGL', function() {
406406
visualTest('Colors in textures have opacity applied correctly', (p5, screenshot) => {
407407
p5.createCanvas(50, 50, p5.WEBGL);
408408
const tex = p5.createFramebuffer();
409-
tex.draw(() => p5.background(255, 0, 0, 100));
409+
tex.draw(() => p5.background(255, 100, 100, 100));
410410
p5.background(255);
411411
p5.texture(tex);
412412
p5.circle(0, 0, 50);
@@ -416,7 +416,7 @@ visualSuite('WebGL', function() {
416416
visualTest('Colors in tinted textures have opacity applied correctly', (p5, screenshot) => {
417417
p5.createCanvas(50, 50, p5.WEBGL);
418418
const tex = p5.createFramebuffer();
419-
tex.draw(() => p5.background(255, 0, 0, 255));
419+
tex.draw(() => p5.background(255, 100, 100, 255));
420420
p5.background(255);
421421
p5.texture(tex);
422422
p5.tint(255, 100);
-92 Bytes
Loading
-92 Bytes
Loading
-104 Bytes
Loading
-92 Bytes
Loading
-92 Bytes
Loading

0 commit comments

Comments
 (0)