[{"data":1,"prerenderedAt":492,"buildId":493},["ShallowReactive",2],{"doc-\u002Fdocs\u002Fprimitives\u002Fsimulate\u002Fgrid":3,"github-stars":400,"guide-nav":402},{"id":4,"title":5,"body":6,"categoryId":62,"categorySlug":62,"categoryTitle":385,"curated":386,"description":387,"editUrl":388,"extension":389,"group":390,"groupTitle":391,"kind":392,"meta":393,"navigation":394,"path":395,"seo":396,"sourceUrl":397,"stem":398,"wordCount":388,"__hash__":399},"primitives\u002Fdocs\u002Fprimitives\u002F46.simulate\u002F1.grid.md","grid",{"type":7,"value":8,"toc":380},"minimark",[9,12,29,57,71,81,165,170,207,211,355,359,376],[10,11,5],"h1",{"id":5},[13,14,15,16,20,21,24,25,28],"p",{},"A grid of ",[17,18,19],"code",{},"vec4f"," cells advanced once per frame by ",[17,22,23],{},"step",", with named outputs in ",[17,26,27],{},"derive",".",[30,31,36],"pre",{"className":32,"code":33,"language":34,"meta":35,"style":35},"language-ts shiki shiki-themes github-dark","grid(config: GridSimInit): GridSim & InputNode\n","ts","",[17,37,38],{"__ignoreMap":35},[39,40,43,46,50,54],"span",{"class":41,"line":42},"line",1,[39,44,5],{"class":45},"svObZ",[39,47,49],{"class":48},"s95oV","(config: GridSimInit): GridSim ",[39,51,53],{"class":52},"snl16","&",[39,55,56],{"class":48}," InputNode\n",[13,58,59,60,63,64,67,68,28],{},"Import ",[17,61,62],{},"simulate"," from ",[17,65,66],{},"shaders\u002Fstd"," and use ",[17,69,70],{},"simulate.grid",[13,72,73,74,77,78,28],{},"Read the grid in WGSL as ",[17,75,76],{},"name(uv)"," (bilinear between cell centres) and an output as ",[17,79,80],{},"name.output(uv)",[82,83,84],"ul",{},[85,86,87,90,91,94,95,98,99,102,103,106,107,110,111,114,115,117,118,121,122,125,126,129,130,132,133,136,137,140,141,121,144,121,146,149,150,153,154,157,158,161,162,164],"li",{},[17,88,89],{},"resolution",": cells per side of a square grid, or ",[17,92,93],{},"[width, height]"," (it does not follow the frame's shape: give ",[17,96,97],{},"[w, h]"," in the frame's proportions). Its cost is fixed, whatever the canvas size. - ",[17,100,101],{},"history: 2"," lets steps read last frame's state with ",[17,104,105],{},"readPrev"," (a wave, or Verlet motion). - ",[17,108,109],{},"precision: 'full'"," stores 32-bit cells, for positions and anything that moves by tiny amounts. - ",[17,112,113],{},"init"," seeds every cell once: a WGSL body returning ",[17,116,19],{}," that sees ",[17,119,120],{},"cell",", ",[17,123,124],{},"cellUV"," (the cell's centre, 0–1), ",[17,127,128],{},"gridSize",", props, helpers and library functions. - ",[17,131,23],{}," runs in order every frame: ",[17,134,135],{},"op.*"," steps and your own ",[17,138,139],{},"op.kernel"," bodies. A kernel reads the grid (",[17,142,143],{},"read",[17,145,105],{},[17,147,148],{},"readLinear","), the built-ins (",[17,151,152],{},"dt"," follows the layer's Speed), props, helpers and other inputs by name (",[17,155,156],{},"clicks(i)",", another grid's ",[17,159,160],{},"field(uv)","). - Revising the component restarts the grid from ",[17,163,113],{},"; a capture continues it.",[166,167,169],"h2",{"id":168},"parameters","Parameters",[171,172,173,189],"table",{},[174,175,176],"thead",{},[177,178,179,183,186],"tr",{},[180,181,182],"th",{},"Name",[180,184,185],{},"Type",[180,187,188],{},"Notes",[190,191,192],"tbody",{},[177,193,194,200,205],{},[195,196,197],"td",{},[17,198,199],{},"config",[195,201,202],{},[17,203,204],{},"GridSimInit",[195,206],{},[166,208,210],{"id":209},"example","Example",[30,212,214],{"className":32,"code":213,"language":34,"meta":35,"style":35},"inputs: {\n  field: simulate.grid({\n    resolution: 256, history: 2,\n    step: [op.wave({damping: p('decay')}), op.splat({at: pointer(), amount: pointerSpeed({max: 2}), radius: p('radius')})],\n    derive: {slope: op.gradient()},\n  }),\n},\neffect: wgsl`return textureSample(childTexture, childSampler, uv + field.slope(uv).xy * intensity);`,\n",[17,215,216,224,238,257,314,326,332,338],{"__ignoreMap":35},[39,217,218,221],{"class":41,"line":42},[39,219,220],{"class":45},"inputs",[39,222,223],{"class":48},": {\n",[39,225,227,230,233,235],{"class":41,"line":226},2,[39,228,229],{"class":45},"  field",[39,231,232],{"class":48},": simulate.",[39,234,5],{"class":45},[39,236,237],{"class":48},"({\n",[39,239,241,244,248,251,254],{"class":41,"line":240},3,[39,242,243],{"class":48},"    resolution: ",[39,245,247],{"class":246},"sDLfK","256",[39,249,250],{"class":48},", history: ",[39,252,253],{"class":246},"2",[39,255,256],{"class":48},",\n",[39,258,260,263,266,269,271,274,278,281,284,287,290,293,296,299,301,304,306,308,311],{"class":41,"line":259},4,[39,261,262],{"class":48},"    step: [op.",[39,264,265],{"class":45},"wave",[39,267,268],{"class":48},"({damping: ",[39,270,13],{"class":45},[39,272,273],{"class":48},"(",[39,275,277],{"class":276},"sU2Wk","'decay'",[39,279,280],{"class":48},")}), op.",[39,282,283],{"class":45},"splat",[39,285,286],{"class":48},"({at: ",[39,288,289],{"class":45},"pointer",[39,291,292],{"class":48},"(), amount: ",[39,294,295],{"class":45},"pointerSpeed",[39,297,298],{"class":48},"({max: ",[39,300,253],{"class":246},[39,302,303],{"class":48},"}), radius: ",[39,305,13],{"class":45},[39,307,273],{"class":48},[39,309,310],{"class":276},"'radius'",[39,312,313],{"class":48},")})],\n",[39,315,317,320,323],{"class":41,"line":316},5,[39,318,319],{"class":48},"    derive: {slope: op.",[39,321,322],{"class":45},"gradient",[39,324,325],{"class":48},"()},\n",[39,327,329],{"class":41,"line":328},6,[39,330,331],{"class":48},"  }),\n",[39,333,335],{"class":41,"line":334},7,[39,336,337],{"class":48},"},\n",[39,339,341,344,347,350,353],{"class":41,"line":340},8,[39,342,343],{"class":45},"effect",[39,345,346],{"class":48},": ",[39,348,349],{"class":45},"wgsl",[39,351,352],{"class":276},"`return textureSample(childTexture, childSampler, uv + field.slope(uv).xy * intensity);`",[39,354,256],{"class":48},[166,356,358],{"id":357},"see-also","See also",[82,360,361,366],{},[85,362,363],{},[17,364,365],{},"op",[85,367,368,375],{},[369,370,372],"a",{"href":371},"\u002Fdocs\u002Fprimitives\u002Ffilter\u002Fdisplaceby",[17,373,374],{},"displaceBy"," — Push the child's pixels around by a vector field from one of your simulations.",[377,378,379],"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 pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}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 .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}",{"title":35,"searchDepth":226,"depth":226,"links":381},[382,383,384],{"id":168,"depth":226,"text":169},{"id":209,"depth":226,"text":210},{"id":357,"depth":226,"text":358},"Simulate",false,"A grid of `vec4f` cells advanced once per frame by `step`, with named outputs in `derive`.",null,"md","simulation","Simulation","function",{},true,"\u002Fdocs\u002Fprimitives\u002Fsimulate\u002Fgrid",{"title":5,"description":387},"https:\u002F\u002Fgithub.com\u002Fshader-effects-inc\u002Fshaders\u002Fblob\u002Fmain\u002Fpackages\u002Fcore\u002Fsrc\u002Fstd\u002Fsimulate.ts#L49","docs\u002Fprimitives\u002F46.simulate\u002F1.grid","JmsK4IPmASGvOa8KbilyGNc9psKFu9DnzgWTE8yzbQo",{"stars":401},6080,[403,407,411,415,419,423,427,431,435,439,443,447,451,455,459,463,467,472,476,480,484,488],{"path":404,"title":405,"description":406,"category":17},"\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":408,"title":409,"description":410,"category":17},"\u002Fdocs\u002Fguide\u002Fquickstart","Quickstart","Install Shaders, render your first effect, and drive a prop from state.",{"path":412,"title":413,"description":414,"category":17},"\u002Fdocs\u002Fguide\u002Fcomposing-effects","Composing effects","Stack components as layers and nest them to control which layers an effect touches.",{"path":416,"title":417,"description":418,"category":17},"\u002Fdocs\u002Fguide\u002Fblending-masking","Blending and masking","Control how a layer mixes with the layers below it, and reveal one layer through another.",{"path":420,"title":421,"description":422,"category":17},"\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":424,"title":425,"description":426,"category":17},"\u002Fdocs\u002Fguide\u002Fanimation","Animating a shader","Tween a shader's props with Motion, GSAP or anything else that animates a number.",{"path":428,"title":429,"description":430,"category":17},"\u002Fdocs\u002Fguide\u002Fdynamic-props","Dynamic props","Drive any numeric or position prop from time, the cursor, or another layer, without writing animation code.",{"path":432,"title":433,"description":434,"category":17},"\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":436,"title":437,"description":438,"category":17},"\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":440,"title":441,"description":442,"category":17},"\u002Fdocs\u002Fguide\u002Ftransforms","Transforms","Position, size, and rotate any layer inside the canvas with a bounding box, in any CSS unit.",{"path":444,"title":445,"description":446,"category":17},"\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":448,"title":449,"description":450,"category":17},"\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":452,"title":453,"description":454,"category":17},"\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":456,"title":457,"description":458,"category":17},"\u002Fdocs\u002Fguide\u002Fperformance","Performance","Learn what makes an effect expensive on the GPU and how to keep it inside the frame budget.",{"path":460,"title":461,"description":462,"category":17},"\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":464,"title":465,"description":466,"category":17},"\u002Fdocs\u002Fguide\u002Ftelemetry","Telemetry","The `\u003CShader>` component occasionally sends an anonymous performance report to help us improve the engine over time.",{"path":468,"title":469,"description":470,"category":471},"\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":473,"title":474,"description":475,"category":471},"\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":477,"title":478,"description":479,"category":471},"\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":481,"title":482,"description":483,"category":17},"\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":485,"title":486,"description":487,"category":17},"\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":489,"title":490,"description":491,"category":17},"\u002Fdocs\u002Fguide\u002Fssr","Server rendering","Render Shaders in Next.js, Nuxt, SvelteKit, SolidStart and other SSR apps by keeping each shader on the client.",1796051186181,"06e02370-81a6-4d74-9931-661d71414be1"]