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="vertexShader" type="x-shader/x-vertex">
varying vec2 vUv;
void main()
{
    vUv = uv;
    gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif

uniform float time;
uniform sampler2D texture;
varying vec2 vUv;

void main( void ) {
  gl_FragColor = vec4(
    texture2D(texture, vec2(vUv.x, 0.5 + vUv.y/2.)).rgb,
    texture2D(texture, vec2(vUv.x, vUv.y/2.)).r
  );
}
</script>
<video id="video" autoplay loop webkit-playsinline crossorigin="anonymous">
  <source src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/39255/spaceships.mp4?t=1" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
</video>
<div id="demo-wrapper">
  <div id="container"></div>
  <p class="editable-text text-front" contenteditable="true">the video is an MP4, but it's transparent thanks to WebGL</p>
  <p class="editable-text text-behind" contenteditable="true"><strong>Update:</strong> Autoplay no longer works; click "play" in the bar below</p>
</div>
<div id="info">Transparent Video GLSL shader - with <a href="https://threejs.org" target="_blank">three.js</a>
</div>
<div id="controls">
  <label for="resolution">resolution: </label>
  <select id="resolution" value="2">
    <option value="0.5">0.5x</option>
    <option value="1" selected>1x</option>
    <option value="2">2x</option>
    <option value="4">4x</option>
    <option value="8">8x</option>
  </select>
  <label for="play-button">video controls: </label>
  <button id="play-button">Play</button>
  <button id="stop-button">Stop</button>
</div>
              
            
!

CSS

              
                body {
  width: 100%;
  height: 100vh;
  color: #ffffff;
  font-family: Monospace;
  font-size: 13px;
  text-align: center;
  font-weight: bold;
  margin: 0px;
  overflow: hidden;
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/168886/vector-landscape.jpg) center center no-repeat;
  background-size: cover;
}
#video {
  display: none;
  // position: absolute;
  // right: 0;
  // top: 0;
  // transform-origin: 100% 0%;
  // transform: scale(0.2);
}
#container {
  pointer-events: none;
  z-index: 5;
  position: absolute;
  left: 50%;
  top: 0;
  width: 100vh;
  height: 100vh;
  transform: translateX(-50%);
}
#demo-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100vh;
}
.editable-text {
  position: relative;
  padding: 0.5em 1em;
  margin: 0;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 8vh;
  font-weight: 300;
  letter-spacing: 0.07em;
  color: #fff;
  text-align: center;
  text-shadow: 2px 5px 20px rgba(#000000, 0.6);
  &.text-behind {
    z-index: 1;
  }
  &.text-front {
    z-index: 10;
  }
}
#info, #controls {
  z-index: 100;
  position: absolute;
  width: 100%;
  padding: 5px;
  background: rgba(#000,0.4);
}
#info { top: 0; }
#controls { bottom: 0; }
a {
  color: #ffffff;
  transition: 150ms all;
  &:hover, &:focus {
    color: #ffc107;
  }
}

              
            
!

JS

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

function init(showStats) {
  // stats
  if (showStats) {
    var stats = new Stats();
    stats.domElement.style.zIndex = '200';
    stats.domElement.style.position = 'absolute';
    stats.domElement.style.left = '0';
    stats.domElement.style.top = '0';
    document.body.appendChild(stats.domElement);
    requestAnimationFrame(function updateStats(){
      stats.update();
      requestAnimationFrame(updateStats);
    });
  }
  
  // basic setup
  container = document.getElementById( 'container' );
  camera = new THREE.Camera();
  camera.position.z = 1;
  scene = new THREE.Scene();
  
  // load video
  var video = document.getElementById( 'video' );
  videoTexture = new THREE.VideoTexture( video );
  videoTexture.minFilter = THREE.LinearFilter;
  videoTexture.magFilter = THREE.LinearFilter;
  videoTexture.format = THREE.RGBFormat;

  // shader stuff
  uniforms = {
    time: { type: "f", value: 1.0 },
    texture: { type: "sampler2D", value: videoTexture }
  };
  var material = new THREE.ShaderMaterial( {
    uniforms: uniforms,
    vertexShader: document.getElementById( 'vertexShader' ).textContent,
    fragmentShader: document.getElementById( 'fragmentShader' ).textContent,
    transparent: true
  } );
  lastUpdate = new Date().getTime();

  // put it together for rendering
  var geometry = new THREE.PlaneBufferGeometry( 2, 2 );
  var mesh = new THREE.Mesh( geometry, material );
  mesh.scale.setScalar(0.8);
  scene.add( mesh );
  renderer = new THREE.WebGLRenderer({ alpha: true });
  renderer.setPixelRatio( window.devicePixelRatio / parseFloat(document.getElementById('resolution').value) );
  container.appendChild( renderer.domElement );
  
  // event listeners
  document.getElementById('play-button').addEventListener('click', e => { video.play(); });
  document.getElementById('stop-button').addEventListener('click', e => { video.pause(); });
  onWindowResize();
  window.addEventListener( 'resize', onWindowResize, false);
  document.getElementById('resolution').addEventListener('change', onResolutionChange, false);
}

// events
function onWindowResize(evt) {
  renderer.setSize( window.innerHeight, window.innerHeight );
}
function onResolutionChange(evt) {
  var newResolutionScale = parseFloat(evt.target.value);
  renderer.setPixelRatio( window.devicePixelRatio / newResolutionScale );
}
function animate() {
  var currentTime = new Date().getTime()
  var timeSinceLastUpdate = currentTime - lastUpdate;
  lastUpdate = currentTime;
  
  requestAnimationFrame( animate );
  render(timeSinceLastUpdate);
}
function render(timeDelta) {
  uniforms.time.value += (timeDelta ? timeDelta / 1000 : 0.05);
  renderer.render( scene, camera );
}

// boot
init(true);
animate();

              
            
!
999px

Console