Blend modes control how each pixel you draw combines with pixels already in the framebuffer. By changing the WebGL blend equation you can create additive glow, darkening shadows, soft light, and alpha-erasure effects without any special shader code.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Nightre/Rapid.js/llms.txt
Use this file to discover all available pages before exploring further.
Available Blend Modes
TheBlendMode enum provides five modes:
| Enum value | Effect | Typical use case |
|---|---|---|
BlendMode.NORMAL | Standard alpha blending (default) | General-purpose sprite rendering |
BlendMode.ADD | Adds source RGB to destination RGB | Glow, fire, laser beams, magic effects |
BlendMode.MULTIPLY | Multiplies source RGB with destination | Shadows, darkening overlays, tinted glass |
BlendMode.SCREEN | Inverse multiply — lightens without over-saturating | Fog, volumetric light, soft halos |
BlendMode.ERASE | Subtracts source alpha from destination alpha | Cutting transparent holes into render textures |
withBlendMode (Recommended)
withBlendMode sets the desired mode, executes a callback, then automatically restores BlendMode.NORMAL — even if the callback throws. This is the safest way to use blend modes because you cannot accidentally leave the renderer in a non-standard state.
Manual setBlendMode
When you need to span blend modes across multiple code paths, usesetBlendMode directly and restore the mode manually when done:
setBlendMode calls rapid.flush() internally before changing the WebGL blend function. This ensures that any draw calls already batched under the previous mode are dispatched before the new mode takes effect. There is never a risk of mixing modes within a single draw batch.Practical Examples
Additive Glow (BlendMode.ADD)
Additive blending accumulates light: drawing the same sprite multiple times makes it brighter, and dark areas of the sprite texture become transparent. Ideal for particles, explosions, and neon effects.Shadow Overlay (BlendMode.MULTIPLY)
Multiply blending darkens the scene: pure white in the source has no effect, pure black makes the destination black, and mid-tones tint the existing pixels. Good for coloured shadows and tinted lens overlays.Soft Light Bloom (BlendMode.SCREEN)
Screen blending brightens without the hard clipping of additive blending. It can never exceed white, so it produces a more natural glow suitable for atmospheric fog or bloom passes.Erasing into a RenderTexture (BlendMode.ERASE)
ERASE subtracts the source alpha from the destination alpha. This is only meaningful when rendering into a RenderTexture (offscreen framebuffer) because the main canvas composites onto the browser page. Use it to punch transparent holes into a pre-rendered texture — for example, a spotlight mask or a fog-of-war reveal.