Summary
melonJS already has ShaderEffect and GLShader support on any Renderable, but using them requires writing raw GLSL from scratch. Adding a set of built-in, ready-to-use effect presets would dramatically lower the barrier for visual polish.
Proposed Built-in Effects
Hit / Status feedback
- FlashEffect — flash the sprite white (or any color) for hit feedback
- TintPulseEffect — pulse a color overlay (poison green, freeze blue, fire red)
- DesaturateEffect — partial or full grayscale (disabled state, death, petrify)
Visual emphasis
- OutlineEffect — solid color outline / glow around the sprite (selection, hover, collectibles)
- DropShadowEffect — offset shadow beneath the sprite
Transitions
- DissolveEffect — noise-based dissolve (death, spawn, teleport)
- PixelateEffect — progressive pixelation (teleport, transition, retro effect)
Stylistic
- ChromaticAberrationEffect — RGB channel offset (impact, glitch, damage)
- ScanlineEffect — horizontal scanlines overlay
API Sketch
import { FlashEffect, OutlineEffect } from "melonjs";
// one-liner usage
mySprite.shader = new FlashEffect(renderer);
// with options
mySprite.shader = new OutlineEffect(renderer, {
color: "#ff0",
width: 2.0
});
// animate via uniforms
const flash = new FlashEffect(renderer, { intensity: 0.0 });
mySprite.shader = flash;
flash.uniforms.intensity = 1.0; // trigger flash, tween back to 0
Implementation Notes
- Each preset is a subclass of
ShaderEffect with a sensible default fragment shader and exposed uniforms
- All effects should be parameterizable (color, intensity, speed, etc.)
- Effects that need the sprite's texture dimensions (outline, pixelate) can read from existing uniforms
- Canvas renderer fallback: effects are silently ignored (existing
ShaderEffect behavior)
- Effects should be lightweight — a developer should be able to apply/remove them at any time without allocation overhead
- Consider pooling for frequently toggled effects (e.g., flash on hit)
Priority
Start with the 3 most universally used: FlashEffect, OutlineEffect, DesaturateEffect. These alone would cover the majority of use cases.
Summary
melonJS already has
ShaderEffectandGLShadersupport on anyRenderable, but using them requires writing raw GLSL from scratch. Adding a set of built-in, ready-to-use effect presets would dramatically lower the barrier for visual polish.Proposed Built-in Effects
Hit / Status feedback
Visual emphasis
Transitions
Stylistic
API Sketch
Implementation Notes
ShaderEffectwith a sensible default fragment shader and exposed uniformsShaderEffectbehavior)Priority
Start with the 3 most universally used: FlashEffect, OutlineEffect, DesaturateEffect. These alone would cover the majority of use cases.