Repository navigation
Troubleshooting
Common issues and solutions for morphbg shader system.
- Shader Rendering Issues
- Performance Problems
- Shader Switching Problems
- Debug Mode
- Browser Compatibility
- Getting Help
Symptoms: Canvas is black or empty, no WebGL rendering
Possible Causes & Solutions:
// Test WebGL support
function hasWebGL() {
try {
const canvas = document.createElement('canvas');
return !!(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
} catch (e) {
return false;
}
}
if (!hasWebGL()) {
console.error('WebGL not supported');
}Solutions:
- Visit get.webgl.org to check support
- Enable hardware acceleration in browser settings
- Update graphics drivers
- Try a different browser
<!-- Verify this element exists -->
<canvas id="bg-canvas"></canvas>Test:
const canvas = document.getElementById('bg-canvas');
console.log(canvas); // Should not be nullCorrect order:
<!-- 1. Three.js first -->
<script src="https://cdn.jsdelivr.net/npm/three@0.152.2/build/three.min.js"></script>
<!-- 2. morphbg bundle -->
<script src="https://cdn.jsdelivr.net/gh/cael-prussian/morphbg@1.0.0/dist/morphbg-all.complete.js"></script><!-- Sections must have these attributes -->
<section data-shader-system="gs1" data-shader-preset="HERO">
<!-- Content -->
</section>Check browser console (F12) for errors like:
Failed to compile shaderWebGL: INVALID_OPERATIONGLSL syntax error
Symptoms: Visual glitches, flashing, or tearing during transitions
Solutions:
For modular loading (manual init), you can adjust fade duration:
// In your initialization code
window.ScrollShaderManager.FADE_DURATION = 800; // Increase from default 600msEnsure sections don't conflict:
<!-- ❌ Bad: overlapping heights -->
<section style="height: 150vh" data-shader-system="gs1">...</section>
<section style="margin-top: -50vh" data-shader-system="gs2">...</section>
<!-- ✅ Good: clear boundaries -->
<section style="min-height: 100vh" data-shader-system="gs1">...</section>
<section style="min-height: 100vh" data-shader-system="gs2">...</section>body {
overscroll-behavior: none;
-webkit-overflow-scrolling: touch;
}Symptoms: Data attributes don't affect shader appearance
Diagnostic Steps:
- Verify attributes are set correctly:
const section = document.querySelector('section');
console.log(section.dataset); // Check all data- attributes- Check attribute names match shader expectations:
<!-- GS1 example -->
<section
data-shader-system="gs1"
data-shader-preset="HERO"
data-topo-bands="20"
data-warp-intensity="0.8">- Enable debug mode to see parameter values (see Debug Mode below)
Diagnostic:
Enable Debug Mode to see current FPS.
Solutions by Shader:
Reduce complexity:
<section
data-shader-system="gs1"
data-shader-preset="READ" <!-- Use READ instead of HERO -->
data-topo-bands="10" <!-- Fewer bands (try 10-15 instead of 30+) -->
data-warp-intensity="0.3"> <!-- Lower warp (try 0.3 instead of 1.0) -->Optimize parameters:
<section
data-shader-system="gs2"
data-shader-preset="READ" <!-- Use READ preset -->
data-calm="0.8" <!-- Higher calm value -->
data-grid-subdivision-depth="0.5"> <!-- Lower subdivision -->Simplify rendering:
<section
data-shader-system="gs3"
data-shader-preset="READ" <!-- Use READ preset -->
data-k-wobble="0.3" <!-- Lower wobble -->
data-k-grid="0.4"> <!-- Fewer grid lanes -->General Performance Tips:
- Use
READpreset for content/reading sections - Use
AMBIENTfor moderate motion - Reserve
HEROfor hero sections only - On mobile, default to
READpreset
Symptoms: Starts smooth, gets slower after minutes
Solutions:
If using manual shader switching:
// Ensure proper cleanup
if (instance.stop) instance.stop();
if (instance.dispose) instance.dispose();document.addEventListener('visibilitychange', () => {
const instance = window.ScrollShaderManager.getInstance();
if (document.hidden) {
if (instance && instance.stop) instance.stop();
} else {
// Will auto-restart when tab becomes visible
window.ScrollShaderManager.init();
}
});Solutions:
<!-- Use READ preset globally for better battery life -->
<section data-shader-system="gs1" data-shader-preset="READ">// Respect user's motion preferences
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
// Force all sections to READ
document.querySelectorAll('section[data-shader-preset]').forEach(section => {
section.setAttribute('data-shader-preset', 'READ');
});
}// Experimental: Battery API
if ('getBattery' in navigator) {
navigator.getBattery().then(battery => {
if (battery.level < 0.2) { // Below 20%
console.log('Low battery - using minimal motion');
// Switch to READ presets
}
});
}Symptoms: Canvas goes white/black briefly during transition
This is expected behavior due to single-canvas architecture:
- Fade out old shader (300ms)
- Dispose and reinitialize
- Fade in new shader (300ms)
Mitigation:
/* Use darker page background to minimize flash */
body {
background: #000;
}
/* Ensure sections have neutral backgrounds */
section {
background: rgba(0, 0, 0, 0.3);
}Symptoms: Ghosting or overlay of old shader
Solution: Ensure proper disposal (usually automatic, but check):
// If using manual control
const manager = window.ScrollShaderManager;
manager.switchTo('gs2'); // Automatically disposes previous shaderEnable debug mode to diagnose issues and monitor performance.
For manual initialization:
window.__INSTANCE__ = window.initBGShaderSystem({
canvasId: 'bg-canvas',
fragmentShader: window.BG_FRAGMENT_SHADER,
config: window.BG_SHADER_CONFIG,
adapter: window.BG_TopoReadAdapter,
debug: true // Enable debug mode
});A live FPS counter appears in the top-left corner showing:
- Current FPS - Actual rendering framerate
- Target FPS - Desired FPS based on preset
- DPR - Current device pixel ratio
Color coding:
- 🟢 Green - Performance good (≥80% of target)
- 🟡 Yellow - Performance degraded (50-80% of target)
- 🔴 Red - Performance poor (<50% of target)
Debug mode logs key events:
Initialization:
[morphbg] Debug mode enabled
[morphbg] Config: {...}
[morphbg] Adapter: BG_TopoReadAdapter
Scroll events:
[morphbg] Computing scroll targets
[morphbg] Section weight: 0.850 - preset: HERO
[morphbg] Final targets: {spatial: 0.89, temporal: 0.64, ...}
const isDev = window.location.hostname === 'localhost' ||
window.location.hostname === '127.0.0.1';
window.__INSTANCE__ = window.initBGShaderSystem({
canvasId: 'bg-canvas',
fragmentShader: window.BG_FRAGMENT_SHADER,
config: window.BG_SHADER_CONFIG,
adapter: window.BG_TopoReadAdapter,
debug: isDev // Only enable locally
});#morphbg-fps-counter {
top: 10px !important;
right: 10px !important; /* Move to top-right */
left: auto !important;
background: rgba(0, 0, 0, 0.9) !important;
font-size: 14px !important;
}const instance = window.__INSTANCE__;
// Check uniforms
console.log('Spatial motion:', instance.material.uniforms.u_spatialMotion.value);
console.log('Temporal motion:', instance.material.uniforms.u_temporalMotion.value);
// Force recalculation
instance.computeScrollTargets();No known issues.
Potential issues:
- Slightly different WebGL precision
- May need to adjust shader precision hints
Potential issues:
- WebGL 1.0 differences
- May need CSS prefixes for some features
Performance tips:
- Default to
READpreset - Use lower device pixel ratio
- Test on actual devices
const isMobile = /iPhone|iPad|Android/i.test(navigator.userAgent);
if (isMobile) {
// Use READ preset on mobile
document.querySelectorAll('section').forEach(s => {
s.setAttribute('data-shader-preset', 'READ');
});
}Before asking for help:
- ✅ Check browser console for errors (F12)
- ✅ Verify WebGL support: get.webgl.org
- ✅ Test with complete bundle (simplest setup)
- ✅ Enable debug mode
- ✅ Check network tab for failed script loads
// Check if morphbg loaded
console.log(window.initBGShaderSystem); // Should be a function
// Check if scroll manager loaded
console.log(window.ScrollShaderManager); // Should be an object
// Get current shader
console.log(ScrollShaderManager.getCurrentShader());
// Get instance
const instance = ScrollShaderManager.getInstance();
console.log(instance);
// Check section attributes
document.querySelectorAll('section[data-shader-system]').forEach(s => {
console.log(s.dataset);
});
// Check WebGL context
const canvas = document.getElementById('bg-canvas');
const gl = canvas.getContext('webgl');
console.log('WebGL context:', gl);| Error | Cause | Solution |
|---|---|---|
Cannot read property 'uniforms' of undefined |
Instance not initialized | Check if scripts loaded correctly |
WebGL: INVALID_OPERATION |
Shader switch issue | Usually auto-handled, check console for details |
Failed to compile shader |
GLSL syntax error | Check browser/device WebGL support |
THREE is not defined |
Three.js not loaded | Load Three.js before morphbg |
computeScrollTargets is not a function |
Wrong instance type | Ensure using correct shader instance |
If problems persist:
- GitHub Issues: cael-prussian/morphbg/issues
-
Include:
- Browser and version
- Console errors (screenshot)
- Minimal reproduction code
- Debug mode output
- Installation - Setup and installation
- Configuration - Parameter reference
- Shader Systems - GS1, GS2, GS3 details
- Bundle Options - Choose your deployment approach