Search the Community
Showing results for tags 'shader fragment'.
-
Tried the official "hello shader" example with pixi6 but it no longer seems to animate: https://pixijs.io/examples/#/filters-advanced/custom.js I inject PixiJs into a React app. (I don't think this is the issue, since it works fine for everything else I've been doing the past few months.) In this code snippet, useEffect just ensures that the code runs outside the render loop. And the useLayoutEffect block ensures the "uniforms" object and animate callback don't trigger re-renders. The shader will load fine. The app.ticker will run the animation function. But the shader does not animate. ?♂️ export function usePixiShader(props: { comp?: Container; uniforms?: Record<string, unknown>; animate?: (filter: Filter, delta: number) => void; }) { const { comp: parent, uniforms, animate } = props; // just gives you the instance of the app const app = useContext(PixiAppContext); const comp = parent ?? app?.stage; const uniformsRef = useRef(uniforms); const animateRef = useRef(animate); useLayoutEffect(() => { uniformsRef.current = uniforms; animateRef.current = animate; }); useEffect(() => { if (!resources || !comp || !app) return; const _shader = ` precision mediump float; varying vec2 vTextureCoord; varying vec4 vColor; uniform sampler2D uSampler; uniform float customUniform; void main(void) { vec2 uvs = vTextureCoord.xy; vec4 fg = texture2D(uSampler, vTextureCoord); fg.r = uvs.y + sin(customUniform); //fg.r = clamp(fg.r,0.0,0.9); gl_FragColor = fg; } `; const filter = new Filter(undefined, _shader, { ...uniformsRef.current, }); comp.filters = [filter]; let animate: undefined | ((delta: number) => void); if (animateRef.current) { animate = (delta: number) => { animateRef.current?.(filter, delta); }; app.ticker.add(animate); } return () => { if (animate) app.ticker.remove(animate); }; }, [app, comp, resources]); return null } // usage usePixiShader({ comp: sprite?.sprite, uniforms: { customUniform: 0, }, animate: (filter, delta) => { filter.uniforms.customUniform += 0.04 * delta; }, });
-
Flow this topic if you don't Use Shader a lot. i try made that because most of member prefer to don't Use shader we talk about this stuffs step by step : What is Shader How It work in GPU : understanding How can i use it How can start programming in shader what information we access in shader [ more question added in next ] we try talk about one stuff per days
- 8 replies
-
- step by step
- shader vertex
-
(and 2 more)
Tagged with: