css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <script id="vertexShader" type="x-shader/x-vertex">
precision mediump float;
attribute vec2 position;
varying vec2 uv;
void main() {
  uv = position;
  gl_Position = vec4(2. * position - 1., 0., 1.);
}
</script>
<script id="highlightFragShader" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D txFeedback;
uniform sampler2D txFrame;
varying vec2 uv;

// from https://github.com/Jam3/glsl-fast-gaussian-blur
vec4 blur9(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
  vec4 color = vec4(0.0);
  vec2 off1 = vec2(1.3846153846) * direction;
  vec2 off2 = vec2(3.2307692308) * direction;
  color += texture2D(image, uv) * 0.2270270270;
  color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;
  color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;
  color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;
  color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;
  return color;
}
 
void main () {
  vec3 feedback = texture2D(txFeedback, uv).rgb;
  vec3 blurred = blur9(txFrame, uv, vec2(512.), vec2(0,1)).rgb;
  vec4 frame = texture2D(txFrame, uv);
  gl_FragColor = vec4(
    1.6*feedback.r - (1.3*blurred.r*(1.-frame.a)) + 2.7*frame.r*frame.a,
    1.6*feedback.g - (1.3*blurred.g*(1.-frame.a)) + 2.7*frame.g*frame.a,
    1.6*feedback.b - (1.3*blurred.b*(1.-frame.a)) + 2.7*frame.b*frame.a,
    1.0
  );
}
</script>
<script id="feedbackFragShader" type="x-shader/x-fragment">
precision mediump float;
uniform float time;
uniform sampler2D txFeedback;
uniform sampler2D txFrame;
varying vec2 uv;

void main () {
  vec2 distortPos = uv + 0.01 * sin(time) * vec2(0.5 - uv.y, uv.x - 0.5) - 0.01 * (uv - 0.5);
  vec3 feedback = 0.76 * texture2D(txFeedback, distortPos).rgb;
  vec3 frame = texture2D(txFrame, uv).rgb;
  gl_FragColor = vec4(
    max(feedback.r, frame.r),
    max(feedback.g, frame.g),
    max(feedback.b, frame.b),
    1.0
  );
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
precision mediump float;
uniform vec2 resolution;
uniform float time;
uniform sampler2D txImage;

varying vec2 uv;

mat2 rot2d(float theta) {
  return mat2(
    cos(theta), -sin(theta),
    sin(theta), cos(theta)
  );
}

mat2 scale2d(float scale) {
  return mat2(
    scale, 0.0,
    0.0, scale
  );
}

void main(void) {
  vec2 initial = uv;
  initial.x = 0.5 - (initial.x - 0.5) * resolution.x / resolution.y;

  vec4 col = vec4(
    clamp(initial.x*1.3, 0., 1.),
    clamp(initial.y*1.3, 0., 1.),
    0.6,
    1.0
  );
  
  // save scaling
  vec2 pos = scale2d(1.3-0.1*pow(sin(time*2.),8.)) * (initial-0.5);
  float outer = texture2D(txImage, pos + 0.5).g;

  float text = texture2D(txImage, rot2d(-0.2*time) * pos + 0.5).r;
  
  float timescale = time + 0.4 * (sin(exp(cos(time*0.5))*2.));
  float tri1 = texture2D(txImage, rot2d(1.*timescale) * pos + 0.5).b;
  float tri2 = texture2D(txImage, rot2d(2.*timescale) * pos + 0.5).b;
  float tri3 = texture2D(txImage, rot2d(3.*timescale) * pos + 0.5).b;
  
  gl_FragColor = col * (
    text + 0.7 * outer + tri1 + tri2 + tri3
  );
}
</script>
            
          
!
            
              html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
body {
  background: #232428;
}
canvas {
  width: 100%;
  height: 100%;
}

            
          
!
            
              const container = document.createElement('canvas');
document.body.appendChild(container);
var regl = createREGL(container);

var patternTexture = new Image();
patternTexture.crossOrigin = 'anonymous';
patternTexture.onload = function () {
  initShader(container, patternTexture);
}
patternTexture.src = 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/168886/tex-magicCircle-01.png';

function initShader(canvas, image) {
  keepFullSize(canvas);
  
  const frameTexture = regl.texture({
    copy: true,
    min: 'linear',
    mag: 'linear'
  });
  const feedbackTexture = regl.texture({
    copy: true,
    min: 'linear',
    mag: 'linear'
  });

  const drawFrame = regl({
    vert: document.getElementById('vertexShader').textContent,
    frag: document.getElementById('fragmentShader').textContent,
    attributes: { position: [-2, 0, 0, -2, 2, 2] },
    count: 3,
    uniforms: {
      resolution: ({ viewportWidth, viewportHeight }) => [
        viewportWidth,
        viewportHeight
      ],
      time: regl.context('time'),
      txImage: regl.texture(image)
    },
    depth: {enable: false}
  });

  const drawFeedback = regl({
    vert: document.getElementById('vertexShader').textContent,
    frag: document.getElementById('feedbackFragShader').textContent,
    attributes: { position: [-2, 0, 0, -2, 2, 2] },
    count: 3,
    uniforms: {
      time: regl.context('time'),
      txFeedback: feedbackTexture,
      txFrame: frameTexture
    },
    depth: {enable: false},
  });

  const drawHighlight = regl({
    vert: document.getElementById('vertexShader').textContent,
    frag: document.getElementById('highlightFragShader').textContent,
    attributes: { position: [-2, 0, 0, -2, 2, 2] },
    count: 3,
    uniforms: {
      txFeedback: feedbackTexture,
      txFrame: frameTexture
    }
  });

  regl.frame(() => {
    drawFrame();
    frameTexture({
      copy: true,
      min: 'linear',
      mag: 'linear'
    });
    drawFeedback();
    feedbackTexture({
      copy: true,
      min: 'linear',
      mag: 'linear'
    });
    drawHighlight();
  })
}

// Utils
const setFullSize = el => {
  el.setAttribute('width', window.innerWidth);
  el.setAttribute('height', window.innerHeight);
};
const keepFullSize = el => {
  window.addEventListener( 'resize', setFullSize.bind(null, el), false);
  setFullSize(el);
};

            
          
!
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.
Loading ..................

Console