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.
CustomGlShader lets you inject GLSL code into the engine’s built-in sprite or graphic rendering pipeline without replacing the entire shader program. Rather than writing a standalone shader from scratch, you provide small hook functions that are spliced into the base shader at well-defined injection points. Rapid compiles the combined source once per region and caches the result.
Creating a CustomGlShader
The
vertex and fragment function signatures must match exactly. The vertex hook receives vec4 position (the transformed vertex position) and vec2 vRegion (the UV region coordinates). The fragment hook receives inout vec4 fragColor (the sampled and tinted color). If you do not need to modify a stage, pass an empty body: void vertex(vec4 position, vec2 vRegion) {}.Using a Shader on a Draw Call
Pass anyCustomGlShader to the shader property of a draw options object:
Setting Uniforms
UsesetUniforms to pass data from JavaScript into your GLSL code:
UniformValue covers all standard GLSL types:
| JavaScript value | GLSL type inferred |
|---|---|
number | float, int, bool, sampler2D |
[n, n] | vec2 / ivec2 |
[n, n, n] | vec3 / ivec3 |
[n, n, n, n] | vec4 / ivec4 |
Float32Array (4 elements) | vec4 |
Float32Array (9 elements) | mat3 |
Float32Array (16 elements) | mat4 |
gl.uniform* call automatically, so you do not need to specify types manually.
Shader Padding
Some effects — outlines, glow, drop shadows — bleed beyond the original sprite boundaries.setPadding expands the rendered quad by the specified number of pixels on each side, giving the fragment shader space to work with:
setPadding returns this for chaining and propagates the value to all already-compiled GLShader instances. When used inside applyFilters, the padding is automatically reflected in the filter render-texture size and output alignment.
Filter Chains with applyFilters
You can compose multiple shaders into a sequential post-process pipeline usingrapid.applyFilters. Each shader in the array receives the output of the previous pass as its input texture:
RenderTexture objects so no new GPU resources are allocated on repeated calls.
Sampling Helpers Available in the Fragment Hook
The built-in fragment shader exposes several helpers yourfragment function can call:
| Function | Description |
|---|---|
sampleTexture(vec2 uv) | Sample at a global UV coordinate. |
sampleClampTexture(vec2 uv) | Sample at a global UV, returning transparent black outside the sprite region. |
sampleTextureLocal(vec2 uv) | Sample using 0–1 local UV coordinates relative to the sprite region. Returns transparent black outside bounds. |