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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <div class="scroll-downs">
  <div class="mousey">
    <div class="scroller"></div>
  </div>
  <span class="text">Move MouseWheel</span>
</div>

<div id="content-canvas"></div>
<script id="vertex-shader" type="x-shader/x-vertex">
  uniform float time;
  varying vec2 vUv;
  varying vec2 vUv1;
  varying vec4 vPosition;

  uniform sampler2D texture1;
  uniform sampler2D texture2;
  uniform vec2 pixels;
  uniform vec2 uvRate1;

  void main() {
    vUv = uv;
    vec2 _uv = uv - 0.5;
    vUv1 = _uv;
    vUv1 *= uvRate1.xy;

    vUv1 += 0.5;
    
    gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  }
</script>

<script type="x-shader/x-fragment" id="fragment-shader">
  uniform float time;
  uniform float progress;
  uniform sampler2D tex1;
  uniform sampler2D tex2;
  uniform vec2 pixels;
  uniform vec2 uvRate1;
  uniform vec2 accel;

  varying vec2 vUv;
  varying vec2 vUv1;
  varying vec4 vPosition;

  vec2 mirrored(vec2 v) {
    vec2 m = mod(v,2.);
    return mix(m,2.0 - m, step(1.0 ,m));
  }

  float tri(float p) {
    return mix(p,1.0 - p, step(0.5 ,p))*2.;
  }

  void main()	{
    vec2 uv = gl_FragCoord.xy/pixels.xy;

    float p = fract(progress);

    float delayValue = p*7. - uv.y*2. + uv.x - 2.;

    delayValue = clamp(delayValue,0.,1.);

    vec2 translateValue = p + delayValue*accel;
    vec2 translateValue1 = vec2(-0.5,1.)* translateValue;
    vec2 translateValue2 = vec2(-0.5,1.)* (translateValue - 1. - accel);

    vec2 w = sin( sin(time)*vec2(0,0.3) + vUv.yx*vec2(0,4.))*vec2(0,0.5);
    vec2 xy = w*(tri(p)*0.5 + tri(delayValue)*0.5);

    vec2 uv1 = vUv1 + translateValue1 + xy;
    vec2 uv2 = vUv1 + translateValue2 + xy;

    vec4 rgba1 = texture2D(tex1,mirrored(uv1));
    vec4 rgba2 = texture2D(tex2,mirrored(uv2));

    vec4 rgba = mix(rgba1,rgba2,delayValue);
    gl_FragColor = rgba;
  }
</script>
              
            
!

CSS

              
                body{
  margin: 0;
  padding: 0;
  min-width: 100vw;
  min-height: 100vh;
}

canvas{
  display: block;
}

// scroll icon by https://codepen.io/2xsamurai/pen/WwmjKQ
.scroll-downs {
  position: absolute;
  min-width: 100%;
  bottom: 10%;
  display: flex;
  align-items: center;
  align-content: center;
  flex-direction: column;
  z-index: 10;
  width :34px;
  height: 55px;
  color: #fff;
  font-family: 'Open Sans', sans-serif;
}
.mousey {
  min-width: 3px;
  padding: 10px 15px;
  min-height: 35px;
  border: 4px solid #fff;
  border-radius: 25px;
  opacity: 0.75;
  box-sizing: content-box;
}
.scroller {
  width: 4px;
  height: 10px;
  border-radius: 25%;
  background-color: #fff;
  animation-name: scroll;
  animation-duration: 2.2s;
  animation-timing-function: cubic-bezier(.15,.41,.69,.94);
  animation-iteration-count: infinite;
}
@keyframes scroll {
  0% { opacity: 0; }
  10% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(15px); opacity: 0;}
}

.text{
  margin-top: 5px;
}
              
            
!

JS

              
                ((d) => {
  const content = d.querySelector("#content-canvas");
  let delta = 0;
  let isWheel = false;
  const gl = {
    camera: new THREE.PerspectiveCamera(
      75,
      innerWidth / innerHeight,
      0.01,
      1000
    ),
    scene: new THREE.Scene(),
    renderer: new THREE.WebGLRenderer(),
    loader: new THREE.TextureLoader()
  };

  const textures = [
    gl.loader.load("https://i.ibb.co/RzDyDDC/pexels-photo-38196.jpg"),
    gl.loader.load("https://i.ibb.co/7CDBNPJ/pexels-photo-573298.jpg"),
    gl.loader.load("https://i.ibb.co/VJMcgmD/pexels-photo-135018.jpg"),
    gl.loader.load("https://i.ibb.co/sP43CmL/julien-r-1265218-unsplash.jpg")
  ];

  const l = textures.length;

  const uniforms = {
    time: { type: "f", value: 0 },
    pixels: { type: "v2", value: new THREE.Vector2(innerWidth, innerHeight) },
    accel: { type: "v2", value: new THREE.Vector2(0.5, 2) },
    progress: { type: "f", value: 0 },
    uvRate1: {
      value: new THREE.Vector2(1, 1)
    },
    tex1: {
      value: textures[0]
    },
    tex2: {
      value: ""
    }
  };

  const addScene = () => {
    gl.renderer.setSize(innerWidth, innerHeight);
    gl.renderer.setPixelRatio(devicePixelRatio);
    content.appendChild(gl.renderer.domElement);

    gl.camera.position.set(0, 0, 1);
    gl.scene.add(gl.camera);
    addMesh();
  };

  const addMesh = () => {
    gl.material = new THREE.ShaderMaterial({
      side: THREE.DoubleSide,
      uniforms: uniforms,
      vertexShader: d.querySelector("#vertex-shader").textContent,
      fragmentShader: d.querySelector("#fragment-shader").textContent
    });

    const geometry = new THREE.PlaneGeometry(1, 1, 1, 1);

    gl.plane = new THREE.Mesh(geometry, gl.material);

    gl.scene.add(gl.plane);
  };

  const update = () => {
    render();
    requestAnimationFrame(update);
  };

  const resize = () => {
    const w = innerWidth;
    const h = innerHeight;

    gl.camera.aspect = w / h;
    gl.renderer.setSize(w, h);

    const dist = gl.camera.position.z - gl.plane.position.z;
    const height = 1;
    gl.camera.fov = 2 * (180 / Math.PI) * Math.atan(height / (2 * dist));

    if (w / h > 1) {
      gl.plane.scale.x = gl.plane.scale.y = w / h;
    }

    gl.camera.updateProjectionMatrix();
  };

  const render = () => gl.renderer.render(gl.scene, gl.camera);

  const animate = () => {
    delta++;

    gsap.to(uniforms.progress, 1, {
      value: delta,
      ease: Sine.easeOut,
      onUpdate: () => {
        const progress = Math.floor(uniforms.progress.value) % textures.length;
        const progress1 =
          Math.floor(uniforms.progress.value + 1) % textures.length;

        const index = progress < 0 ? textures.length + progress : progress;
        const index2 = progress1 < 0 ? textures.length + progress1 : progress1;

        uniforms.tex1.value = textures[index];
        uniforms.tex2.value = textures[index2];
      }
    });
  };

  window.addEventListener("resize", resize);
  window.addEventListener("wheel", (e) => {
    if (isWheel) return;

    isWheel = true;
    delta += Math.sign(e.deltaY);

    gsap.to(uniforms.progress, 1, {
      value: delta,
      ease: Sine.easeOut,
      onUpdate: () => {
        const progress = Math.floor(uniforms.progress.value) % textures.length;
        const progress1 =
          Math.floor(uniforms.progress.value + 1) % textures.length;

        const index = progress < 0 ? textures.length + progress : progress;
        const index2 = progress1 < 0 ? textures.length + progress1 : progress1;

        uniforms.tex1.value = textures[index];
        uniforms.tex2.value = textures[index2];
      },
      onComplete: () => {
        isWheel = false;
      }
    });
  });

  addScene();
  update();
  resize();
})(document);

              
            
!
999px

Console