123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              html, body {
  height: 100%;
  width: 100%;
  background: #111;
}
body {
  display: flex;
  align-items: center;
  justify-content: center;
}
            
          
!
            
              // 📈 Track FPS
var stats = new Stats();
stats.domElement.style.position = "absolute";
stats.domElement.style.bottom = "-48px";
stats.domElement.style.right = "0px";
stats.domElement.style.zIndex = 100;
document.getElementById("container").appendChild(stats.domElement);

const uniformData = {
  time: {
    type: 'float',
    value: 0.0
  },
  lacunarity: {
    type: 'float',
    value: 30.0
  },
  gain: {
    type: 'float',
    value: 1.0
  },
  parallel: {
    type: 'b',
    value: true
  },
  light: {
    type: 'v2',
    value: [0.0, 0.0]
  },
  dimensions: {
    type: 'v2',
    value: [960, 640]
  },
  aspect: {
    type: 'float',
    value: 1.0
  }
};

const fragSource = 
`
precision mediump float;

varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform vec4 filterArea;
uniform vec2 dimensions;

uniform vec2 light;
uniform bool parallel;
uniform float aspect;

uniform float gain;
uniform float lacunarity;
uniform float time;

// 3D gradient Noise
// MIT License
// Copyright © 2013 Inigo Quilez
// https://www.shadertoy.com/view/Xsl3Dl

vec3 hash(vec3 p) {
  p = vec3(dot(p, vec3(127.1, 311.7, 74.7)), dot(p, vec3(269.5, 183.3, 246.1)),
           dot(p, vec3(113.5, 271.9, 124.6)));

  return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);
}

float noise(in vec3 p) {
  vec3 i = floor(p);
  vec3 f = fract(p);

  vec3 u = f * f * (3.0 - 2.0 * f);

  return mix(
      mix(mix(dot(hash(i + vec3(0.0, 0.0, 0.0)), f - vec3(0.0, 0.0, 0.0)),
              dot(hash(i + vec3(1.0, 0.0, 0.0)), f - vec3(1.0, 0.0, 0.0)), u.x),
          mix(dot(hash(i + vec3(0.0, 1.0, 0.0)), f - vec3(0.0, 1.0, 0.0)),
              dot(hash(i + vec3(1.0, 1.0, 0.0)), f - vec3(1.0, 1.0, 0.0)), u.x),
          u.y),
      mix(mix(dot(hash(i + vec3(0.0, 0.0, 1.0)), f - vec3(0.0, 0.0, 1.0)),
              dot(hash(i + vec3(1.0, 0.0, 1.0)), f - vec3(1.0, 0.0, 1.0)), u.x),
          mix(dot(hash(i + vec3(0.0, 1.0, 1.0)), f - vec3(0.0, 1.0, 1.0)),
              dot(hash(i + vec3(1.0, 1.0, 1.0)), f - vec3(1.0, 1.0, 1.0)), u.x),
          u.y),
      u.z);
}

const mat3 m = mat3(0.00, 0.80, 0.60, -0.80, 0.36, -0.48, -0.60, -0.48, 0.64);

float turb(vec3 pos, float lacunarity, float gain ) {
  float f;
  vec3 q = 8.0 * pos;
  f = gain * noise(q);
  q = m * q * 2.01 * lacunarity;
  f += (gain * gain) * noise(q);
  q = m * q * 2.02 * lacunarity;
  f += (gain * gain * gain) * noise(q);
  q = m * q * 2.03 * lacunarity;
  f += (gain * gain * gain * gain) * noise(q);
  q = m * q * 2.01 * lacunarity;
  f = 0.5 + 0.5 * f;
  return clamp(f, 0.0, 1.0);
}

void main(void) {
  gl_FragColor = texture2D(uSampler, vTextureCoord);

  float d = 0.0;
  vec2 coord = vTextureCoord;// * filterArea.xy / dimensions.xy;
  if (parallel) {
    float _cos = light.x;
    float _sin = light.y;
    d = (_cos * coord.x) + (_sin * coord.y * aspect);
  } else {
    float dx = coord.x - light.x / dimensions.x;
    float dy = (coord.y - light.y / dimensions.y) * aspect;
    float dis = sqrt(dx * dx + dy * dy) + 0.00001;
    d = dy / dis;
  }
  vec2 dir = vec2(d, d);
  float noise = turb(vec3(dir, time), lacunarity, gain);
  noise = mix(noise, 0.0, 0.3);
  // fade vertically
  vec4 mist = vec4(noise, noise, noise, 1.0);
  mist = clamp(mist, 0.0, 1.0);
  mist *= 1.0 - coord.y;
  mist = clamp(mist, 0.0, 1.0);

  gl_FragColor += mist;
}
`;

/*
 * Shader Start
 */
var startTime = Date.now();
var filter = new PIXI.Filter(null, fragSource, uniformData);
filter.apply = function(filterManager, input, output)
{
  this.uniforms.time = 0.0001 * (Date.now() - startTime);
  this.uniforms.angle = 15.0;
  this.uniforms.lacunarity = 1.0;
  this.uniforms.gain = .3;
  
  const radians = 30.0 * Math.PI / 180.0;

  this.uniforms.light[0] = Math.cos(radians);
  this.uniforms.light[1] = Math.sin(radians);
  
  const {width, height} = input.filterFrame;
  this.uniforms.dimensions[0] = width;
  this.uniforms.dimensions[1] = height;

  this.uniforms.aspect = height / width;
  this.uniforms.parallel = true;
  
  // draw the filter...
  filterManager.applyFilter(this, input, output);
}
/*
 * Pixi Start
 */
PIXI.RENDERER_TYPE = PIXI.WEBGL;
var app = new PIXI.Application(960, 640, {backgroundColor : 0xaa0322, resolution: window.devicePixelRatio});
document.getElementById("container").appendChild(app.view);

var container = new PIXI.Container();
container.scale.x = container.scale.y = 2;

var graphics = new PIXI.Graphics();
graphics.beginFill(0x1e1f26);
graphics.drawRect(0, 0, 480, 320);
graphics.filterArea = app.screen;
container.filters = [filter];
container.addChild(graphics);

app.stage.addChild(container);

requestAnimationFrame(animate);

function animate() {
  requestAnimationFrame(animate);
  app.render();
  stats.update();
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console