[{"data":1,"prerenderedAt":334,"buildId":335},["ShallowReactive",2],{"doc-\u002Fdocs\u002Fprimitives\u002Fmath\u002Ffwidth":3,"github-stars":242,"guide-nav":244},{"id":4,"title":5,"body":6,"categoryId":47,"categorySlug":47,"categoryTitle":227,"curated":228,"description":229,"editUrl":230,"extension":231,"group":232,"groupTitle":233,"kind":234,"meta":235,"navigation":236,"path":237,"seo":238,"sourceUrl":239,"stem":240,"wordCount":230,"__hash__":241},"primitives\u002Fdocs\u002Fprimitives\u002F22.math\u002F52.fwidth.md","fwidth",{"type":7,"value":8,"toc":222},"minimark",[9,12,21,42,56,59,64,101,105,173,191,195,218],[10,11,5],"h1",{"id":5},[13,14,15,16,20],"p",{},"How much a value changes across one pixel, in any direction: ",[17,18,19],"code",{},"|dpdx| + |dpdy|",".",[22,23,28],"pre",{"className":24,"code":25,"language":26,"meta":27,"style":27},"language-ts shiki shiki-themes github-dark","fwidth(x: Val): Expr\n","ts","",[17,29,30],{"__ignoreMap":27},[31,32,35,38],"span",{"class":33,"line":34},"line",1,[31,36,5],{"class":37},"svObZ",[31,39,41],{"class":40},"s95oV","(x: Val): Expr\n",[13,43,44,45,48,49,52,53,20],{},"Import ",[17,46,47],{},"math"," from ",[17,50,51],{},"shaders\u002Fstd"," and use ",[17,54,55],{},"math.fwidth",[13,57,58],{},"The pixel footprint of anything you compute: feather an edge by it, or spread samples over it. Like every derivative it exists only in a pixel body, never in a compute input.",[60,61,63],"h2",{"id":62},"parameters","Parameters",[65,66,67,83],"table",{},[68,69,70],"thead",{},[71,72,73,77,80],"tr",{},[74,75,76],"th",{},"Name",[74,78,79],{},"Type",[74,81,82],{},"Notes",[84,85,86],"tbody",{},[71,87,88,94,99],{},[89,90,91],"td",{},[17,92,93],{},"x",[89,95,96],{},[17,97,98],{},"Val",[89,100],{},[60,102,104],{"id":103},"example","Example",[22,106,108],{"className":24,"code":107,"language":26,"meta":27,"style":27},"const aa = local(fwidth(sdf), 'aa')\nconst coverage = sub(1, smoothstep(neg(aa), aa, sdf))\n",[17,109,110,141],{"__ignoreMap":27},[31,111,112,116,120,123,126,129,131,134,138],{"class":33,"line":34},[31,113,115],{"class":114},"snl16","const",[31,117,119],{"class":118},"sDLfK"," aa",[31,121,122],{"class":114}," =",[31,124,125],{"class":37}," local",[31,127,128],{"class":40},"(",[31,130,5],{"class":37},[31,132,133],{"class":40},"(sdf), ",[31,135,137],{"class":136},"sU2Wk","'aa'",[31,139,140],{"class":40},")\n",[31,142,144,146,149,151,154,156,159,162,165,167,170],{"class":33,"line":143},2,[31,145,115],{"class":114},[31,147,148],{"class":118}," coverage",[31,150,122],{"class":114},[31,152,153],{"class":37}," sub",[31,155,128],{"class":40},[31,157,158],{"class":118},"1",[31,160,161],{"class":40},", ",[31,163,164],{"class":37},"smoothstep",[31,166,128],{"class":40},[31,168,169],{"class":37},"neg",[31,171,172],{"class":40},"(aa), aa, sdf))\n",[174,175,176],"blockquote",{},[13,177,178,182,183,186,187,190],{},[179,180,181],"strong",{},"Tip."," Derivatives are only legal outside per-pixel branches: wrap the result in ",[17,184,185],{},"local()"," before the guard and pass that local to ",[17,188,189],{},"guarded"," as a dep.",[60,192,194],{"id":193},"see-also","See also",[196,197,198,209],"ul",{},[199,200,201,208],"li",{},[202,203,205],"a",{"href":204},"\u002Fdocs\u002Fprimitives\u002Fmath\u002Fdpdx",[17,206,207],{},"dpdx"," — How much a value changes from this pixel to the next one to the right.",[199,210,211,217],{},[202,212,214],{"href":213},"\u002Fdocs\u002Fprimitives\u002Fmath\u002Fdpdy",[17,215,216],{},"dpdy"," — How much a value changes from this pixel to the next one down.",[219,220,221],"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 .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}",{"title":27,"searchDepth":143,"depth":143,"links":223},[224,225,226],{"id":62,"depth":143,"text":63},{"id":103,"depth":143,"text":104},{"id":193,"depth":143,"text":194},"Math",false,"How much a value changes across one pixel, in any direction: `|dpdx| + |dpdy|`.",null,"md","space","Shapes, frames & warps","function",{},true,"\u002Fdocs\u002Fprimitives\u002Fmath\u002Ffwidth",{"title":5,"description":229},"https:\u002F\u002Fgithub.com\u002Fshader-effects-inc\u002Fshaders\u002Fblob\u002Fmain\u002Fpackages\u002Fcore\u002Fsrc\u002Fstd\u002Fmath.ts#L456","docs\u002Fprimitives\u002F22.math\u002F52.fwidth","IqqTJCPEDXhMiLcY3n76te5d5bMcOe9AXk9Rormnsbk",{"stars":243},6080,[245,249,253,257,261,265,269,273,277,281,285,289,293,297,301,305,309,314,318,322,326,330],{"path":246,"title":247,"description":248,"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":250,"title":251,"description":252,"category":17},"\u002Fdocs\u002Fguide\u002Fquickstart","Quickstart","Install Shaders, render your first effect, and drive a prop from state.",{"path":254,"title":255,"description":256,"category":17},"\u002Fdocs\u002Fguide\u002Fcomposing-effects","Composing effects","Stack components as layers and nest them to control which layers an effect touches.",{"path":258,"title":259,"description":260,"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":262,"title":263,"description":264,"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":266,"title":267,"description":268,"category":17},"\u002Fdocs\u002Fguide\u002Fanimation","Animating a shader","Tween a shader's props with Motion, GSAP or anything else that animates a number.",{"path":270,"title":271,"description":272,"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":274,"title":275,"description":276,"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":278,"title":279,"description":280,"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":282,"title":283,"description":284,"category":17},"\u002Fdocs\u002Fguide\u002Ftransforms","Transforms","Position, size, and rotate any layer inside the canvas with a bounding box, in any CSS unit.",{"path":286,"title":287,"description":288,"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":290,"title":291,"description":292,"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":294,"title":295,"description":296,"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":298,"title":299,"description":300,"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":302,"title":303,"description":304,"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":306,"title":307,"description":308,"category":17},"\u002Fdocs\u002Fguide\u002Ftelemetry","Telemetry","The `\u003CShader>` component occasionally sends an anonymous performance report to help us improve the engine over time.",{"path":310,"title":311,"description":312,"category":313},"\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":315,"title":316,"description":317,"category":313},"\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":319,"title":320,"description":321,"category":313},"\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":323,"title":324,"description":325,"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":327,"title":328,"description":329,"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":331,"title":332,"description":333,"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.",1796051181834,"06e02370-81a6-4d74-9931-661d71414be1"]