[{"data":1,"prerenderedAt":514,"buildId":515},["ShallowReactive",2],{"doc-\u002Fdocs\u002Fprimitives\u002Fsimulate\u002Ffluid":3,"github-stars":422,"guide-nav":424},{"id":4,"title":5,"body":6,"categoryId":69,"categorySlug":69,"categoryTitle":408,"curated":409,"description":15,"editUrl":410,"extension":411,"group":412,"groupTitle":413,"kind":414,"meta":415,"navigation":416,"path":417,"seo":418,"sourceUrl":419,"stem":420,"wordCount":410,"__hash__":421},"primitives\u002Fdocs\u002Fprimitives\u002F46.simulate\u002F3.fluid.md","fluid",{"type":7,"value":8,"toc":404},"minimark",[9,12,16,64,79,201,206,247,251,400],[10,11,5],"h1",{"id":5},[13,14,15],"p",{},"A fluid solve with coloured dye.",[17,18,23],"pre",{"className":19,"code":20,"language":21,"meta":22,"style":22},"language-ts shiki shiki-themes github-dark","fluid(opts: Parameters\u003Ctypeof fluidInput>[0] = {}): FluidInput\n","ts","",[24,25,26],"code",{"__ignoreMap":22},[27,28,31,34,38,42,45,48,51,55,58,61],"span",{"class":29,"line":30},"line",1,[27,32,5],{"class":33},"svObZ",[27,35,37],{"class":36},"s95oV","(opts: Parameters",[27,39,41],{"class":40},"snl16","\u003Ctypeof",[27,43,44],{"class":36}," fluidInput",[27,46,47],{"class":40},">",[27,49,50],{"class":36},"[",[27,52,54],{"class":53},"sDLfK","0",[27,56,57],{"class":36},"] ",[27,59,60],{"class":40},"=",[27,62,63],{"class":36}," {}): FluidInput\n",[13,65,66,67,70,71,74,75,78],{},"Import ",[24,68,69],{},"simulate"," from ",[24,72,73],{},"shaders\u002Fstd"," and use ",[24,76,77],{},"simulate.fluid",".",[80,81,82],"ul",{},[83,84,85,88,89,92,93,96,97,100,101,104,105,108,109,111,112,115,116,100,119,122,123,125,126,129,130,133,134,137,138,141,142,108,145,148,149,152,153,156,157,159,160,163,164,166,167,170,171,174,175,177,178,180,181,184,185,188,189,192,193,196,197,200],"li",{},[24,86,87],{},"velocity"," \u002F ",[24,90,91],{},"dye.res",": grid sizes (cells on the long side). 256 \u002F 512 is a good start. - ",[24,94,95],{},"dye.space: 'oklab'"," carries the dye in OKLab, so colours mix cleanly instead of going muddy. - ",[24,98,99],{},"forces",": WGSL returning a ",[24,102,103],{},"vec2f"," acceleration for this cell (uv per second²). It sees ",[24,106,107],{},"cellUV",", ",[24,110,87],{}," (this cell's), ",[24,113,114],{},"dye"," (this cell's colour), and everything a body sees. - ",[24,117,118],{},"inject",[24,120,121],{},"vec4f"," of dye to add this frame at this cell (premultiplied: the alpha is how much). It sees ",[24,124,114],{},", the cell's dye before this frame's addition (straight linear colour, alpha how much), so a spout can top up to a set thickness: ",[24,127,128],{},"return vec4f(color.rgb, 1.0) * max(target - dye.a, 0.0)",". ",[24,131,132],{},"isNew(period)"," is true on the first frame of each ",[24,135,136],{},"period","-second slot: use it to add a drop once instead of every frame. - ",[24,139,140],{},"init",": WGSL returning the dye's first state at this cell (straight linear colour, alpha how much), written once when the fluid starts: a pool that's already full. - ",[24,143,144],{},"stir",[24,146,147],{},"dissipation"," and ",[24,150,151],{},"drain.floor"," take a number or a prop (",[24,154,155],{},"stir: p('smear')","), read live each frame. - ",[24,158,144],{},": how hard the pointer pushes the fluid (0 turns it off; default 1). A drag swirls it; for clicks, read ",[24,161,162],{},"events('click')"," in ",[24,165,118],{}," and add dye where they land. - ",[24,168,169],{},"boundary.floor: 'solid'"," makes the bottom a wall dye piles up against (paint pooling); ",[24,172,173],{},"boundary.walls: 'solid'"," does the same at the sides. ",[24,176,151],{}," removes that much dye per second near the floor so the canvas never fills. - ",[24,179,147],{},": how fast the flow's motion dies away (default 0.2; 0 keeps it swirling, higher feels thicker). The dye itself never fades; ",[24,182,183],{},"drain"," removes it. - ",[24,186,187],{},"pressureIterations",": solver accuracy (default 20); more keeps swirls tighter, at a cost. - Read the dye as ",[24,190,191],{},"ink(uv)",": straight-alpha colour, alpha how much dye is there (in OKLab mode it comes back as ordinary linear colour). ",[24,194,195],{},"ink.velocity(uv).xy"," is the flow, in uv per second. Shade from the dye's alpha (its slope gives a surface normal) for a thick, glossy look. - The solve runs at a fixed size, so its cost doesn't grow with the canvas; ",[24,198,199],{},"dt"," follows Speed.",[202,203,205],"h2",{"id":204},"parameters","Parameters",[207,208,209,225],"table",{},[210,211,212],"thead",{},[213,214,215,219,222],"tr",{},[216,217,218],"th",{},"Name",[216,220,221],{},"Type",[216,223,224],{},"Notes",[226,227,228],"tbody",{},[213,229,230,236,241],{},[231,232,233],"td",{},[24,234,235],{},"opts",[231,237,238],{},[24,239,240],{},"Parameters\u003Ctypeof fluidInput>[0]",[231,242,243,244,78],{},"Optional. Default ",[24,245,246],{},"{}",[202,248,250],{"id":249},"example","Example",[17,252,254],{"className":19,"code":253,"language":21,"meta":22,"style":22},"inputs: {\n  ink: simulate.fluid({\n    velocity: 256, dye: {res: 512, space: 'oklab'}, boundary: {floor: 'solid'}, drain: {floor: 0.05},\n    forces: wgsl`return vec2f(0.0, gravity * dye.a);`,\n    inject: wgsl`\n      let id = floor(time * drops);\n      let at = vec2f(hash11(id), 0.08);\n      let k = select(0.0, 1.0, isNew(1.0 \u002F drops)) * (1.0 - smoothstep(0.0, 0.03, distance(cellUV, at)));\n      return colors(hash11(id + 1.0)) * k;\n    `,\n  }),\n},\npaint: wgsl`return ink(uv);`,\n",[24,255,256,264,278,315,330,341,347,353,359,365,373,379,384],{"__ignoreMap":22},[27,257,258,261],{"class":29,"line":30},[27,259,260],{"class":33},"inputs",[27,262,263],{"class":36},": {\n",[27,265,267,270,273,275],{"class":29,"line":266},2,[27,268,269],{"class":33},"  ink",[27,271,272],{"class":36},": simulate.",[27,274,5],{"class":33},[27,276,277],{"class":36},"({\n",[27,279,281,284,287,290,293,296,300,303,306,309,312],{"class":29,"line":280},3,[27,282,283],{"class":36},"    velocity: ",[27,285,286],{"class":53},"256",[27,288,289],{"class":36},", dye: {res: ",[27,291,292],{"class":53},"512",[27,294,295],{"class":36},", space: ",[27,297,299],{"class":298},"sU2Wk","'oklab'",[27,301,302],{"class":36},"}, boundary: {floor: ",[27,304,305],{"class":298},"'solid'",[27,307,308],{"class":36},"}, drain: {floor: ",[27,310,311],{"class":53},"0.05",[27,313,314],{"class":36},"},\n",[27,316,318,321,324,327],{"class":29,"line":317},4,[27,319,320],{"class":36},"    forces: ",[27,322,323],{"class":33},"wgsl",[27,325,326],{"class":298},"`return vec2f(0.0, gravity * dye.a);`",[27,328,329],{"class":36},",\n",[27,331,333,336,338],{"class":29,"line":332},5,[27,334,335],{"class":36},"    inject: ",[27,337,323],{"class":33},[27,339,340],{"class":298},"`\n",[27,342,344],{"class":29,"line":343},6,[27,345,346],{"class":298},"      let id = floor(time * drops);\n",[27,348,350],{"class":29,"line":349},7,[27,351,352],{"class":298},"      let at = vec2f(hash11(id), 0.08);\n",[27,354,356],{"class":29,"line":355},8,[27,357,358],{"class":298},"      let k = select(0.0, 1.0, isNew(1.0 \u002F drops)) * (1.0 - smoothstep(0.0, 0.03, distance(cellUV, at)));\n",[27,360,362],{"class":29,"line":361},9,[27,363,364],{"class":298},"      return colors(hash11(id + 1.0)) * k;\n",[27,366,368,371],{"class":29,"line":367},10,[27,369,370],{"class":298},"    `",[27,372,329],{"class":36},[27,374,376],{"class":29,"line":375},11,[27,377,378],{"class":36},"  }),\n",[27,380,382],{"class":29,"line":381},12,[27,383,314],{"class":36},[27,385,387,390,393,395,398],{"class":29,"line":386},13,[27,388,389],{"class":33},"paint",[27,391,392],{"class":36},": ",[27,394,323],{"class":33},[27,396,397],{"class":298},"`return ink(uv);`",[27,399,329],{"class":36},[401,402,403],"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 pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}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 .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}",{"title":22,"searchDepth":266,"depth":266,"links":405},[406,407],{"id":204,"depth":266,"text":205},{"id":249,"depth":266,"text":250},"Simulate",false,null,"md","simulation","Simulation","function",{},true,"\u002Fdocs\u002Fprimitives\u002Fsimulate\u002Ffluid",{"title":5,"description":15},"https:\u002F\u002Fgithub.com\u002Fshader-effects-inc\u002Fshaders\u002Fblob\u002Fmain\u002Fpackages\u002Fcore\u002Fsrc\u002Fstd\u002Fsimulate.ts#L134","docs\u002Fprimitives\u002F46.simulate\u002F3.fluid","-ugasgc26I5FsM9LoypPH9-xvylf7HZQtEfYzfusZbg",{"stars":423},6080,[425,429,433,437,441,445,449,453,457,461,465,469,473,477,481,485,489,494,498,502,506,510],{"path":426,"title":427,"description":428,"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":430,"title":431,"description":432,"category":24},"\u002Fdocs\u002Fguide\u002Fquickstart","Quickstart","Install Shaders, render your first effect, and drive a prop from state.",{"path":434,"title":435,"description":436,"category":24},"\u002Fdocs\u002Fguide\u002Fcomposing-effects","Composing effects","Stack components as layers and nest them to control which layers an effect touches.",{"path":438,"title":439,"description":440,"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":442,"title":443,"description":444,"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":446,"title":447,"description":448,"category":24},"\u002Fdocs\u002Fguide\u002Fanimation","Animating a shader","Tween a shader's props with Motion, GSAP or anything else that animates a number.",{"path":450,"title":451,"description":452,"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":454,"title":455,"description":456,"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":458,"title":459,"description":460,"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":462,"title":463,"description":464,"category":24},"\u002Fdocs\u002Fguide\u002Ftransforms","Transforms","Position, size, and rotate any layer inside the canvas with a bounding box, in any CSS unit.",{"path":466,"title":467,"description":468,"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":470,"title":471,"description":472,"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":474,"title":475,"description":476,"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":478,"title":479,"description":480,"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":482,"title":483,"description":484,"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":486,"title":487,"description":488,"category":24},"\u002Fdocs\u002Fguide\u002Ftelemetry","Telemetry","The `\u003CShader>` component occasionally sends an anonymous performance report to help us improve the engine over time.",{"path":490,"title":491,"description":492,"category":493},"\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":495,"title":496,"description":497,"category":493},"\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":499,"title":500,"description":501,"category":493},"\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":503,"title":504,"description":505,"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":507,"title":508,"description":509,"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":511,"title":512,"description":513,"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.",1796051186190,"06e02370-81a6-4d74-9931-661d71414be1"]