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="fragment-shader" type="x-shader/x-fragment">
  #define PI 3.1415926535897932384626433832795
    
  uniform vec2 dims;
  uniform float time;
  uniform float zNear, zFar;
  uniform sampler2D depthMap;
  
  varying vec2 _uv;
  vec2 u_k = vec2(20.0);
  
  // Source: http://www.bidouille.org/prog/plasma
  float plasma() { 
    float v = 0.0;
    vec2 c = _uv * u_k - u_k/2.0;
    v += sin((c.x+time));
    v += sin((c.y+time)/2.0);
    v += sin((c.x+c.y+time)/2.0);
    c += u_k/2.0 * vec2(sin(time/3.0), cos(time/2.0));
    v += sin(sqrt(c.x*c.x+c.y*c.y+1.0)+time);
    v = v/2.0;
    return sin(PI*v) * 0.5 + 0.5;
  }
  
  void main() {
    float solidsDepth = texture2D(depthMap, gl_FragCoord.xy / dims).r;
  
    float solidsDiff = 1.0 - smoothstep(zNear, zFar, gl_FragCoord.z / gl_FragCoord.w) - solidsDepth;
  
    float alpha = 0.1 * plasma();

    alpha += 0.3 + max(0.0, 1.0 - log(100.0 * (solidsDiff - 0.005) + 1.0));
  
    vec2 vignette = 2.0 * _uv - 1.0;
    alpha += 0.3 * (vignette.x * vignette.x + vignette.y * vignette.y);
  
    gl_FragColor = vec4(vec3(1.0), alpha);
  }
</script>

<script id="vertex-shader" type="x-shader/x-vertex">
  varying vec2 _uv;
  
  void main() {
    _uv = uv;
    gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
  }
</script>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
              
            
!

JS

              
                scene = new THREE.Scene!
solids = new THREE.Scene!

const z-near = 1
const z-far  = 1000

THREE.ImageUtils.cross-origin = ''
crate-texture = THREE.ImageUtils.load-texture 'http://crossorigin.me/http://i.imgur.com/CnkTvAG.gif'

box = new THREE.Mesh do
  new THREE.BoxGeometry 100, 100, 100
  new THREE.MeshBasicMaterial map: crate-texture
box.rotation.y = 0.25 * Math.PI
scene.add box

box.clone!
  ..material = new THREE.MeshDepthMaterial!
  solids.add ..

box = new THREE.Mesh do
  new THREE.BoxGeometry 100, 100, 100
  new THREE.MeshBasicMaterial map: crate-texture
box
  ..rotation
    ..x = 0.25 * Math.PI
    ..z = 0.2 * Math.PI
  ..position.x = -100
scene.add box

box.clone!
  ..material = new THREE.MeshDepthMaterial!
  solids.add ..

depth-map = new THREE.WebGLRenderTarget window.inner-width, window.inner-height, min-filter: THREE.LinearFilter, mag-filter: THREE.NearestFilter, format: THREE.RGBFormat

time-uniform =
  type: \f
  value: 0.0

dims-uniform =
  type: \v2
  value: new THREE.Vector2 window.inner-width, window.inner-height

shield = new THREE.Mesh do
  new THREE.PlaneGeometry 200, 200
  new THREE.ShaderMaterial do
    transparent: true
    uniforms:
      depth-map:
        type: \t
        value: depth-map
      dims: dims-uniform
      time: time-uniform
      z-near:
        type: \f
        value: z-near
      z-far:
        type: \f
        value: z-far
    vertex-shader: document.getElementById \vertex-shader .text-content
    fragment-shader: document.getElementById \fragment-shader .text-content
shield.position
  ..x = -5
  ..y = -5
  ..z = 50
scene.add shield

camera = new THREE.PerspectiveCamera 70, window.inner-width / window.inner-height, z-near, z-far
  ..position
    ..x = -100
    ..y = 100
    ..z = 400
  ..rotation
    ..x = -0.1 * Math.PI
    ..y = -0.1 * Math.PI 
    
renderer = new THREE.WebGLRenderer!
  ..set-pixel-ratio window.device-pixel-ratio
  ..set-size window.inner-width, window.inner-height
  document.body.append-child ..dom-element

window.add-event-listener \resize !->
  camera.aspect = window.inner-width / window.inner-height
  camera.update-projection-matrix!
  renderer.set-size window.inner-width, window.inner-height
  dims-uniform.value = new THREE.Vector2 window.inner-width, window.inner-height

tick = 0
animate = !->
  requestAnimationFrame animate
  shield.position.z = 50 + 100 * Math.sin tick += 0.05
  time-uniform.value += 0.01
  renderer.render solids, camera, depth-map
  renderer.render scene, camera

animate!
              
            
!
999px

Console