[{"data":1,"prerenderedAt":427,"buildId":428},["ShallowReactive",2],{"doc-\u002Fdocs\u002Fprimitives\u002Finputs-compute\u002Fkernel":3,"github-stars":335,"guide-nav":337},{"id":4,"title":5,"body":6,"categoryId":319,"categorySlug":320,"categoryTitle":321,"curated":322,"description":15,"editUrl":323,"extension":324,"group":325,"groupTitle":326,"kind":327,"meta":328,"navigation":329,"path":330,"seo":331,"sourceUrl":332,"stem":333,"wordCount":323,"__hash__":334},"primitives\u002Fdocs\u002Fprimitives\u002F41.inputs-compute\u002F2.kernel.md","kernel",{"type":7,"value":8,"toc":314},"minimark",[9,12,16,89,99,141,146,197,201,261,271,275,310],[10,11,5],"h1",{"id":5},[13,14,15],"p",{},"Your own compute pass.",[17,18,23],"pre",{"className":19,"code":20,"language":21,"meta":22,"style":22},"language-ts shiki shiki-themes github-dark","kernel(\n  body: WgslBody | string,\n  opts: {over: string | readonly [number, number]; iterations?: number; when?: 'frame' | 'init'},\n): KernelInput\n","ts","",[24,25,26,38,51,83],"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","(\n",[27,39,41,44,48],{"class":29,"line":40},2,[27,42,43],{"class":36},"  body: WgslBody ",[27,45,47],{"class":46},"snl16","|",[27,49,50],{"class":36}," string,\n",[27,52,54,57,59,62,65,68,70,74,77,80],{"class":29,"line":53},3,[27,55,56],{"class":36},"  opts: {over: string ",[27,58,47],{"class":46},[27,60,61],{"class":36}," readonly [number, number]; iterations",[27,63,64],{"class":46},"?:",[27,66,67],{"class":36}," number; when",[27,69,64],{"class":46},[27,71,73],{"class":72},"sU2Wk"," 'frame'",[27,75,76],{"class":46}," |",[27,78,79],{"class":72}," 'init'",[27,81,82],{"class":36},"},\n",[27,84,86],{"class":29,"line":85},4,[27,87,88],{"class":36},"): KernelInput\n",[13,90,91,92,94,95,98],{},"Import ",[24,93,5],{}," from ",[24,96,97],{},"shaders\u002Fstd",".",[13,100,101,102,105,106,109,110,113,114,117,118,121,122,125,126,125,129,132,133,136,137,140],{},"Over a buffer (",[24,103,104],{},"over: 'stars'",") it runs once per live element with ",[24,107,108],{},"index: u32","; over a grid size (",[24,111,112],{},"over: [64, 64]",") once per cell with ",[24,115,116],{},"cell: vec2i",". It reads and writes every buffer it names, reads other inputs by name (",[24,119,120],{},"soft(p)","), and sees props, built-ins (",[24,123,124],{},"time",", ",[24,127,128],{},"dt",[24,130,131],{},"pointer","…), library functions and helpers. ",[24,134,135],{},"iterations"," repeats it within a frame; ",[24,138,139],{},"when: 'init'"," runs it once, to seed a buffer (and again after a resize).",[142,143,145],"h2",{"id":144},"parameters","Parameters",[147,148,149,165],"table",{},[150,151,152],"thead",{},[153,154,155,159,162],"tr",{},[156,157,158],"th",{},"Name",[156,160,161],{},"Type",[156,163,164],{},"Notes",[166,167,168,183],"tbody",{},[153,169,170,176,181],{},[171,172,173],"td",{},[24,174,175],{},"body",[171,177,178],{},[24,179,180],{},"WgslBody | string",[171,182],{},[153,184,185,190,195],{},[171,186,187],{},[24,188,189],{},"opts",[171,191,192],{},[24,193,194],{},"{over: string | readonly [number, number]; iterations?: number; when?: 'frame' | 'init'}",[171,196],{},[142,198,200],{"id":199},"example","Example",[17,202,204],{"className":19,"code":203,"language":21,"meta":22,"style":22},"move: kernel(wgsl`\n  var s = stars[index];\n  s.vel += (pointer - s.pos) * dt;\n  s.pos += s.vel * dt;\n  stars[index] = s;\n`, {over: 'stars'}),\n",[24,205,206,225,230,235,240,246],{"__ignoreMap":22},[27,207,208,211,214,216,219,222],{"class":29,"line":30},[27,209,210],{"class":33},"move",[27,212,213],{"class":36},": ",[27,215,5],{"class":33},[27,217,218],{"class":36},"(",[27,220,221],{"class":33},"wgsl",[27,223,224],{"class":72},"`\n",[27,226,227],{"class":29,"line":40},[27,228,229],{"class":72},"  var s = stars[index];\n",[27,231,232],{"class":29,"line":53},[27,233,234],{"class":72},"  s.vel += (pointer - s.pos) * dt;\n",[27,236,237],{"class":29,"line":85},[27,238,239],{"class":72},"  s.pos += s.vel * dt;\n",[27,241,243],{"class":29,"line":242},5,[27,244,245],{"class":72},"  stars[index] = s;\n",[27,247,249,252,255,258],{"class":29,"line":248},6,[27,250,251],{"class":72},"`",[27,253,254],{"class":36},", {over: ",[27,256,257],{"class":72},"'stars'",[27,259,260],{"class":36},"}),\n",[262,263,264],"blockquote",{},[13,265,266,270],{},[267,268,269],"strong",{},"Tip."," A kernel has no return value: write your results into a buffer.",[142,272,274],{"id":273},"see-also","See also",[276,277,278,297,305],"ul",{},[279,280,281,288,289,292,293,296],"li",{},[282,283,285],"a",{"href":284},"\u002Fdocs\u002Fprimitives\u002Finputs-compute\u002Fbuffer",[24,286,287],{},"buffer"," — A storage buffer of ",[24,290,291],{},"count"," records of a ",[24,294,295],{},"struct"," type, zero-filled.",[279,298,299,304],{},[282,300,302],{"href":301},"\u002Fdocs\u002Fprimitives\u002Finputs-compute\u002Fstruct",[24,303,295],{}," — Declare a record type.",[279,306,307],{},[24,308,309],{},"simulate",[311,312,313],"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 .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}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);}",{"title":22,"searchDepth":40,"depth":40,"links":315},[316,317,318],{"id":144,"depth":40,"text":145},{"id":199,"depth":40,"text":200},{"id":273,"depth":40,"text":274},"inputs.compute","inputs-compute","Raw compute",false,null,"md","inputs","Inputs","function",{},true,"\u002Fdocs\u002Fprimitives\u002Finputs-compute\u002Fkernel",{"title":5,"description":15},"https:\u002F\u002Fgithub.com\u002Fshader-effects-inc\u002Fshaders\u002Fblob\u002Fmain\u002Fpackages\u002Fcore\u002Fsrc\u002Fstd\u002Finputs\u002Fcompute.ts#L186","docs\u002Fprimitives\u002F41.inputs-compute\u002F2.kernel","WjE2ww4RYxP4YZuYwK09V75zFwr6SgJtYkVK5EtI7eM",{"stars":336},6080,[338,342,346,350,354,358,362,366,370,374,378,382,386,390,394,398,402,407,411,415,419,423],{"path":339,"title":340,"description":341,"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":343,"title":344,"description":345,"category":24},"\u002Fdocs\u002Fguide\u002Fquickstart","Quickstart","Install Shaders, render your first effect, and drive a prop from state.",{"path":347,"title":348,"description":349,"category":24},"\u002Fdocs\u002Fguide\u002Fcomposing-effects","Composing effects","Stack components as layers and nest them to control which layers an effect touches.",{"path":351,"title":352,"description":353,"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":355,"title":356,"description":357,"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":359,"title":360,"description":361,"category":24},"\u002Fdocs\u002Fguide\u002Fanimation","Animating a shader","Tween a shader's props with Motion, GSAP or anything else that animates a number.",{"path":363,"title":364,"description":365,"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":367,"title":368,"description":369,"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":371,"title":372,"description":373,"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":375,"title":376,"description":377,"category":24},"\u002Fdocs\u002Fguide\u002Ftransforms","Transforms","Position, size, and rotate any layer inside the canvas with a bounding box, in any CSS unit.",{"path":379,"title":380,"description":381,"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":383,"title":384,"description":385,"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":387,"title":388,"description":389,"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":391,"title":392,"description":393,"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":395,"title":396,"description":397,"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":399,"title":400,"description":401,"category":24},"\u002Fdocs\u002Fguide\u002Ftelemetry","Telemetry","The `\u003CShader>` component occasionally sends an anonymous performance report to help us improve the engine over time.",{"path":403,"title":404,"description":405,"category":406},"\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":408,"title":409,"description":410,"category":406},"\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":412,"title":413,"description":414,"category":406},"\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":416,"title":417,"description":418,"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":420,"title":421,"description":422,"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":424,"title":425,"description":426,"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.",1796051186121,"06e02370-81a6-4d74-9931-661d71414be1"]