name of the shader asset (as specified in the preload list)
the shared, precompiled shader, or null if not found
me.loader.preload([
// from a file (or data: URI)
{ name: "waterRipple", type: "shader", src: "shaders/waterRipple.frag" },
// or inline GLSL via the `data` field
{ name: "flash", type: "shader", data: `
uniform float uIntensity;
vec4 apply(vec4 color, vec2 uv) { return mix(color, vec4(1.0), uIntensity); }
` },
// or a complete program — a {vertex, fragment} GLSL pair and/or a
// full WGSL module → one GLShader carrying both realizations; the
// active renderer hosts the one it speaks
{ name: "toonMesh", type: "shader", src: {
vertex: "shaders/toon.vert",
fragment: "shaders/toon.frag",
wgsl: "shaders/toon.wgsl",
} },
], () => {
// one shared program — same uniform state for every user
mySprite.shader = me.loader.getShader("waterRipple");
// private copy with its own uniforms (caller-owned, shared = false)
boss.shader = me.loader.getShader("flash").clone();
// a complete program hosts on a mesh, replacing the built-in shading
myMesh.shader = me.loader.getShader("toonMesh");
});
Return the precompiled
ShaderEffectfor the given "shader" asset — compiled once during preloading, ready to assign to a renderable or camerashaderproperty.This returns a SHARED instance: the same
ShaderEffectobject on every call, owned by the loader (itssharedflag istrue). That means:setUniformon it affects every renderable using the shader.When a renderable needs its own uniform values, make a private, caller-owned copy with
ShaderEffect.clone()— the clone'ssharedflag is reset tofalse, so it is auto-destroyed with the renderable it is assigned to, like any hand-constructed effect.A shader asset declared as a complete program — a
{vertex, fragment}GLSL pair and/or a fullwgslmodule (see the example) — compiles into a raw GLShader instead, carrying one realization per GPU backend (isWebGL/isWebGPU): the type the hosted paths take directly (aMeshcustom shader,renderer.customShader, a custom batcher). Same shared-instance semantics, andGLShader.clone()likewise yields a caller-owned copy.Degradation is never fatal: a fragment-body asset without a body in the active renderer's language (or on Canvas) is an inert
ShaderEffectstub, and a complete-program asset without a realization for the active backend is an inertGLShader— assigning either just keeps the built-in rendering. Note that shader assets require an initialized Application (await app.init()) — an inherent precondition of the preload flow, since the loading screen itself needs the renderer.