MX2 Web Assembly Graphics Demo
A powerful web-based demonstration application featuring real-time shader effects, interactive controls, and custom shader compilation.
Uses libmx2 found here: https://github.com/lostjared/libmx2/
Explore a diverse collection of visually stunning shader effects including:
- Kaleidoscope effects - Symmetrical fractal patterns with real-time transformations
- Distortion effects - Wave, ripple, twist, and bend distortions
- Psychedelic effects - Color shifts, rainbow effects, and chromatic aberration
- ** 3D transformations** - Perspective warping, 3D rotations, and projections
- Noise & chaos - Scrambling, VHS effects, and digital artifacts
- Interactive effects - Mouse-controlled swirls, zooms, and fractal folding
Write and compile your own GLSL ES 3.0 fragment shaders with:
- Real-time shader code editing
- Instant compilation feedback with detailed error messages
- Pre-built shader templates to get started
- Live preview of your custom effects
- Shader compilation validation before applying
- Load PNG and JPG images directly into the application
- Apply any shader effect to your own images
- Supports file selection
- Dynamic texture replacement at runtime
- Save the current rendered output as PNG
- Automatically timestamped filenames
- High-quality WebGL canvas capture
- Arrow Keys / Spacebar - Cycle through shaders
- Mouse Movement - Control interactive shader parameters
- Mouse Click & Drag - Manipulate focal points in mouse-aware effects
- Custom Shader Panel - Press
βοΈ Custom Shaderbutton to edit
# Build with Emscripten
make -f Makefile.emWeb:
Open index.html in a modern web browser (Chrome, Firefox, Edge)
inside a running web server. If you have Python, you can start one with
$ python3 -m http.server 3000
Then navigate to localhost:3000
-
Browsing Shaders:
- Click
β PrevandNext βΆbuttons - Use arrow keys (ββ) or spacebar
- Each shader is instantly applied
- Click
-
Loading Custom Images:
- Click
πΌοΈ Load Imagebutton - Select a PNG or JPG file
- The image is loaded into the current shader
- Try different shaders on your image
- Click
-
Creating Custom Shaders:
- Click
βοΈ Custom Shaderbutton - The shader editor modal opens
- Choose a template or start from scratch
- Edit the GLSL code
- Click
βΆ Compile & Applyto test - Compilation errors appear in red in the log
- Reset to defaults with
π Reset
- Click
-
Saving Screenshots:
- Click
πΎ Save Imagebutton - Or press
Skey - PNG saves with timestamp:
mx2_shader_YYYYMMDD_HHMMSS.png
- Click
When writing custom shaders, you have access to:
uniform sampler2D textTexture; // Input texture/image
uniform float time_f; // Animation time in seconds
uniform vec2 iResolution; // Screen resolution (width, height)
uniform vec4 iMouse; // Mouse state (x, y, button_pressed, dragging)
uniform float alpha; // Opacity (0.0 - 1.0)
uniform float amp; // Amplitude parameter (0.0 - 1.0)
uniform float uamp; // User amplitude (0.0 - 1.0)#version 300 es
precision highp float;
out vec4 color;
in vec2 TexCoord;
uniform sampler2D textTexture;
uniform float time_f;
uniform vec2 iResolution;
uniform vec4 iMouse;
void main(void) {
vec2 tc = TexCoord;
vec2 center = iMouse.xy / iResolution;
vec2 dist = tc - center;
float r = length(dist);
// Ripple effect from mouse
float ripple = sin(r * 30.0 - time_f * 5.0) * 0.02;
vec2 displaced = tc + normalize(dist + 0.001) * ripple;
color = texture(textTexture, displaced);
}- Bubble - Bubble distortion effect
- Kaleidoscope - Symmetrical fractal patterns
- KaleidoscopeAlt - Alternative kaleidoscope
- Scramble - Digital scrambling
- Swirl - Smooth swirl distortion
- Mirror - Mirrored reflection
- VHS - VCR/VHS tape effect
- Twist - Twist and rotation
- Time - Time-based morphing
- Bend - Bending distortion
- Pong - Logarithmic spiral animation
- PsychWave - Psychedelic wave patterns
- CrystalBall - Crystal ball effect
- ZoomMouse - Mouse-controlled zoom
- Drain - Spiral drain effect
- Ufo - UFO distortion
- Wave - Diagonal wave patterns
- UfoWarp - UFO with warping
- ByMouse - Mouse interaction
- Deform - Organic deformation
- Geo - Geometric patterns
- Smooth - Smooth blur and color
- Hue - Hue shifting
- kMouse - Kaleidoscope with mouse
- Drum - Drum ripple effect
- ColorSwirl - Color swirling
- MouseZoom - Mouse-based zoom
- Rev2 - Mirrored reflection
- Fish - Fisheye lens effect
- RipplePrism - Ripple with color separation
- MirrorMouse - Mouse-controlled mirror
- FracMouse - Fractal folding with mouse
- Cats - Psychedelic XOR effects
- ColorMouse - Color manipulation with mouse
- TwistFull - Full-screen twist
- BowlByTime - Time-based bowl effect
- Pebble - Ripple from pebble
- MirrorPutty - Putty-like mirroring
| Action | Web |
|---|---|
| Next Shader | Next βΆ button or β |
| Prev Shader | β Prev button or β |
| Load Image | πΌοΈ Load Image button |
| Save Screenshot | πΎ Save Image or S |
| Open Shader Editor | βοΈ Custom Shader button |
| Close Editor | β Close or Esc |
| Interact with Effect | Mouse movement/click |
- Check GLSL syntax against ES 3.0 specification
- Ensure all variable types match (vec2, vec3, vec4, float, int)
- Look at the compilation log for specific errors
- Try a template as a starting point
- Ensure file is PNG or JPG format
- Check file size isn't too large
- Try a different image file
- Check browser console for errors
- Click
βΆ Compile & Applybutton - Check compilation log for errors
- Ensure the shader has a
main()function - Verify all uniforms are declared
- Close the shader editor modal when not in use
- Reduce shader complexity (fewer loops, simpler math)
- Lower canvas resolution on older devices
libmx2/gl_about/
βββ graphics.cpp # Main application and shader definitions
βββ index.html # Web interface and controls
βββ Makefile.em # Emscripten build configuration
βββ data/
βββ logo.png # Default texture
- Create shader source string:
const char *szNewShader = R"(#version 300 es
// ... shader code ...
)";- Add to
shaderSourcesvector:
{"ShaderName", szNewShader}Modify shader uniforms, add new features, or integrate with other GL applications by linking against the library components.
Part of the MX2 Graphics Library collection.
Shader effects created with inspiration from:
- Shadertoy community
- Demoscene artists
- Interactive graphics researchers
- Web version runs in WebGL 2.0 (hardware-accelerated)
- 60 FPS target on modern hardware
- Shader compilation happens in real-time
- Image loading supports up to 4K resolution

