Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Custom fragment shader filter vTextureCoord does not behave as expected #438

Open
CaptainStiggz opened this issue May 27, 2023 · 0 comments

Comments

@CaptainStiggz
Copy link

CaptainStiggz commented May 27, 2023

Current Behavior

I'm using pixi with @pixi/react. I'm trying to create a simple fragment shader filter that's applied to a Graphics object. It works as expected, until I place the Graphics object inside a Container with a scale. At that point, adjusting the scale of the Container seems to shift the vTextureCoord in my glsl code. The strangest part is, at various scale levels, the filter appears to reset, and the filter behaves as expected once again.

Screenshot 2023-05-26 at 5 01 05 PM Screenshot 2023-05-26 at 5 01 23 PM

Expected Behavior

I would expect the vTextureCoord range to correctly map from 0 - 1 on my Graphics object's bounds, regardless of the parent container's scale.

Steps to Reproduce

Here's a CodeSandbox link to the problem. https://codesandbox.io/s/pensive-cache-8zkitk?file=/src/App.tsx

The code is as follows.

const fragmentShader = `

varying vec2 vTextureCoord;

void main() {
  
  vec2 uv = vTextureCoord;
  gl_FragColor = vec4(uv.x, 0, uv.y, 1.);
}
`;

export function useTestShader() {
  return useMemo(() => {
    const f = new PIXI.Filter(undefined, fragmentShader);
    f.autoFit = false;
    return [f];
  }, []);
}

export default function App() {
  const [zoom, setZoom] = useState(1);

  const draw = useCallback((g: PIXI.Graphics) => {
    g.clear();
    g.beginFill("red");
    g.drawRect(0, 0, 256, 256);
    g.endFill();
  }, []);

  const filter = useTestShader();

  return (
    <>
      <Stage width={window.innerWidth} height={window.innerHeight}>
        <Container scale={zoom}>
          <Graphics draw={draw} width={256} height={256} filters={filter} />
        </Container>
      </Stage>
      <div className="buttons">
        <button onClick={() => setZoom((z) => z + 0.1)}>+</button>
        <button onClick={() => setZoom((z) => z - 0.1)}>-</button>
      </div>
    </>
  );
}

Environment

Possible Solution

No response

Additional Information

I also posted this issue on the main pixi.js repo here: pixijs/pixijs#9447

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant