Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <div id="wrap-texture">
  <!-- div that will hold our WebGL canvas -->
  <div id="canvas"></div>

  <!-- div used to create our plane -->
  <div class="plane">
    <div class="text-canvas">
      <h1>CREATIVE CODE</h1>
    </div>
    
    <img class="gradient-texture" src="https://i.ibb.co/sRkwn7y/fuzzy-1800136-1920.jpg" alt="" crossorigin="anonymous">
  </div>
</div>

<script id="vs" type="x-shader/x-vertex">
    #ifdef GL_ES
    precision mediump float;
    #endif
    
    #define TAU 6.28318530718
    #define PI 3.14159265359
    #define S(a,b,n) smoothstep(a,b,n)
    #define NUM_OCTAVES 5
    
    uniform float uTime; 
    
    // 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;

    uniform mat4 gradientTextureMatrix;
    uniform mat4 canvasTextureMatrix;

    // if you want to pass your vertex and texture coords to the fragment shader
    varying vec3 vVertexPosition;
    varying vec2 vCanvasCoord;
    varying vec2 vGradientCoord;
    varying float vTime;

    void main() {
        vec3 vertexPosition = aVertexPosition;
        vTime = uTime;
      
        // set the varyings
        vCanvasCoord = (canvasTextureMatrix * vec4(aTextureCoord, 0., 1.)).xy;
        vGradientCoord = (gradientTextureMatrix * vec4(aTextureCoord, 0., 1.)).xy;
        vVertexPosition = vertexPosition;
      
        vec2 center = vCanvasCoord - .5;
      
        float dist = length(center);

        gl_Position = uPMatrix * uMVMatrix * vec4(vertexPosition, 1.0);
    }
</script>
<script id="fs" type="x-shader/x-fragment">
    #ifdef GL_ES
    precision mediump float;
    #endif

    #define TAU 6.28318530718
    #define PI 3.14159265359
    #define S(a,b,n) smoothstep(a,b,n)
    #define NUM_OCTAVES 5

    varying float vTime;
    uniform float uProgress;
    uniform vec2 uReso;
    uniform vec2 uMouse;
    
    // get our varyings
    varying vec3 vVertexPosition;
    varying vec2 vCanvasCoord;
    varying vec2 vGradientCoord;

    // the uniform we declared inside our javascript

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

  
    // 2D Random
    float random (in vec2 st) {
        return fract(sin(dot(st.xy,
                             vec2(12.9898,78.233)))
                     * 43758.5453123);
    }

      // 2D Noise based on Morgan McGuire @morgan3d
      // https://www.shadertoy.com/view/4dS3Wd
      float perlin (in vec2 st) {
          vec2 i = floor(st);
          vec2 f = fract(st);

          // Four corners in 2D of a tile
          float a = random(i);
          float b = random(i + vec2(1.0, 0.0));
          float c = random(i + vec2(0.0, 1.0));
          float d = random(i + vec2(1.0, 1.0));

          // Smooth Interpolation

          // Cubic Hermine Curve.  Same as SmoothStep()
          vec2 u = f*f*(3.0-2.0*f);
          // u = smoothstep(0.,1.,f);

          // Mix 4 coorners percentages
          return mix(a, b, u.x) +
                  (c - a)* u.y * (1.0 - u.x) +
                  (d - b) * u.x * u.y;
      }
   
    void main(){
        vec2 uv0 = vCanvasCoord;
        vec2 uv1 = vGradientCoord;
        
        vec2 st = (gl_FragCoord.xy - 0.5 * uReso) / min(uReso.y, uReso.y);
        vec2 mouse = (uMouse - 0.5 * uReso) / min(uReso.y, uReso.y);
              
        float freq = PI * 10.0;
        float amp = 10.0;
        float t = vTime * 0.4;
      
        float x = uv1.y * freq + t;
        float y = uv1.x * freq + t;
      
        float distX = cos(x+y) * amp * cos(y);
        float distY = sin(x-y) * amp * cos(y);
        
        vec2 distortion = vec2(distX, distY);

        uv1 += distortion;
        
        float n = abs(perlin(uv1 * 6.0 + perlin(uv1 * 6.0) ));
                    
        vec4 text = texture2D(canvasTexture, uv0);
        vec4 gradient = texture2D(gradientTexture, uv1 + n ) * S(0.7 * uProgress, 1.0, n) * 2.0;
     
        gl_FragColor = vec4(text.r * gradient.rgb, 1.0);
    }
</script>
              
            
!

CSS

              
                @font-face {
  font-family: "Altero";
  src: url(https://rawcdn.githack.com/AlainBarrios/Fonts/22bbee76f635dcbead59903159189186d569bfe7/Altero-Regular.otf?raw=true);
}

:root {
  --altero: "Altero";
}

body {
  /* make the body fits our viewport */
  position: relative;
  width: 100%;
  height: 100vh;
  margin: 0;
  background-color: rgb(0,0,0);
}

h1 {
  margin: 0;
}

canvas {
  max-width: 100%;
}

#wrap-texture {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100%;
}

#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 */
  z-index: 100;
  margin-left: 4%;
}

.plane img {
  /* hide the img element */
  display: none;
}

.text-canvas {
  visibility: hidden;
  font-family: var(--altero);
  font-weight: bold;
  font-size: calc(9/16 * 7vw);
}

              
            
!

JS

              
                class CanvasTexture {
  constructor({ curtains, el, debug }) {
    this.curtains = curtains;
    this.element = el;
    this.canvas = document.createElement("canvas");
    this.ctx = this.canvas.getContext("2d");

    if (debug) this.debugCanvas();
  }

  createText() {
    const childEle = this.element.children[0].children[0];
    const text = childEle.textContent;

    const computed = window.getComputedStyle(childEle);
    const boundChild = this.curtains.planes[0].getBoundingRect();

    this.canvas.width = this.ctx.width =
      boundChild.width / this.curtains.pixelRatio;
    this.canvas.height = this.ctx.height =
      boundChild.height / this.curtains.pixelRatio;

    this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);

    this.ctx.fillStyle = "rgb(255, 255, 255)";
    this.ctx.textBaseline = `${computed.verticalAlign}`;
    this.ctx.textAlign = `${computed.textAlign}`;
    this.ctx.font = `${computed.fontWeight} ${computed.fontSize} Arial`;

    this.ctx.fillText(text, 0, boundChild.height);
  }

  debugCanvas() {
    this.canvas.id = "canvas-debug";
    document.body.append(this.canvas);
  }
}

class WEBGL {
  constructor(set) {
    this.canvas = set.canvas;
    this.webGLCurtains = new Curtains("canvas");
    this.planeElement = set.planeElement;
    this.mouse = {
      x: 0,
      y: 0
    };
    this.params = {
      vertexShader: document.getElementById("vs").textContent, // our vertex shader ID
      fragmentShader: document.getElementById("fs").textContent, // our framgent shader ID
      widthSegments: 40,
      heightSegments: 40, // we now have 40*40*6 = 9600 vertices !
      uniforms: {
        time: {
          name: "uTime", // uniform name that will be passed to our shaders
          type: "1f", // this means our uniform is a float
          value: 0
        },
        mousepos: {
          name: "uMouse",
          type: "2f",
          value: [0, 0]
        },
        resolution: {
          name: "uReso",
          type: "2f",
          value: [innerWidth, innerHeight]
        },
        progress: {
          name: "uProgress",
          type: "1f",
          value: 0
        }
      }
    };
  }

  initPlane() {
    // create our plane mesh
    this.plane = this.webGLCurtains.addPlane(this.planeElement, this.params);

    // create gradient texture
    const gradientTexture = this.plane.createTexture("gradientTexture");
    const image0 = document.querySelector(".gradient-texture");
    gradientTexture.setSource(image0);

    this.canvasTexture = new CanvasTexture({
      curtains: this.webGLCurtains,
      el: this.plane.htmlElement,
      debug: false
    });
    this.canvasTexture.canvas.setAttribute("data-sampler", "canvasTexture");
    this.canvasTexture.createText();
    this.plane.loadCanvas(this.canvasTexture.canvas);

    // use the onRender method of our plane fired at each requestAnimationFrame call

    if (this.plane) {
      this.plane.onReady(() => {
        this.update();
        this.initEvent();
      });
    }
  }

  update() {
    this.plane.onRender(() => {
      this.plane.uniforms.time.value += 0.01; // update our time uniform value

      this.plane.uniforms.resolution.value = [innerWidth, innerHeight];
    });
  }

  initEvent() {
    this.planeElement.addEventListener("mouseover", e => {
      gsap.to(this.plane.uniforms.progress, 0.7, {
        value: 1
      });
    });

    this.planeElement.addEventListener("mouseout", e => {
      gsap.to(this.plane.uniforms.progress, 0.7, {
        value: 0
      });
    });

    window.addEventListener("resize", () => this.onResize());
  }

  onResize() {
    if (this.plane.textures[0]) {
      this.canvasTexture.createText();
      this.plane.textures[0].needUpdate();
    }
  }
}

const webgl = new WEBGL({
  canvas: document.getElementById("canvas"),
  planeElement: document.getElementsByClassName("plane")[0]
});

webgl.initPlane();

              
            
!
999px

Console