feat(shaders): add simple single-pass Blur shader#40
Merged
Conversation
Adds a Blur shader for both WebGL and Canvas2D backends, intended primarily for nodes with an Image Texture. WebGL uses a 9-tap Gaussian-approximation kernel in a single fragment pass (no render target, no second pass) to keep it cheap on constrained devices. Canvas2D delegates to the native `ctx.filter = 'blur(Npx)'`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
eaa8c2b to
7f9447e
Compare
Without registration, `renderer.createShader('Blur', ...)` falls back to
the default shader, so the shader-blur example rendered all four nodes
identically without any blur applied.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Blurshader for both WebGL and Canvas2D backends, intended primarily for nodes with an Image Texture.ctx.filter = 'blur(Npx)'and relies onsaveAndRestore: trueso the renderer cleans up filter state automatically.amountprop (node-space pixels, default 4).Files
src/core/shaders/templates/BlurTemplate.ts— props + defaultsrc/core/shaders/webgl/Blur.ts— WebGL fragment shadersrc/core/shaders/canvas/Blur.ts— Canvas2D filter-based shaderexports/{webgl,canvas}-shaders.ts— public re-exportsexamples/tests/shader-blur.ts— visual regression example at amounts[0, 2, 6, 12]src/core/shaders/templates/BlurTemplate.test.ts— unit testsTradeoffs
amountvalues (>~8) lose smoothness because there are only 9 fixed taps. For heavier blur, a separable two-pass via RenderTexture would be needed — intentionally out of scope here per "simple/performant."ctx.filter(Chrome 53+). Browsers below the floor will silently no-op rather than emulate in JS.Test plan
pnpm build— cleanpnpm test(BlurTemplate) — passingpnpm test:visual:updatethen review snapshot forshader-blurbefore mergingpnpm start🤖 Generated with Claude Code