[{"data":1,"prerenderedAt":527,"buildId":528},["ShallowReactive",2],{"doc-\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage":3,"github-stars":435,"guide-nav":437},{"id":4,"title":5,"body":6,"categoryId":419,"categorySlug":420,"categoryTitle":421,"curated":422,"description":15,"editUrl":423,"extension":424,"group":425,"groupTitle":426,"kind":427,"meta":428,"navigation":429,"path":430,"seo":431,"sourceUrl":432,"stem":433,"wordCount":423,"__hash__":434},"primitives\u002Fdocs\u002Fprimitives\u002F48.sim-grids\u002F2.stage.md","stage",{"type":7,"value":8,"toc":412},"minimark",[9,12,16,38,53,60,103,108,242,255,259,379,383,394,398,408],[10,11,5],"h1",{"id":5},[13,14,15],"p",{},"The stages a grid frame is built from.",[17,18,23],"pre",{"className":19,"code":20,"language":21,"meta":22,"style":22},"language-ts shiki shiki-themes github-dark","stage: { host, values, settle, readyWhen, pass, cache, publish, seedOnce, iterate, sortPass }\n","ts","",[24,25,26],"code",{"__ignoreMap":22},[27,28,31,34],"span",{"class":29,"line":30},"line",1,[27,32,5],{"class":33},"svObZ",[27,35,37],{"class":36},"s95oV",": { host, values, settle, readyWhen, pass, cache, publish, seedOnce, iterate, sortPass }\n",[13,39,40,41,44,45,48,49,52],{},"Import ",[24,42,43],{},"sim"," from ",[24,46,47],{},"shaders\u002Fstd"," and use ",[24,50,51],{},"sim.grids.stage",".",[13,54,55,56,59],{},"List them in ",[24,57,58],{},"stages"," in the order they should run.",[13,61,62,63,66,67,70,71,74,75,78,79,82,83,86,87,90,91,94,95,98,99,102],{},"Bookkeeping: ",[24,64,65],{},"host"," (before any gate), ",[24,68,69],{},"values"," (write this frame's values), ",[24,72,73],{},"readyWhen"," (wait for an input), ",[24,76,77],{},"settle"," (sleep once the field is still). Work: ",[24,80,81],{},"pass"," (one GPU pass), ",[24,84,85],{},"cache"," (a pass picked per frame), ",[24,88,89],{},"seedOnce"," (a one-shot reset), ",[24,92,93],{},"iterate"," (a pass N times), ",[24,96,97],{},"sortPass"," (a compare-swap chain), ",[24,100,101],{},"publish"," (write the result the layer samples).",[104,105,107],"h2",{"id":106},"example","Example",[17,109,111],{"className":19,"code":110,"language":21,"meta":22,"style":22},"stages: [stage.readyWhen(() => ready), stage.values('write', (f) => paramsU.write({dt: f.dt})), stage.iterate({count: () => 8, step: (i, nodes) => nodes.push(react.with(i % 2 ? groupBA : groupAB))}), stage.publish(() => output)]\n",[24,112,113],{"__ignoreMap":22},[27,114,115,117,120,122,125,129,132,134,137,141,144,148,151,153,156,159,162,164,167,170,173,175,179,182,185,188,191,193,196,198,200,203,206,209,212,215,218,221,224,227,230,233,235,237,239],{"class":29,"line":30},[27,116,58],{"class":33},[27,118,119],{"class":36},": [stage.",[27,121,73],{"class":33},[27,123,124],{"class":36},"(() ",[27,126,128],{"class":127},"snl16","=>",[27,130,131],{"class":36}," ready), stage.",[27,133,69],{"class":33},[27,135,136],{"class":36},"(",[27,138,140],{"class":139},"sU2Wk","'write'",[27,142,143],{"class":36},", (",[27,145,147],{"class":146},"s9osk","f",[27,149,150],{"class":36},") ",[27,152,128],{"class":127},[27,154,155],{"class":36}," paramsU.",[27,157,158],{"class":33},"write",[27,160,161],{"class":36},"({dt: f.dt})), stage.",[27,163,93],{"class":33},[27,165,166],{"class":36},"({",[27,168,169],{"class":33},"count",[27,171,172],{"class":36},": () ",[27,174,128],{"class":127},[27,176,178],{"class":177},"sDLfK"," 8",[27,180,181],{"class":36},", ",[27,183,184],{"class":33},"step",[27,186,187],{"class":36},": (",[27,189,190],{"class":146},"i",[27,192,181],{"class":36},[27,194,195],{"class":146},"nodes",[27,197,150],{"class":36},[27,199,128],{"class":127},[27,201,202],{"class":36}," nodes.",[27,204,205],{"class":33},"push",[27,207,208],{"class":36},"(react.",[27,210,211],{"class":33},"with",[27,213,214],{"class":36},"(i ",[27,216,217],{"class":127},"%",[27,219,220],{"class":177}," 2",[27,222,223],{"class":127}," ?",[27,225,226],{"class":36}," groupBA ",[27,228,229],{"class":127},":",[27,231,232],{"class":36}," groupAB))}), stage.",[27,234,101],{"class":33},[27,236,124],{"class":36},[27,238,128],{"class":127},[27,240,241],{"class":36}," output)]\n",[243,244,245],"blockquote",{},[13,246,247,251,252,254],{},[248,249,250],"strong",{},"Tip."," A ",[24,253,69],{}," stage sits before the passes that read it. Stages run in list order.",[104,256,258],{"id":257},"members","Members",[260,261,262,276,285,298,314,323,332,341,354,366],"ul",{},[263,264,265,272,273,275],"li",{},[266,267,269],"a",{"href":268},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-host",[24,270,271],{},"stage.host"," — A named step that runs before any gate: pointer smoothing, activity flags, anything a later ",[24,274,77],{}," needs to know.",[263,277,278,284],{},[266,279,281],{"href":280},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-values",[24,282,283],{},"stage.values"," — A named step that writes this frame's values for the passes after it.",[263,286,287,293,294,297],{},[266,288,290],{"href":289},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-settle",[24,291,292],{},"stage.settle"," — Sleep the simulation once nothing has driven it for ",[24,295,296],{},"settleMs"," of simulated time.",[263,299,300,306,307,310,311,52],{},[266,301,303],{"href":302},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-readywhen",[24,304,305],{},"stage.readyWhen"," — Run nothing until ",[24,308,309],{},"fn"," returns true, typically once the child's picture has arrived through ",[24,312,313],{},"bindInputs",[263,315,316,322],{},[266,317,319],{"href":318},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-pass",[24,320,321],{},"stage.pass"," — One GPU pass, the same every frame.",[263,324,325,331],{},[266,326,328],{"href":327},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-cache",[24,329,330],{},"stage.cache"," — A GPU pass chosen per frame, for a pass whose input is rebound after the frame starts.",[263,333,334,340],{},[266,335,337],{"href":336},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-publish",[24,338,339],{},"stage.publish"," — The last stage: write the state into the texture the layer samples.",[263,342,343,349,350,353],{},[266,344,346],{"href":345},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-seedonce",[24,347,348],{},"stage.seedOnce"," — A one-shot reset run before the rest of the frame whenever ",[24,351,352],{},"staleWhen"," says the state is stale: on the first frame, or when a seed prop changes.",[263,355,356,362,363,365],{},[266,357,359],{"href":358},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-iterate",[24,360,361],{},"stage.iterate"," — Run a step ",[24,364,169],{}," times this frame.",[263,367,368,374,375,378],{},[266,369,371],{"href":370},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage-sortpass",[24,372,373],{},"stage.sortPass"," — A compare-and-swap sort that converges a little more every frame: ",[24,376,377],{},"passes"," swaps per frame, alternating odd and even pairs and the two buffers.",[104,380,382],{"id":381},"see-also","See also",[260,384,385],{},[263,386,387,393],{},[266,388,390],{"href":389},"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fgridsim",[24,391,392],{},"gridSim"," — A field of cells advanced every frame by an ordered list of stages.",[104,395,397],{"id":396},"used-by","Used by",[13,399,400,181,404],{},[266,401,403],{"href":402},"\u002Fdocs\u002Fcomponents\u002Fpixelsort","PixelSort",[266,405,407],{"href":406},"\u002Fdocs\u002Fcomponents\u002Freactiondiffusion","ReactionDiffusion",[409,410,411],"style",{},"html pre.shiki code .svObZ, html code.shiki .svObZ{--shiki-default:#B392F0}html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html pre.shiki code .s9osk, html code.shiki .s9osk{--shiki-default:#FFAB70}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}",{"title":22,"searchDepth":413,"depth":413,"links":414},2,[415,416,417,418],{"id":106,"depth":413,"text":107},{"id":257,"depth":413,"text":258},{"id":381,"depth":413,"text":382},{"id":396,"depth":413,"text":397},"sim.grids","sim-grids","Grid programs",false,null,"md","simulation","Simulation","object",{},true,"\u002Fdocs\u002Fprimitives\u002Fsim-grids\u002Fstage",{"title":5,"description":15},"https:\u002F\u002Fgithub.com\u002Fshader-effects-inc\u002Fshaders\u002Fblob\u002Fmain\u002Fpackages\u002Fcore\u002Fsrc\u002Fstd\u002Fsim\u002Fgrids.ts#L185","docs\u002Fprimitives\u002F48.sim-grids\u002F2.stage","g8NTcgP3iR1sKoemX55PCQ58NHGgXjmKaP3GowoGHtI",{"stars":436},6080,[438,442,446,450,454,458,462,466,470,474,478,482,486,490,494,498,502,507,511,515,519,523],{"path":439,"title":440,"description":441,"category":24},"\u002Fdocs\u002Fguide","Getting started","Shaders is a desktop app where your AI agent designs interactive effects on an infinite canvas, and you shape them by hand.",{"path":443,"title":444,"description":445,"category":24},"\u002Fdocs\u002Fguide\u002Fquickstart","Quickstart","Install Shaders, render your first effect, and drive a prop from state.",{"path":447,"title":448,"description":449,"category":24},"\u002Fdocs\u002Fguide\u002Fcomposing-effects","Composing effects","Stack components as layers and nest them to control which layers an effect touches.",{"path":451,"title":452,"description":453,"category":24},"\u002Fdocs\u002Fguide\u002Fblending-masking","Blending and masking","Control how a layer mixes with the layers below it, and reveal one layer through another.",{"path":455,"title":456,"description":457,"category":24},"\u002Fdocs\u002Fguide\u002Fprops-reactivity","Props and reactivity","Bind props to your framework's state so effects update when it changes, and animate props with an animation library.",{"path":459,"title":460,"description":461,"category":24},"\u002Fdocs\u002Fguide\u002Fanimation","Animating a shader","Tween a shader's props with Motion, GSAP or anything else that animates a number.",{"path":463,"title":464,"description":465,"category":24},"\u002Fdocs\u002Fguide\u002Fdynamic-props","Dynamic props","Drive any numeric or position prop from time, the cursor, or another layer, without writing animation code.",{"path":467,"title":468,"description":469,"category":24},"\u002Fdocs\u002Fguide\u002Flayout-positioning","Layout and positioning","Size and place a shader in your page with CSS, as a background, a fill, or an inline block.",{"path":471,"title":472,"description":473,"category":24},"\u002Fdocs\u002Fguide\u002Fsizing-and-units","Sizing and units","Size and place layers in CSS units (px, %, vw, rem, and canvas units) that stay correct as the canvas and window resize.",{"path":475,"title":476,"description":477,"category":24},"\u002Fdocs\u002Fguide\u002Ftransforms","Transforms","Position, size, and rotate any layer inside the canvas with a bounding box, in any CSS unit.",{"path":479,"title":480,"description":481,"category":24},"\u002Fdocs\u002Fguide\u002Fshape-effects","Shape effects","Pick the 2D, 3D or custom SVG shape that Glass, Neon, Emboss and other shape effects draw inside.",{"path":483,"title":484,"description":485,"category":24},"\u002Fdocs\u002Fguide\u002Fcolor-space","Color space","Match colors to your design tool with the output color space, and keep bright layers from clipping with tone mapping.",{"path":487,"title":488,"description":489,"category":24},"\u002Fdocs\u002Fguide\u002Fhooks-events","Hooks and events","Run code when an effect is ready to show, and show a fallback when the GPU can't run it.",{"path":491,"title":492,"description":493,"category":24},"\u002Fdocs\u002Fguide\u002Fperformance","Performance","Learn what makes an effect expensive on the GPU and how to keep it inside the frame budget.",{"path":495,"title":496,"description":497,"category":24},"\u002Fdocs\u002Fguide\u002Fcustom-shaders","Custom components","Write your own component in TypeScript, use it like any component in the library, and write WGSL by hand when you need to.",{"path":499,"title":500,"description":501,"category":24},"\u002Fdocs\u002Fguide\u002Ftelemetry","Telemetry","The `\u003CShader>` component occasionally sends an anonymous performance report to help us improve the engine over time.",{"path":503,"title":504,"description":505,"category":506},"\u002Fdocs\u002Fguide\u002Fmcp","Working with your agent","The Shaders MCP connects your AI agent to the desktop app, so it can design shaders on your canvas and install them in your project.","workflows",{"path":508,"title":509,"description":510,"category":506},"\u002Fdocs\u002Fguide\u002Fcli","Working with the CLI","The Shaders CLI installs shaders from your projects and the Pro library into your codebase as component files, and keeps them in sync as you keep designing.",{"path":512,"title":513,"description":514,"category":506},"\u002Fdocs\u002Fguide\u002Fframeworks","Supported frameworks","Shaders runs in any web project that renders in a browser with WebGPU, with components for React, Vue, Svelte and Solid and a JavaScript API for everything else.",{"path":516,"title":517,"description":518,"category":24},"\u002Fdocs\u002Fguide\u002Fagent-skill","Agent skill for the engine","Teach your coding agent to write Shaders code with the open-source engine, for when it's working in your codebase instead of on the canvas.",{"path":520,"title":521,"description":522,"category":24},"\u002Fdocs\u002Fguide\u002Fvideo-rendering","Rendering to video","Render a shader effect to video frame by frame, from Remotion, Hyperframes or your own headless Chrome script.",{"path":524,"title":525,"description":526,"category":24},"\u002Fdocs\u002Fguide\u002Fssr","Server rendering","Render Shaders in Next.js, Nuxt, SvelteKit, SolidStart and other SSR apps by keeping each shader on the client.",1796051187268,"06e02370-81a6-4d74-9931-661d71414be1"]