Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <script id="fragmentShader" type="x-shader/x-fragment">
  
  varying vec2 vUv;
  uniform float dispFactor;
  uniform sampler2D disp;
  uniform sampler2D map1;
  uniform sampler2D map2;
  uniform float intensity;
  uniform bool direction;
    float random(vec3 scale,float seed)
  {
    return fract(  sin(dot(gl_FragCoord.xyz+seed,scale))*43758.5453  +  seed  );
  }

  void main()
  {
    const float iterations = 25.;//float(quality+1)*25.;
    vec2 pos = vUv;//gl_FragCoord.xy / RENDERSIZE;
    vec4 color = vec4(0.);
    float total = 0.;
    vec2 toCenter = vec2(0.5, 0.5) - pos;
    float offset = random(  vec3(12.9898,78.233,151.7182), 0.  );
    for(float t=0.; t<=iterations; t++)
    {
      float percent = (t+offset)/iterations;
      float weight = 4.0*(percent-percent*percent);
      vec4 sample1 = texture2D(map1, pos+toCenter*percent*intensity*dispFactor);
      vec4 sample2 = vec4(0.0);
      if(!direction)
      {
        sample2 = texture2D(map2, pos+toCenter*percent*intensity*(-1.0+dispFactor));
      } else {
        sample2 = texture2D(map2, pos+toCenter*percent*intensity*(1.0-dispFactor));
      }

      vec4 sample = mix(sample1, sample2, dispFactor);

      sample.rgb *= sample.a;
      color += sample*weight;
      total += weight;
    }
    gl_FragColor = color/total;
    gl_FragColor.rgb /= max(gl_FragColor.a,0.00001);
  }
</script>
<script id="vertexShader" type="x-shader/x-vertex">
	varying vec2 vUv;
  void main() {
    vUv = uv;
    gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  }

</script> 
<div id="container">
  <video src="https://robindelaporte.fr/codepen/video3.mp4" crossorigin="anonymous" id="video" muted="true" loop="true"></video>
  <video src="https://robindelaporte.fr/codepen/video2.mp4" crossorigin="anonymous" id="video2" muted="true" loop="true"></video>
  </div>
</div>
              
            
!

CSS

              
                body {
  color: #ffffff;
  font-family: Monospace;
  font-size: 13px;
  text-align: center;
  font-weight: bold;
  background-color: #000000;
  margin: 0px;
  overflow: hidden;
}

video {
  display: none;
}
              
            
!

JS

              
                var lastUpdate;
var container;
var camera, scene, renderer;
var uniforms;

function init() {
  // basic setup
  container = document.getElementById("container");
  camera = new THREE.Camera();
  camera.position.z = 1;
  scene = new THREE.Scene();
  var geometry = new THREE.PlaneBufferGeometry(2, 2);

  const map = document.querySelector("#video");
  map.oncanplay = function() {
    map.play();
  };
  const texture = new THREE.VideoTexture(map);
  texture.minFilter = THREE.LinearFilter;

  const map2 = document.querySelector("#video2");
  map2.oncanplay = function() {
    map2.play();
  };
  const texture2 = new THREE.VideoTexture(map2);
  texture2.minFilter = THREE.LinearFilter;

  // shader stuff
  uniforms = {
    intensity: { type: "f", value: 0.75 },
    dispFactor: { type: "f", value: 0.0 },
    direction: { type: "b", value: false },
    map1: { type: "t", value: texture },
    map2: { type: "t", value: texture2 }
  };
  var material = new THREE.ShaderMaterial({
    uniforms: uniforms,
    vertexShader: document.getElementById("vertexShader").textContent,
    fragmentShader: document.getElementById("fragmentShader").textContent
  });
  
  lastUpdate = new Date().getTime();
  // put it together for rendering
  var mesh = new THREE.Mesh(geometry, material);
  scene.add(mesh);
  renderer = new THREE.WebGLRenderer();
  renderer.setPixelRatio(window.devicePixelRatio);
  container.appendChild(renderer.domElement);

  // event listeners
  onWindowResize();
  window.addEventListener("resize", onWindowResize, false);

  // gui
  this.GUI = new dat.GUI();
  this.GUI.add(uniforms.intensity, "value", 0, 2, 0.01).name("intensity");
  this.GUI.add(uniforms.dispFactor, "value", 0, 1, 0.01).name("transition");

  this.guiObj = {
    reverse: false
  };
  this.GUI.add(this.guiObj, "reverse")
    .listen()
    .onChange(() => {
      uniforms.direction.value = this.guiObj.reverse;
    });

  var self = this;
  var obj = {
    animate: () => {
      var t = 1;
      if (this._value == 1) {
        t = 0;
      }
      TweenMax.to(uniforms.dispFactor, 1.1, {
        value: t,
        ease: Expo.easeOut
      });

      if (this._value == 1) {
        this._value = 0;
      } else {
        this._value = 1;
      }
    }
  };
  this.GUI.add(obj, "animate");
}

// events
function onWindowResize(evt) {
  renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
  var currentTime = new Date().getTime();
  var timeSinceLastUpdate = currentTime - lastUpdate;
  lastUpdate = currentTime;

  requestAnimationFrame(animate);
  render(timeSinceLastUpdate);
}
function render(timeDelta) {
  renderer.render(scene, camera);
}

// boot
init();
animate();

              
            
!
999px

Console