What is it ?

Shaders are the new front-end web developpment big thing, with the ability to create very powerful 3D interactions and animations. A lot of very good javascript libraries already handle WebGL but with most of them it's kind of a headache to position your meshes relative to the DOM elements of your web page.

curtains.js was created with just that issue in mind. It is a small vanilla WebGL javascript library that converts HTML elements containing images and videos into 3D WebGL textured planes, allowing you to animate them via shaders.
You can define each plane size and position via CSS, which makes it super easy to add WebGL responsive planes all over your pages.

curtains.js demo gif

Knowledge and technical requirements

It is easy to use but you will of course have to possess good basics of HTML, CSS and javascript.

If you've never heard about shaders, you may want to learn a bit more about them on The Book of Shaders for example. You will have to understand what are the vertex and fragment shaders, the use of uniforms as well as the GLSL syntax basics.

Installation and usage

You can directly download the files and start using the ES6 modules: ```javascript import {Curtains, Plane} from 'path/to/src/index.mjs'; const curtains = new Curtains({ container: "canvas" }); const plane = new Plane(curtains, document.querySelector("#plane")); ```
Or you can use npm: ``` npm i curtainsjs ```
Load ES6 modules: ```javascript import {Curtains, Plane} from 'curtainsjs'; ```
In a browser, you can use the UMD files located in the `dist` directory: ```html ``` ```javascript const curtains = new Curtains({ container: "canvas" }); const plane = new Plane(curtains, document.querySelector("#plane")); // etc ```

Usage with React

Note that if you are using React, you might want to try react-curtains, curtains.js official React package.

Documentation

The library is split into classes modules. Most of them are used internally by the library but there are however a few classes meant to be used directly, exported in the [src/index.mjs](src/index.mjs) file.

Core

Frame Buffer Objects

Loader

Math

Extras

Full documentation

Getting started
API docs
Examples

Basic example

HTML

```html
```

CSS

```css body { /* make the body fits our viewport */ position: relative; width: 100%; height: 100vh; margin: 0; overflow: hidden; } #canvas { /* make the canvas wrapper fits the document */ position: absolute; top: 0; right: 0; bottom: 0; left: 0; } .plane { /* define the size of your plane */ width: 80%; height: 80vh; margin: 10vh auto; } .plane img { /* hide the img element */ display: none; } ```

Javascript

```javascript import {Curtains, Plane} from 'curtainsjs'; window.addEventListener("load", () => { // set up our WebGL context and append the canvas to our wrapper const curtains = new Curtains({ container: "canvas" }); // get our plane element const planeElement = document.getElementsByClassName("plane")[0]; // set our initial parameters (basic uniforms) const params = { vertexShaderID: "plane-vs", // our vertex shader ID fragmentShaderID: "plane-fs", // our fragment shader ID uniforms: { time: { name: "uTime", // uniform name that will be passed to our shaders type: "1f", // this means our uniform is a float value: 0, }, }, }; // create our plane using our curtains object, the bound HTML element and the parameters const plane = new Plane(curtains, planeElement, params); plane.onRender(() => { // use the onRender method of our plane fired at each requestAnimationFrame call plane.uniforms.time.value++; // update our time uniform value }); }); ```

Shaders

Vertex shader

```glsl ```

Fragment shader

```glsl ```

Changelog

Complete [changelog](CHANGELOG.md) starting from version 7.1.0