[{"data":1,"prerenderedAt":446,"buildId":447},["ShallowReactive",2],{"doc-\u002Fdocs\u002Fprimitives\u002Fmaterials\u002Fspectralsum":3,"github-stars":354,"guide-nav":356},{"id":4,"title":5,"body":6,"categoryId":92,"categorySlug":92,"categoryTitle":340,"curated":341,"description":16,"editUrl":342,"extension":343,"group":344,"groupTitle":345,"kind":346,"meta":347,"navigation":348,"path":349,"seo":350,"sourceUrl":351,"stem":352,"wordCount":342,"__hash__":353},"primitives\u002Fdocs\u002Fprimitives\u002F14.materials\u002F60.spectralsum.md","spectralSum",{"type":7,"value":8,"toc":334},"minimark",[9,13,17,87,102,125,130,181,185,275,288,292,320,324,330],[10,11,5],"h1",{"id":12},"spectralsum",[14,15,16],"p",{},"Light seen across the whole visible spectrum, added up slice by slice into one rgb colour.",[18,19,24],"pre",{"className":20,"code":21,"language":22,"meta":23,"style":23},"language-ts shiki shiki-themes github-dark","spectralSum(\n  opts: {samples: number; jitter: Expr; deps?: Expr[]; hint?: string},\n  body: (band: SpectralBand) =,\n> Expr): Expr\n","ts","",[25,26,27,39,57,76],"code",{"__ignoreMap":23},[28,29,32,35],"span",{"class":30,"line":31},"line",1,[28,33,5],{"class":34},"svObZ",[28,36,38],{"class":37},"s95oV","(\n",[28,40,42,45,49,52,54],{"class":30,"line":41},2,[28,43,44],{"class":37},"  opts: {samples: number; jitter: Expr; deps",[28,46,48],{"class":47},"snl16","?:",[28,50,51],{"class":37}," Expr[]; hint",[28,53,48],{"class":47},[28,55,56],{"class":37}," string},\n",[28,58,60,63,67,70,73],{"class":30,"line":59},3,[28,61,62],{"class":37},"  body: (",[28,64,66],{"class":65},"s9osk","band",[28,68,69],{"class":47},":",[28,71,72],{"class":34}," SpectralBand",[28,74,75],{"class":37},") =,\n",[28,77,79,82,84],{"class":30,"line":78},4,[28,80,81],{"class":37},"> Expr)",[28,83,69],{"class":47},[28,85,86],{"class":34}," Expr\n",[14,88,89,90,93,94,97,98,101],{},"Import ",[25,91,92],{},"materials"," from ",[25,95,96],{},"shaders\u002Fstd"," and use ",[25,99,100],{},"materials.spectralSum",".",[14,103,104,105,108,109,112,113,116,117,120,121,124],{},"The word behind dispersion: anything that bends each colour by a different amount (glass, water, a diamond) traces each slice separately and lets this word mix them back into colour. ",[25,106,107],{},"body(band)"," returns the rgb light seen at that slice; give it a slice-dependent index of refraction and white edges fan into spectra. ",[25,110,111],{},"samples"," is how many slices (8 is smooth, 4 is cheap, 2 the fewest that reach every colour; fixed when the shader compiles). ",[25,114,115],{},"jitter"," is a 0–1 per-pixel offset (",[25,118,119],{},"interleavedNoise",") that turns banding between slices into fine grain; pass a constant 0.5 where neighbours must agree. Anything the body reads from outside goes in ",[25,122,123],{},"deps",". One real GPU loop.",[126,127,129],"h2",{"id":128},"parameters","Parameters",[131,132,133,149],"table",{},[134,135,136],"thead",{},[137,138,139,143,146],"tr",{},[140,141,142],"th",{},"Name",[140,144,145],{},"Type",[140,147,148],{},"Notes",[150,151,152,167],"tbody",{},[137,153,154,160,165],{},[155,156,157],"td",{},[25,158,159],{},"opts",[155,161,162],{},[25,163,164],{},"{samples: number; jitter: Expr; deps?: Expr[]; hint?: string}",[155,166],{},[137,168,169,174,179],{},[155,170,171],{},[25,172,173],{},"body",[155,175,176],{},[25,177,178],{},"(band: SpectralBand) => Expr",[155,180],{},[126,182,184],{"id":183},"example","Example",[18,186,188],{"className":20,"code":187,"language":22,"meta":23,"style":23},"const rgb = spectralSum({samples: 8, jitter, deps: [n]}, (band) => {\n  const ior = add(u.refraction, mul(sub(band.t, 0.5), spread))\n  return backdropThrough(ior)\n})\n",[25,189,190,225,259,270],{"__ignoreMap":23},[28,191,192,195,199,202,205,208,211,214,216,219,222],{"class":30,"line":31},[28,193,194],{"class":47},"const",[28,196,198],{"class":197},"sDLfK"," rgb",[28,200,201],{"class":47}," =",[28,203,204],{"class":34}," spectralSum",[28,206,207],{"class":37},"({samples: ",[28,209,210],{"class":197},"8",[28,212,213],{"class":37},", jitter, deps: [n]}, (",[28,215,66],{"class":65},[28,217,218],{"class":37},") ",[28,220,221],{"class":47},"=>",[28,223,224],{"class":37}," {\n",[28,226,227,230,233,235,238,241,244,247,250,253,256],{"class":30,"line":41},[28,228,229],{"class":47},"  const",[28,231,232],{"class":197}," ior",[28,234,201],{"class":47},[28,236,237],{"class":34}," add",[28,239,240],{"class":37},"(u.refraction, ",[28,242,243],{"class":34},"mul",[28,245,246],{"class":37},"(",[28,248,249],{"class":34},"sub",[28,251,252],{"class":37},"(band.t, ",[28,254,255],{"class":197},"0.5",[28,257,258],{"class":37},"), spread))\n",[28,260,261,264,267],{"class":30,"line":59},[28,262,263],{"class":47},"  return",[28,265,266],{"class":34}," backdropThrough",[28,268,269],{"class":37},"(ior)\n",[28,271,272],{"class":30,"line":78},[28,273,274],{"class":37},"})\n",[276,277,278],"blockquote",{},[14,279,280,284,285,287],{},[281,282,283],"strong",{},"Tip."," The cost is ",[25,286,111],{}," times the body. Keep texture taps in the body to one or two.",[126,289,291],{"id":290},"see-also","See also",[293,294,295,306,315],"ul",{},[296,297,298,305],"li",{},[299,300,302],"a",{"href":301},"\u002Fdocs\u002Fprimitives\u002Fmaterials\u002Fspectralweight",[25,303,304],{},"spectralWeight"," — The colour one slice of the visible spectrum adds to white light, as linear rgb weights.",[296,307,308,314],{},[299,309,311],{"href":310},"\u002Fdocs\u002Fprimitives\u002Fmaterials\u002Fthroughslab",[25,312,313],{},"throughSlab"," — Follow one ray through a transparent body: in through the front face, out through the back.",[296,316,317],{},[25,318,319],{},"sampleSum",[126,321,323],{"id":322},"used-by","Used by",[14,325,326],{},[299,327,329],{"href":328},"\u002Fdocs\u002Fcomponents\u002Fprismaticglass","PrismaticGlass",[331,332,333],"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 .s9osk, html code.shiki .s9osk{--shiki-default:#FFAB70}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}",{"title":23,"searchDepth":41,"depth":41,"links":335},[336,337,338,339],{"id":128,"depth":41,"text":129},{"id":183,"depth":41,"text":184},{"id":290,"depth":41,"text":291},{"id":322,"depth":41,"text":323},"Materials & surfaces",false,null,"md","light","Noise, light & materials","function",{},true,"\u002Fdocs\u002Fprimitives\u002Fmaterials\u002Fspectralsum",{"title":5,"description":16},"https:\u002F\u002Fgithub.com\u002Fshader-effects-inc\u002Fshaders\u002Fblob\u002Fmain\u002Fpackages\u002Fcore\u002Fsrc\u002Fstd\u002Fpaint\u002Fmaterials.ts#L1375","docs\u002Fprimitives\u002F14.materials\u002F60.spectralsum","21krr3ZVazkhWLvHFCSDTlrMbINqaU1BDoohibIltQ8",{"stars":355},6080,[357,361,365,369,373,377,381,385,389,393,397,401,405,409,413,417,421,426,430,434,438,442],{"path":358,"title":359,"description":360,"category":25},"\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":362,"title":363,"description":364,"category":25},"\u002Fdocs\u002Fguide\u002Fquickstart","Quickstart","Install Shaders, render your first effect, and drive a prop from state.",{"path":366,"title":367,"description":368,"category":25},"\u002Fdocs\u002Fguide\u002Fcomposing-effects","Composing effects","Stack components as layers and nest them to control which layers an effect touches.",{"path":370,"title":371,"description":372,"category":25},"\u002Fdocs\u002Fguide\u002Fblending-masking","Blending and masking","Control how a layer mixes with the layers below it, and reveal one layer through another.",{"path":374,"title":375,"description":376,"category":25},"\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":378,"title":379,"description":380,"category":25},"\u002Fdocs\u002Fguide\u002Fanimation","Animating a shader","Tween a shader's props with Motion, GSAP or anything else that animates a number.",{"path":382,"title":383,"description":384,"category":25},"\u002Fdocs\u002Fguide\u002Fdynamic-props","Dynamic props","Drive any numeric or position prop from time, the cursor, or another layer, without writing animation code.",{"path":386,"title":387,"description":388,"category":25},"\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":390,"title":391,"description":392,"category":25},"\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":394,"title":395,"description":396,"category":25},"\u002Fdocs\u002Fguide\u002Ftransforms","Transforms","Position, size, and rotate any layer inside the canvas with a bounding box, in any CSS unit.",{"path":398,"title":399,"description":400,"category":25},"\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":402,"title":403,"description":404,"category":25},"\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":406,"title":407,"description":408,"category":25},"\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":410,"title":411,"description":412,"category":25},"\u002Fdocs\u002Fguide\u002Fperformance","Performance","Learn what makes an effect expensive on the GPU and how to keep it inside the frame budget.",{"path":414,"title":415,"description":416,"category":25},"\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":418,"title":419,"description":420,"category":25},"\u002Fdocs\u002Fguide\u002Ftelemetry","Telemetry","The `\u003CShader>` component occasionally sends an anonymous performance report to help us improve the engine over time.",{"path":422,"title":423,"description":424,"category":425},"\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":427,"title":428,"description":429,"category":425},"\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":431,"title":432,"description":433,"category":425},"\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":435,"title":436,"description":437,"category":25},"\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":439,"title":440,"description":441,"category":25},"\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":443,"title":444,"description":445,"category":25},"\u002Fdocs\u002Fguide\u002Fssr","Server rendering","Render Shaders in Next.js, Nuxt, SvelteKit, SolidStart and other SSR apps by keeping each shader on the client.",1796051178781,"06e02370-81a6-4d74-9931-661d71414be1"]