LoginSignup
5
3

More than 5 years have passed since last update.

PIXI.jsでフラグメントシェーダ内でアルファ値を変更できない

Posted at

PIXI.jsで写真を部分的に透過させるという処理をしたかったのですが、つまずいたのでメモ。

下記のようにただ単純に表示されたもののアルファ値を変更しようとしたのですがうまくいきませんでした。

fragment.glsl
precision mediump float;

varying vec2 vTextureCoord;
uniform sampler2D uSampler;

void main(){
   vec4 color = texture2D(uSampler, vTextureCoord);
   color.w = 0.1;

   gl_FragColor = vec4(color);
}

原因はレンダラーの設定でした。

gl_FragColorの透過を反映させる場合には、レンダラーのオプションでtranparentを指定する必要があるようです。

app.js
this.renderer = new PIXI.autoDetectRenderer(this.width, this.height);

⬇︎

this.renderer = PIXI.autoDetectRenderer(this.width, this.height, {transparent: true});

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3