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">
  uniform float time;
  uniform vec2 resolution;
  uniform float fogDensity;
  uniform vec3 fogColor;
  uniform sampler2D texture1;
  uniform sampler2D texture2;
  varying vec2 vUv;
  void main( void ) {
    vec2 position = -1.0 + 2.0 * vUv;
    vec4 noise = texture2D( texture1, vUv );
    vec2 T1 = vUv + vec2( 1.5, -1.5 ) * time  *0.02;
    vec2 T2 = vUv + vec2( -0.5, 2.0 ) * time * 0.01;
    T1.x += noise.x * 2.0;
    T1.y += noise.y * 2.0;
    T2.x -= noise.y * 0.2;
    T2.y += noise.z * 0.2;
    float p = texture2D( texture1, T1 * 2.0 ).a;
    vec4 color = texture2D( texture2, T2 * 2.0 );
    vec4 temp = color * ( vec4( p, p, p, p ) * 2.0 ) + ( color * color - 0.1 );
    if( temp.r > 1.0 ){ temp.bg += clamp( temp.r - 2.0, 0.0, 100.0 ); }
    if( temp.g > 1.0 ){ temp.rb += temp.g - 1.0; }
    if( temp.b > 1.0 ){ temp.rg += temp.b - 1.0; }
    gl_FragColor = temp;
    float depth = gl_FragCoord.z / gl_FragCoord.w;
    const float LOG2 = 1.442695;
    float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );
    fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );
    gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );
  }
</script>
<script id="vertexShader" type="x-shader/x-vertex">
  uniform vec2 uvScale;
  varying vec2 vUv;
  void main()
  {
    vUv = uvScale * uv;
    vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
    gl_Position = projectionMatrix * mvPosition;
  }
</script>
              
            
!

CSS

              
                body {
  overflow: hidden;
  background-color: #000;
}
canvas {
  width: 100%;
  height: 100%;
}
              
            
!

JS

              
                (function(parent, W, H) {
  
  var
  stats = new Stats(),
  clock = new THREE.Clock(),
  scene = new THREE.Scene(),
  camera = new THREE.PerspectiveCamera( 75, W / H, 0.1, 1000 ),
  uniforms = {
    fogDensity: { type: "f", value: 0.45 },
    fogColor: { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) },
    time: { type: "f", value: 1.0 },
    resolution: { type: "v2", value: new THREE.Vector2() },
    uvScale: { type: "v2", value: new THREE.Vector2( 3.0, 1.0 ) },
    texture1: { type: "t", value: THREE.ImageUtils.loadTexture( "" ) },
    texture2: { type: "t", value: THREE.ImageUtils.loadTexture( "" ) }
  },
  material = new THREE.ShaderMaterial( {
    uniforms: uniforms,
    vertexShader: document.getElementById( 'vertexShader' ).textContent,
    fragmentShader: document.getElementById( 'fragmentShader' ).textContent
  } ),
  mesh = new THREE.Mesh( new THREE.TorusKnotGeometry( 0.8, 0.5, 100, 100 ), material ),
  renderer = new THREE.WebGLRenderer({
    antialias: true,
    alpha: true
  }),
  render = function () {
    requestAnimationFrame( render );
    stats.begin();
    var delta = 5 * clock.getDelta();
    uniforms.time.value += 0.2 * delta;
    renderer.render(scene, camera);
    stats.end();
  },
  loadTexture = function(url, uniform, cb){
    var image = document.createElement( 'img' );
    image.crossOrigin = '';
    var texture = new THREE.Texture( image );
    image.onload = function()  {
      texture.needsUpdate = true;
      uniform.value = texture;
      uniform.value.wrapS = uniform.value.wrapT = THREE.RepeatWrapping;
      if (typeof(cb) !== 'undefined'){
        cb(this);
      }
    };
    image.src = url;
  };
  loadTexture('https://dl.dropboxusercontent.com/u/48498161/codepen/QwyxZN/cloud.png', uniforms.texture1 );
  loadTexture('https://dl.dropboxusercontent.com/u/48498161/codepen/QwyxZN/lavatile.jpg', uniforms.texture2 );

  renderer.setSize( W, H );
  camera.position.z = 3;

  scene.add( mesh );

  THREEx.WindowResize(renderer, camera);
  
  stats.domElement.style.position = 'absolute';
  stats.domElement.style.top = '5px';
  stats.domElement.style.left = '5px';

  parent.appendChild( renderer.domElement );
  parent.appendChild( stats.domElement );
  render();
})(
  document.body,
  window.innerWidth,
  window.innerHeight
);
              
            
!
999px

Console