This boilerplate allows you to develop quickly and easily WebGL canvas bundles. It has two modes. The result of production mode is a minimized bundle. You can embed this bundle as a 3D animated background on a website, for example.
In development mode, the GLSLX shader files are watched. That means, if you edit them and save your changes, the shaders will be recompiled and reloaded immediately. Feel free to adapt the existing shaders or create a completely new one. If you need inspiration, check out Shadertoy or GLSL Sandbox for fragment shaders and Vertexshaderart for vertex shaders. There you can see what's possible.
If you don't need this boilerplate but would like to embed the already minimized canvas bundles directly on your website, see the following.
Header.mp4 |
Header.mp4 |
Header.mp4 |
Header.mp4 |
with jsDelivr
<canvas id="mtw-canvas" style="width:100vw;height:100vh;left:0;top:0;position:fixed;"></canvas>
<script src="https://cdn.jsdelivr.net/gh/mythemeway/[email protected]/boilerplate-canvas/twgl/canvas.bundle.min.js"></script>
<canvas id="mtw-canvas" style="width:100vw;height:100vh;left:0;top:0;position:fixed;"></canvas>
<script src="./canvas.bundle.min.js"></script>
Warning: WebGL canvases can make your CPU sweat. For the environment, stop the requestAnimationFrame loop when the canvas isn't visible #GreenCoding. See my website-boilerplate for an example.
Two types of minimized bundles are available for each canvas. One contains TWGL and one contains three.js instead. I recommend using the TWGL bundles because they are much smaller as you can see in the table below.
Bundle Sizes | malachite | __disks__ | __spiral__ | blacksea |
---|---|---|---|---|
TWGL | ||||
three.js |
Note: Badges are clickable and linked to the corresponding minimized bundle.
GLSLX & prepr are integrated via esbuild-plugin-glslx
Badges are clickable and linked to their sources.
Note: Cards are clickable and linked to the corresponding GitHub repositories.
To enable local operation of this boilerplate, you can do the following:
- open your terminal and define your startup file
MYSTARTUPFILE
in use - install nvm and source your startup file again
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash source ~/$MYSTARTUPFILE
- if your terminal has closed, open it again and continue
- execute to install Node.js
- clone the repository
git clone https://github.com/mythemeway/mtw-boilerplate-graphics
or your fork to your local machine - change your current directory to mtw-boilerplate-graphics
cd mtw-boilerplate-graphics
- run
npm install
Note: If you've already installed you only have to do steps 5-7.
That's it.
Go to the mtw-boilerplate-graphics directory on your local machine and execute npm start
. The result will appear at e. g. http://localhost:8080
.
There are two ways to get your minimized bundle.
Way 1: npm run build
= without terser [default] [faster]
Way 2: npm run terser
= with terser additionally [smaller]
Note: output directory is always
~/mtw-boilerplate-graphics/dist
- open
~/mtw-boilerplate-graphics/canvas.config.js
- change
const canvas
and save it// // CANVAS SETTINGS // - path: path to canvas // - prepr: GLSL preprocessing // - id: canvas id attribute // // TWGL // // const canvas = { path: './src/twgl/mtw-canvas-disks', prepr: null, id: 'mtw-canvas' }; // const canvas = { path: './src/twgl/mtw-canvas-malachite', prepr: {}, id: 'mtw-canvas' }; // const canvas = { path: './src/twgl/mtw-canvas-blacksea', prepr: {}, id: 'mtw-canvas' }; // const canvas = { path: './src/twgl/mtw-canvas-spiral', prepr: null, id: 'mtw-canvas' }; // three.js // // const canvas = { path: './src/three/mtw-canvas-disks', prepr: null, id: 'mtw-canvas' }; const canvas = { path: './src/three/mtw-canvas-malachite', prepr: {}, id: 'mtw-canvas' }; // const canvas = { path: './src/three/mtw-canvas-blacksea', prepr: {}, id: 'mtw-canvas' }; // const canvas = { path: './src/three/mtw-canvas-spiral', prepr: null, id: 'mtw-canvas' }; module.exports = canvas;
- put
mtw-canvas-new
into the~/mtw-boilerplate-graphics/src/...
directory - follow the switch canvas procedure
// // CANVAS SETTINGS // - path: path to canvas // - prepr: GLSL preprocessing // - id: canvas id attribute // // TWGL // // const canvas = { path: './src/twgl/mtw-canvas-disks', prepr: null, id: 'mtw-canvas' }; // const canvas = { path: './src/twgl/mtw-canvas-malachite', prepr: {}, id: 'mtw-canvas' }; const canvas = { path: './src/twgl/mtw-canvas-new', prepr: { myVar: 1, myMacro: function (arg) { return arg; } }, id: 'mtw-canvas' }; // const canvas = { path: './src/twgl/mtw-canvas-blacksea', prepr: {}, id: 'mtw-canvas' }; // const canvas = { path: './src/twgl/mtw-canvas-spiral', prepr: null, id: 'mtw-canvas' }; module.exports = canvas;
mtw-canvas-new
must have a main.js fileyour canvas id attribute setting is only used in production mode; in development mode it is always the default
mtw-canvas
if you switch/add a canvas in development mode, the result is displayed immediately after saving your changes
to customize the fragment and/or vertex shaders, modify the shaders.glslx files
mtw-canvas-disks [included] [default]; Fragment shader is based on CoordSys - intersection [License: MIT; Copyright: © 2013 Inigo Quilez; Changes: made]
mtw-canvas-malachite [included]; Fragment shader is based on Glare of water [License: CC BY 3.0; Copyright: © 2019 Jan Mróz; Changes: made]
mtw-canvas-spiral and mtw-canvas-blacksea [not included]; you have to add them manually
The use of protected brand names, trade names, utility models and brand logos on this website does not constitute an infringement of copyright; rather, it serves as an illustrative note. Even if this is not marked as such at the respective points, the corresponding legal provisions always apply.
The brand names and logos used are the property of their respective owners and are subject to their copyright provisions.
This offer is in no way related to the legal entities of the protected brand names and logos used.
This README contains links to external third-party websites. The README operator has no influence on the content of these sites. Therefore, he cannot assume any liability. Instead, the respective provider is always responsible for the content.
The linked pages were checked for possible legal violations at the time of linking and illegal content wasn't discernible. A permanent control of the linked pages is unreasonable without concrete evidence of an infringement. However, if the README operator becomes aware of such a violation, he will act immediately.
star-solid.svg & code-branch-solid.svg [License: CC BY 4.0; Copyright: © Fonticons, Inc.; Changes: made]
GitHub Readme Stats [License: MIT; Copyright © 2021 Anurag Hazra; Changes: made]
Simple Icons [License: CC0 1.0]
Shields.io [License: CC0 1.0]