Questions tagged [curtains.js]

curtains.js 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, add post processing, etc.

It was created by Martin Laxenaire and is released under the MIT license.

Basic example

<html> 
  <head> 
    <title>curtains.js basic example</title> 
    <style>
      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: fixed;
        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;
      }
    </style> 
  </head> 
  <body> 
    <!-- div that will hold our WebGL canvas -->
    <div id="canvas"></div>
    <!-- div used to create our plane -->
    <div class="plane">
      <!-- image that will be used as texture by our plane -->
      <img src="path/to/my-image.jpg" />
    </div>

    <script src="curtains.umd.min.js"></script> 
    <script> 
      const vertexShader = `
        #ifdef GL_ES
        precision mediump float;
        #endif

        // those are the mandatory attributes that the lib sets
        attribute vec3 aVertexPosition;
        attribute vec2 aTextureCoord;

        // those are mandatory uniforms that the lib sets and that contain our model view and projection matrix
        uniform mat4 uMVMatrix;
        uniform mat4 uPMatrix;

        // our texture matrix that will handle image cover
        uniform mat4 uTextureMatrix0;

        // pass your vertex and texture coords to the fragment shader
        varying vec3 vVertexPosition;
        varying vec2 vTextureCoord;

        void main() {       
          gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
    
          // set the varyings
          // here we use our texture matrix to calculate the accurate texture coords
          vTextureCoord = (uTextureMatrix0 * vec4(aTextureCoord, 0.0, 1.0)).xy;
          vVertexPosition = aVertexPosition;
        }
      `;

       const fragmentShader = `
        #ifdef GL_ES
        precision mediump float;
        #endif

        // get our varyings
        varying vec3 vVertexPosition;
        varying vec2 vTextureCoord;

        // the uniform we declared inside our javascript
        uniform float uTime;

        // our texture sampler (default name, to use a different name please refer to the documentation)
        uniform sampler2D uSampler0;

        void main() {
          // get our texture coords from our varying
          vec2 textureCoord = vTextureCoord;
    
          // displace our pixels along the X axis based on our time uniform
          // textures coords are ranging from 0.0 to 1.0 on both axis
          textureCoord.x += sin(textureCoord.y * 25.0) * cos(textureCoord.x * 25.0) * (cos(uTime / 50.0)) / 25.0;
    
          // map our texture with the texture matrix coords
          gl_FragColor = texture2D(uSampler0, textureCoord);
        }
      `;

      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.querySelector(".plane");

        // set our initial parameters (basic uniforms)
        const params = {
          vertexShader: vertexShader, // our vertex shader
          fragmentShader: fragmentShader, // our fragment shader
          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
        });
      });
    </script> 
  </body> 
</html>

Useful links

17 questions
2
votes
2 answers

ReactJS fire up useEffect with window.location.reload() inside just one time on every page visit

please forgive me for this kind of amateur question. I have the following problem which I can´t solve by my own: I´m working on a cra-project in which I´m using a continually distorted image animation and scroll animation from curtainjs, and…
2
votes
4 answers

Run a function when animation completes using Curtains.js

I'm looking to call a function right at the end of the wobble effect. That is, at the end of the damping effect (when the wobble stops), I'd like to execute a GSAP timeline function. I'd assume this type of "onComplete" function would need to be…
Nish
  • 81
  • 6
1
vote
1 answer

CurtainsJS GSAP WebGL list items mouseover issue

I'm trying to integrate a WebGL animation on list items: images who give place to a video on mouseover. The transitions are same as http://taotajima.jp/ and I'm inspired of the frag and vertex from…
F3LENYR
  • 125
  • 1
  • 7
1
vote
0 answers

How to call multiple planes in javascript?

I've been trying to fix an issue with my site for the past week to no avail. I'm using Curtains.js and I just want to display multiple planes on the home page. I've got that working, but every plane after the first shifts up, overlaps or is…
blaine
  • 47
  • 4
0
votes
0 answers

How can i change the edges of the plane to be rounded (Without interfering with the functioning of the script)?

My objective is to utilize curtainjs to apply a distortion and scale effect along the Y axis to a plane and its texture, with the added specification of incorporating rounded edges on the plane. However, I am not sure of how to execute this…
0
votes
0 answers

Passing a value to a shader in OpenGL Shading Language using curtains.js

I have a curtain.js component. I have a mousemove event that determines planeDeformation. My issue is that I want the coordinates in my shader to track the cursor, but currently the coordinates only displace as per the shader. Thinking about it with…
Jeremiah
  • 1
  • 2
0
votes
1 answer

Curtainjs doesn't load when changing page

So I'm using curtainjs on my website. I have a landing page that redirect to my about page, but when I go to my about page from the landing page, the curtainjs doesn't work. But as soon as I reload the page everything works fine. Here's how I…
Eli-ott
  • 153
  • 2
  • 10
0
votes
1 answer

Curtains Shader with react

I try to recreate this effect with curtains-react but I can not find a shader that corresponds, and at the same time make the uniforms work ... If someone can give a lead, an article or an example with curtains-react, it would be of great help to…
DELORME Joris
  • 97
  • 1
  • 7
0
votes
0 answers

Curtains.js Smooth Scroll Reactjs

I trying ton implement smooth scroll of locomotive-scroll to curtains in Reactjs. But he still doesn't work... I get errors : react_curtains__WEBPACK_IMPORTED_MODULE_2__.Curtains.disableDrawing is not a…
0
votes
0 answers

Curtains JS in NextJS not rendering images

I'm trying to Create the nextJS Slideshow component using curtainsJS and GSAP. I'm following this algorithm. I'm used curtainsJS npm library to create this slide show. but images not rendering in the canvas in code sandbox it work perfectly with…
Buddhika Prasadh
  • 356
  • 1
  • 5
  • 16
0
votes
0 answers

Curtains Animation isn't working on multiple images

I am using curtains animation in my web page Below is the link to codepen for animation demo curtain animation I used above example but I am unable to achieve this on multiple images. also it have some 100vh height, width and absolute position…
Afzal Ali
  • 880
  • 8
  • 25
0
votes
2 answers

Multiple textures webgl frag shader problem

I'm using curtains.js for my web project. I'm telling you this because I tried to find similar questions on stackoverflow about this topic but due to the way curtains is made, I wasn't able to reproduce the answers. curtains.js is very specific…
0
votes
1 answer

curtains.js — Unable to initialize the shader program

I'm attempting to add a fragment shader to plane created via curtains. I've used this fragment shader with other libraries before — namely, canvas-sketch — however I can't seem to get the shader to run as the console prompts me with the error:…
heyron
  • 117
  • 7
0
votes
1 answer

Next JS with Courtain.js library not receiving parameter

Good day friends, I am creating a website and in the homepage I need to insert an image that is distorted with an animation. For that I got a library called Courtain.js that cost me to understand and a developer managed to make it work and sent me…
JDLR
  • 520
  • 1
  • 4
  • 20
0
votes
1 answer

Curtains.js does not work

Here is my project https://c9.io/antibioticvz/demo-project I tried implement Curtains.js and it's scrolling a page, but I not able to change scrollSpeed: and curtainLinks: So how to make link to my page part? Who had relevant…
victor zadorozhnyy
  • 889
  • 1
  • 12
  • 25
1
2