Repository navigation
Configuration
Complete reference for configuring morphbg shader backgrounds.
Every section must have these two attributes:
<section
data-shader-system="gs1|gs2|gs3" <!-- Which shader -->
data-shader-preset="HERO|AMBIENT|READ"> <!-- Motion level --><!-- Hero section: High motion, dramatic -->
<section data-shader-system="gs1" data-shader-preset="HERO">
<!-- Content section: Medium motion -->
<section data-shader-system="gs2" data-shader-preset="AMBIENT">
<!-- Reading section: Low motion -->
<section data-shader-system="gs3" data-shader-preset="READ">These work across all shader systems.
Required. Specifies which shader to use.
<section data-shader-system="gs1|gs2|gs3">Values:
-
gs1- Topographic Flow (organic patterns) -
gs2- Dynamic Warp (glitch aesthetic) -
gs3- Dot Field (Kusama-inspired)
See Shader Systems for details on each.
Required. Controls motion intensity preset.
<section data-shader-preset="HERO|AMBIENT|READ">Presets:
| Preset | Motion | Target FPS | Best For |
|---|---|---|---|
HERO |
High | 50-60 | Hero sections, above fold |
AMBIENT |
Medium | 55-60 | Feature sections, mid-page |
READ |
Low | 60 | Content sections, reading |
Under the hood: Presets control these uniforms:
-
u_spatialMotion- Spatial animation intensity -
u_temporalMotion- Temporal animation intensity -
u_cursorEnabled- Cursor interaction on/off -
u_calm- Overall calmness factor
Fine-tune calmness within a preset.
<section data-calm="0.5">- Range: 0.0-1.0
- Default: Preset-dependent
- 0.0: Maximum motion
- 1.0: Nearly static
Use case: Override preset defaults
<!-- HERO preset but calmer -->
<section data-shader-preset="HERO" data-calm="0.6">
<!-- AMBIENT but more energetic -->
<section data-shader-preset="AMBIENT" data-calm="0.2">Topographic Flow shader customization.
Visual mode for GS1.
<section data-shader-mode="atmospheric-mesh">Modes:
-
atmospheric-mesh- Atmospheric mesh patterns -
topographic-flow- Flowing topographic patterns -
fabric-warp- Woven fabric-like textures
Number of topographic contour lines.
<section data-topo-bands="20">- Range: 1-50
- Default: 20
- Low (5-10): Few bold lines
- High (30-50): Dense contours
Performance: Higher = more GPU work.
How much the pattern warps and flows.
<section data-warp-intensity="0.8">- Range: 0.0-2.0
- Default: 1.0
- Subtle (0.0-0.5): Gentle flow
- Dramatic (1.5-2.0): Strong distortion
Flattens topography (good for text sections).
<section data-read-topo-flatten="0.7">- Range: 0.0-1.0
- Default: 0.0
- 0.0: Full relief
- 1.0: Nearly flat
Adds brightness for better text legibility.
<section data-read-white-bias="0.3">- Range: 0.0-1.0
- Default: 0.0
- 0.0: Full color
- 1.0: Nearly white
<section
data-shader-system="gs1"
data-shader-preset="AMBIENT"
data-topo-bands="15"
data-warp-intensity="0.6"
data-read-topo-flatten="0.2"
data-read-white-bias="0.1">
<h2>Features</h2>
<p>Your content here...</p>
</section>Dynamic Warp shader customization.
Visual mode for GS2.
<section data-shader-mode="glitch-grid">Modes:
-
glitch-grid- Geometric grid disruption -
vector-glitch- Angular vector disruption -
signal-flow- Flowing data streams
Directional bias of glitch flow.
<section data-flow-dir="45deg">
<!-- Or radians -->
<section data-flow-dir="1.57">-
Format: Degrees with
degsuffix or radians - Range: 0-360deg / 0-6.28rad
-
Common:
-
0deg- Right → -
45deg- Diagonal ↗ -
90deg- Up ↑ -
180deg- Left ← -
270deg- Down ↓
-
Geometric fragmentation detail level.
<section data-grid-subdivision-depth="0.6">- Range: 0.0-1.0
- Default: 0.5
- Low (0.0-0.3): Large chunks
- High (0.8-1.0): Fine fragmentation
Performance: Higher = more work.
Animation speed (vector-glitch mode).
<section data-shard-speed="0.8">- Range: 0.0-2.0
- Default: 1.0
Reduces glitch intensity.
<section data-read-topo-flatten="0.5">- Range: 0.0-1.0
- Default: 0.0
Note: data-calm is the primary control for GS2.
Lightens technical color palette.
<section data-read-white-bias="0.2">- Range: 0.0-1.0
- Default: 0.0
<section
data-shader-system="gs2"
data-shader-preset="HERO"
data-shader-mode="vector-glitch"
data-flow-dir="45deg"
data-grid-subdivision-depth="0.7"
data-shard-speed="1.2"
data-read-white-bias="0.1">
<h1>Technical Hero</h1>
</section>Dot Field (Kusama) shader customization.
Visual mode for GS3.
<section data-shader-mode="perlin-dot-field">Modes:
-
perlin-dot-field- Large organic blobs (4x scale) -
kusama-infinite- Dense crisp circles -
octopus-legs- Curvy lanes with wave patterns
Six primary artistic controls:
Lane spacing and density.
<section data-kusama-k-grid="0.5">- Range: 0.0-1.0
- Default: 0.5
- Lower: More spacious
- Higher: Tighter packing
Random positional offset for organic feel.
<section data-kusama-k-jitter="0.35">- Range: 0.0-1.0
- Default: 0.35
- 0.0: Perfect grid
- 0.5: Hand-painted feel
- 1.0: Strong scatter
Base dot size.
<section data-kusama-k-size="0.55">- Range: 0.0-1.0
- Default: 0.55
Note: In perlin-dot-field mode, dots are 4x larger.
Animation/wobble intensity.
<section data-kusama-k-wobble="0.5">- Range: 0.0-1.0
- Default: 0.5
- 0.0: Static
- 1.0: Strong wobble
Performance: Higher = more GPU work.
Number of horizontal lanes.
<section data-kusama-k-lane-freq="0.5">- Range: 0.0-1.0
- Default: 0.5
- Lower: Fewer lanes
- Higher: More lanes
Cursor interaction strength.
<section data-kusama-k-cursor="0.5">- Range: 0.0-1.0
- Default: 0.5 (HERO), 0.0 (READ)
- 0.0: No interaction
- 1.0: Strong repulsion
Additional parameters for octopus-legs mode:
Curve amplitude (how much lanes bend).
<section data-kusama-k-curve-amp="0.5">- Range: 0.0-1.0
- Default: 0.5
- 0.0: Straight lanes
- 1.0: Maximum curve
Variation between adjacent lanes.
<section data-kusama-k-curve-variety="0.5">- Range: 0.0-1.0
- Default: 0.5
- 0.0: Uniform curves
- 1.0: Maximum variety
<section
data-shader-system="gs3"
data-shader-preset="HERO"
data-shader-mode="perlin-dot-field"
data-kusama-k-grid="0.6"
data-kusama-k-jitter="0.4"
data-kusama-k-size="0.65"
data-kusama-k-wobble="0.7"
data-kusama-k-lane-freq="0.5"
data-kusama-k-cursor="0.8">
<h1>Kusama Hero</h1>
</section>By default, morphbg looks for #bg-canvas. To use a different ID:
<canvas id="my-custom-canvas"></canvas>
<script src="https://cdn.jsdelivr.net/npm/three@0.152.2/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/cael-prussian/morphbg@1.0.0/src/engine.js"></script>
<script src="https://cdn.jsdelivr.net/gh/cael-prussian/morphbg@1.0.0/src/scroll-manager.js"></script>
<!-- Load shader files... -->
<script>
// Manual initialization with custom canvas
ScrollShaderManager.init('my-custom-canvas');
</script>Enable debug mode for development:
window.__INSTANCE__ = window.initBGShaderSystem({
canvasId: 'bg-canvas',
fragmentShader: window.BG_FRAGMENT_SHADER,
config: window.BG_SHADER_CONFIG,
adapter: window.BG_TopoReadAdapter,
debug: true // Enables FPS counter and console logging
});See Troubleshooting#Debug Mode for details.
Programmatically switch shaders:
// Switch to GS2
window.ScrollShaderManager.switchTo('gs2');
// Get current shader
const current = window.ScrollShaderManager.getCurrentShader();
console.log(current); // 'gs1', 'gs2', or 'gs3'Adjust parameters based on viewport:
// Detect mobile
const isMobile = /iPhone|iPad|Android/i.test(navigator.userAgent);
// Update sections for mobile
if (isMobile) {
document.querySelectorAll('section').forEach(section => {
// Use READ preset on mobile
section.setAttribute('data-shader-preset', 'READ');
// Reduce parameters for better performance
if (section.dataset.shaderSystem === 'gs1') {
section.setAttribute('data-topo-bands', '10');
}
if (section.dataset.shaderSystem === 'gs3') {
section.setAttribute('data-kusama-k-wobble', '0.3');
}
});
}// Check user's motion preference
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
// Force READ preset globally
document.querySelectorAll('section[data-shader-preset]').forEach(section => {
section.setAttribute('data-shader-preset', 'READ');
section.setAttribute('data-calm', '0.9');
});
}Begin with just required attributes:
<section data-shader-system="gs1" data-shader-preset="HERO">Add optional parameters only if needed.
Presets are tuned for good performance and aesthetics:
-
HEROfor hero sections -
AMBIENTfor content -
READfor reading
Enable debug mode and check FPS:
- Target 50-60 FPS for smooth experience
- Use READ preset if FPS drops below 40
- Reduce complexity parameters on lower-end devices
Mobile devices need lighter configuration:
<!-- Desktop: High motion -->
<section
data-shader-system="gs1"
data-shader-preset="HERO"
data-topo-bands="25">
<!-- Consider mobile overrides via JavaScript -->Respect user preferences:
// Reduced motion
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
// Use minimal motion
}
// Contrast preference
if (window.matchMedia('(prefers-contrast: high)').matches) {
// Increase read-white-bias
}When multiple sources define parameters:
-
Section
data-attributes (highest priority) - Preset defaults
- Shader defaults (lowest priority)
Example:
<!-- READ preset sets calm=0.75 -->
<!-- But section overrides to calm=0.3 -->
<section
data-shader-preset="READ"
data-calm="0.3">
<!-- Result: calm=0.3 is used -->- See Shader Systems for detailed parameter descriptions
- See Troubleshooting for performance optimization
- See Installation for setup instructions
- See Bundle Options for deployment approaches