Jump to content

Graphics rectangle filter shader conversion from v7 to v8 not working


Deoxyz
 Share

Recommended Posts

I recently upgrade my shader code from pixi v7 to pixi v8 and after some issues with shader not compiling I manged to get it where there are no errors thrown. But I don't see it working either. My code should create a black screen with alpha 0.8 and somewhere on that rect I should see a cut out circle with faded edges:
447042738-cc2ecf7c-0ead-4c47-b598-30899c64a64a.thumb.png.73dbc9019d17dc4f1993e12307882cc5.png

But instead I don't get anything, not even an error. But I see my uniforms filled in correctly (I think):

447043059-00854168-7d77-4584-a10b-26cee798a644.thumb.png.73289f907487b69277f585d6bf431f8c.png

447043178-d654f220-9f0e-4479-a5d6-c841200e308e.thumb.png.0436f6dd95ed6ca4961eb1c81683abc2.png

 

v7 code:
tutorialShaderFrag.txt

shaders.ts.txt

In my view I do following (uses pixi default vertex shader):

private filterShader: TutorialFilter = new TutorialFilter();

//... Apply
this.backgroundGraphic = new Pixi.Graphics();
this.backgroundGraphic.pivot.set(0.5, 0.5);
this.backgroundGraphic.beginFill(0xffffff);
this.backgroundGraphic.drawRect(-2000, -2000, 5000, 5000);
this.backgroundGraphic.endFill();
this.backgroundGraphic.filters = [this.filterShader];

// ... Update
this.filterShader.uniforms.uResolution = [appResolution.w, appResolution.h];
const rNormalized = transform.r / actualGameResolution.w;
this.filterShader.uniforms.uCirclePosition = [xNormalized, yNormalized];
this.filterShader.uniforms.uCircleRadius = rNormalized;
this.filterShader.uniforms.uSquashFactorY = transform.sy;

 

v8 code:

shaders.mts.txt

private filterShader: TutorialFilter = new TutorialFilter();

//... Apply
this.backgroundGraphic = new Pixi.Graphics();
this.backgroundGraphic.rect(-2000, -2000, 5000, 5000);
this.backgroundGraphic.fill({ color: 0xffffff });
this.backgroundGraphic.filters = [this.filterShader];

// ... Update
this.filterShader?.update({
    resolution: new Float32Array([appResolution.w, appResolution.h]),
    circlePosition: new Float32Array([xNormalized, yNormalized]),
    circleRadius: rNormalized,
    squashFactorY: transform.sy ?? 1.0,
    alpha: 0.8,
});


We also upgraded the project to ESM, but I don't think that is the issue. WebGL only, no WebGPU (yet).
The pixi version we use at the moment is v8.7.2.

I don't have a clue what I might have missed.

Thanks in advance!

Link to comment
Share on other sites

It seems that I got a bit further now. There were 2 issues. 
1st was that webpack imported my .frag & .vert shader as an url instead of the content of the file as string. 2nd was that my vertex shader had to be updated in order to make it work. Now I see a black rectangle, but not in the correct place yet.

801218699_Screenshot2025-05-28091746.png.bd82f02f65c26588329321c72edff4b2.png

Hopfully I have the full fix soon. 😄 

Link to comment
Share on other sites

I got it working by tweaking my vertex shader that the created rect was bottom left of the screen as following:

precision mediump float;
attribute vec2 aPosition;

void main() {
    // Map aPosition from [0, 1] range to clip space [-1, 1]
    vec2 clipSpace = aPosition * 2.0 - 1.0;
    // Invert Y for screen space (WebGL's Y is flipped)
    clipSpace.y = -clipSpace.y;
    gl_Position = vec4(clipSpace, 0.0, 1.0);
}

image.png.95cc2276e0417a69d60dd6cea15aad44.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...