Repository navigation
Effects: place a pattern on the renderable drawn - #1789
Merged
Merged
Conversation
The built-in effects that place a pattern placed it by `uv`, the coordinate they sample their texture at. That runs 0..1 across the renderable only for a sprite with a texture of its own drawn with that one effect: - on a sprite cut from an atlas, SwayEffect and an anchored WaveEffect rocked the sprite's roots (the anchor was a row of the atlas), and VignetteEffect, RadialGradientEffect and ScanlineEffect's curvature landed on the atlas, not the sprite; - with two or more effects, the chain runs over a canvas-sized capture, so every pattern, noise_uv included, sat on the canvas and slid with the camera, upside down on WebGL. Effects now read where they are on the renderable (effects/local_space.js, internal): ME_local runs 0..1 across the renderable following its art (flip and rotation included), ME_art is the coordinate its texture has there, and helpers turn a displacement in either into one of `uv`. The renderer works the space out at the end of Renderable#preDraw, from the transform that draws the renderable: a renderable drawn with its one effect hands it to the effect for its draws (from each vertex's position, so a renderable drawn in several quads is one space), and one with a chain hands it to the blits of the chain, where noise_uv is the renderable's too. Every other path keeps the space `uv` always was: a camera's effects, drawLight, meshes (spliced with a fallback), layers. What is measured in the texture stays measured in it, so values tuned on an atlas sprite look the same: WaveEffect's amplitude and frequency, ShineEffect's sweep, bands and width, DissolveEffect's grain, the lines of HologramEffect and ScanlineEffect. SwayEffect, new in 20.11, measures everything across the sprite. Camera effects draw exactly as before (pinned against the previous Scanline and Shine bodies). Sprites sharing one of these effects now draw one by one, each told where it is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SeWCkETjW35ZbXDRswV1hx
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SeWCkETjW35ZbXDRswV1hx
5 of 10 tasks
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.
Description
Fixes #1407. The built-in effects that place a pattern placed it by
uv, the coordinate they sample their texture at, which runs 0..1 across the renderable only for a sprite with a texture of its own drawn with that one effect:SwayEffectand an anchoredWaveEffectmoved the sprite's roots (the anchor was a row of the atlas), andVignetteEffect,RadialGradientEffectandScanlineEffect's curvature landed on the atlas rather than the sprite.noise_uvincluded, sat on the canvas and slid with the camera, and ran upside down on WebGL.How
A new internal module,
effects/local_space.js, gives effect bodies where they are on the renderable:ME_local: 0..1 across the renderable, following its art (mirrored with a flip, turned with a rotation).ME_art: the coordinate its texture has there, for what is measured in the texture.ME_localToUV,ME_artToUV,ME_localToArt: turn a displacement in one into the others, to move where a body samples.The renderer works the space out at the end of
Renderable#preDraw, from the transform that draws the renderable (Renderer#_setEffectSpace):_beginChainSpace). Therenoise_uvis the renderable's too, and is no longer the canvas's.uvalways was (mode 0, the default): a camera's effects,drawLight, layers, and meshes (the mesh splice gives such a bodyuv, so meshes host exactly what they hosted before).Nothing here is public API: no new option, method or documented shader input.
Backward compatibility
WaveEffect's amplitude and frequency,ShineEffect's sweep, bands and width,DissolveEffect's grain, the lines ofHologramEffectandScanlineEffect. With other effects after them, they now stay on the sprite.SwayEffect, new in 20.11, measures everything across the sprite (strength, bend, anchor), as agreed.Docs
JSDoc of Sway, Wave, Shine and RadialGradient (its atlas caveat is gone), the
noise_uvdocs, themelonjs-effects-and-shadersskill, and the CHANGELOG (20.12.0, Fixed).Type of change
Checklist
pnpm lintpasses): eslint and biome on the changed files,tscclean for melonjspnpm testpasses)pnpm build)Tests: new
tests/effect-local-space.spec.js(55 tests). It compares pixels on WebGL, and every picture must be at least 15% lit, so two blank draws can never match.noise_uvbody.uv; a single effect is put back after its renderable draws; a camera's chain gets no space.uv.Nineteen mutants of the fix (each part reverted in turn) each fail at least one test.
Also checked:
webgl_review_fixes.spec.jsnow checks that Shine reads the direction through the space (its ownuUVYDiruniform is gone), andwebgpu_post_effect_flow.spec.js's bare renderer gets the two new fields.tests/webgpu_effects_validate.spec.js, run headed with WebGPU enabled, compiles every built-in effect's WGSL with no errors.Related issues
Closes #1407
🤖 Generated with Claude Code
https://claude.ai/code/session_01SeWCkETjW35ZbXDRswV1hx