Working examples demonstrating different implementation approaches.
No server required! Just open HTML files directly in your browser:
# macOS
open demo-complete-bundle.html
# Linux
xdg-open demo-complete-bundle.html
# Windows
start demo-complete-bundle.htmlFile: demo-complete-bundle.html
Demonstrates the complete all-in-one bundle approach.
- ✅ Simplest implementation (2 script tags)
- ✅ All 3 shaders included
- ✅ Automatic shader switching on scroll
- ✅ Multiple presets showcased
Use this when: You want the easiest setup with all features.
File: demo-modular-single.html
Demonstrates loading a single shader with modular approach.
- ✅ Smallest file size (~13KB gzipped)
- ✅ Only GS2 shader loaded
- ✅ Multiple presets within one shader
- ✅ No ScrollShaderManager needed
Use this when: You only need one shader and want to optimize file size.
File: demo-modular-multi.html
Demonstrates loading multiple specific shaders modularly.
- ✅ Load only the shaders you need
- ✅ Automatic shader switching
- ✅ Only loads GS1 and GS3 (skips GS2)
- ✅ File size optimization
Use this when: You want shader switching but don't need all shaders.
Test files for each shader system:
test-gs1.html- Test GS1 (Topographic Flow)test-gs2.html- Test GS2 (Dynamic Warp)test-gs3.html- Test GS3 (Dot Field)
Use these for: Testing individual shaders during development.
File: config-form.html
Interactive configuration interface for testing shader parameters in real-time.
- ✅ Live parameter adjustment
- ✅ Preset testing
- ✅ Debug mode toggle
- ✅ Visual feedback
Use this for: Testing and fine-tuning shader configurations.
All examples follow this pattern:
<!DOCTYPE html>
<html>
<head>
<style>
/* Styles for canvas and content */
</style>
</head>
<body>
<canvas id="bg-canvas"></canvas>
<!-- Content sections -->
<section data-shader-system="gs1" data-bg-preset="HERO">
<h1>Content</h1>
</section>
<!-- Scripts -->
<script src="https://cdn.jsdelivr.net/npm/three@0.152.2/build/three.min.js"></script>
<script src="../dist/morphbg-all.complete.js"></script>
</body>
</html>All examples use a fixed-position canvas with id="bg-canvas":
#bg-canvas {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}Sections use data attributes to control the shader:
<section data-shader-system="gs2" data-bg-preset="ENERGETIC">data-shader-system- Which shader to use (gs1, gs2, gs3)data-bg-preset- Which preset to apply (HERO, AMBIENT, CALM, etc.)
Always load in this order:
- Three.js (required dependency)
- morphbg files (engine, shaders, manager)
Edit the data-bg-preset attribute:
<section data-shader-system="gs1" data-bg-preset="CALM">Available presets vary by shader (see shader documentation).
Edit the data-shader-system attribute:
<section data-shader-system="gs3" data-bg-preset="HERO">Just add more sections with appropriate attributes:
<section data-shader-system="gs2" data-bg-preset="AMBIENT">
<h2>New Section</h2>
<p>Content here</p>
</section>Add styles in the <head>:
section {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
color: white;
}- Check browser console for errors
- Ensure Three.js CDN is accessible
- Verify
dist/folder exists (runnode scripts/build.js)
- Check canvas element exists with
id="bg-canvas" - Verify z-index is negative
- Check console for WebGL errors
- Ensure sections have
data-shader-systemattributes - Verify ScrollShaderManager is loaded
- Check that multiple shaders are loaded
- Try the single shader approach
- Reduce number of sections
- Check browser GPU acceleration is enabled
- Read the API Reference
- Check the Wiki for full documentation
- See Contributing Guide to add your own examples