the current renderer instance
Optionaloptions: { color?: number[]; intensity?: number; speed?: number } = {}effect options
Optionalcolor?: number[]pulse color as [r, g, b] (0.0–1.0)
Optionalintensity?: numbermaximum tint strength (0.0–1.0)
Optionalspeed?: numberpulse speed (oscillations per second)
Readonlydestroyedtrue once destroy has been called. Distinct from
enabled — which also toggles transiently across a context
lost / restored cycle — to give callers a stable signal for
"this effect has been explicitly released."
whether this effect is active (false in Canvas mode, false after
destroy, and false while the WebGL context is suspended
between an ONCONTEXT_LOST and the matching ONCONTEXT_RESTORED
event).
When true, a renderable will NOT auto-destroy this effect when it is
removed from its postEffects (via the shader setter,
Renderable#removePostEffect, Renderable#clearPostEffects)
or when the renderable itself is destroyed. Set this on an effect shared
across several renderables so one of them going away doesn't free the GL
program still used by the others — you then own its lifecycle and call
destroy yourself.
Create an independent copy of this effect, compiled as its own GL program. Use it when several renderables need the same effect with different uniform values — a single instance has a single set of uniforms, shared by everything it is assigned to.
The clone copies the recipe: the fragment source, float precision,
every uniform value set so far, and any extra textures bound via
setTexture (the clone uploads and owns its own GL copies).
It does NOT copy ownership or lifecycle state — in particular the
clone's shared flag is always reset to false, even when
cloning a shared shader (such as one returned by loader.getShader()):
the clone is caller-owned and will be auto-destroyed by the renderable
it is assigned to, exactly like a hand-constructed effect. Set
shared = true on the clone yourself if you intend to reuse it across
several renderables.
a new, caller-owned effect (shared === false)
destroy this shader effect. Idempotent — calling destroy twice is safe. Unsubscribes from the renderer's context-lost / restored events so a destroyed effect is not auto-reactivated.
set the pulse color
pulse color as [r, g, b] (0.0–1.0)
Bind an extra texture to a named sampler2D uniform in this shader, so
a custom effect can read a second texture — a noise map, mask, gradient,
flow/lookup table — besides the sprite/target it post-processes (uSampler).
The engine uploads, caches, and re-binds it to a reserved texture unit each
time the effect draws, and points the sampler uniform at it — no raw WebGL
texture-unit juggling.
Declare the sampler in your fragment (uniform sampler2D <name>;) and pass
that name here. Any engine texture works — e.g. noiseTexture.getTexture().
No-op in Canvas mode.
the sampler2D uniform name declared in the fragment
the texture source
Optionalrepeat: "repeat" | "no-repeat" | "repeat-x" | "repeat-y" = "no-repeat"wrap mode; use "repeat" for a tiled/scrolled texture (power-of-two size under WebGL 1)
this effect for chaining
// "water": distort the sprite by a static noise texture scrolled over time
const noise = new me.NoiseTexture2d({ width: 256, height: 256, seamless: true });
const water = new me.ShaderEffect(renderer, `
uniform sampler2D uNoise;
uniform float uTime;
vec4 apply(vec4 color, vec2 uv) {
vec2 flow = texture2D(uNoise, uv + uTime * 0.03).rg - 0.5;
return texture2D(uSampler, uv + flow * 0.02);
}`);
water.setTexture("uNoise", noise.getTexture(), "repeat");
waterSprite.shader = water;
// each frame, in your Stage's update(dt):
water.setTime(me.timer.getTime() / 1000);
set the current time (call each frame for animation)
time in seconds
Set the uniform to the given value
the uniform name
the value to assign to that uniform
A shader effect that pulses a color overlay on the sprite. Commonly used for status effects — poison green, freeze blue, fire red. The
timeuniform should be updated each frame for the pulse animation.See
Renderable.shader for usage
Example