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 src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/three.min.js"></script>
<script id="vertexShader" type="x-shader/x-vertex">
    void main() {
        gl_Position = vec4( position, 1.0 );
    }
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
  uniform vec2 u_resolution;
  uniform vec2 u_mouse;
  uniform float u_time;
  uniform sampler2D u_noise;

  #define PI 3.14159265359
  #define TAU 6.283185307179586
  
  
  float tri( float x ) { 
    return abs( fract(x) - .5 );
  }

  vec3 tri3( vec3 p ){

    return vec3( 
        tri( p.z + tri( p.y * 1. ) ), 
        tri( p.z + tri( p.x * 1. ) ), 
        tri( p.y + tri( p.x * 1. ) )
    );

  }
  float triNoise3D( vec3 p, float spd , float time){

    float z  = 1.4;
    float rz =  0.;
    vec3  bp =   p;

    for( float i = 0.; i <= 3.; i++ ){

      vec3 dg = tri3( bp * 2. );
      p += ( dg + time * .1 * spd );

      bp *= 1.8;
      z  *= 1.5;
      p  *= 1.2; 

      float t = tri( p.z + tri( p.x + tri( p.y )));
      rz += t / z;
      bp += 0.14;

    }

    return rz;

  }
  

  void main() {
    
    float scale = .4;
    vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / min(u_resolution.y, u_resolution.x);
        
    vec3 highlightColour;
    vec3 bodyColour;
    vec3 bgColour = mix(vec3(0., .0, .1), vec3(.6,.45,.1) * .5, uv.y + .1);
    bgColour += (1. - length(uv * 1.5)) * .2;
    
    vec2 pos = uv / .5;
    float bottom = 0.5*(pos.y+1.0) * sin(u_time);
    vec2 wave = vec2(0.);
    wave.x += bottom*sin(4.0*pos.y-8.0*u_time)*.5;
    
    pos += .25*wave;
    pos.x += pos.x / (1.0-(pos.y));
    
    float flameMask = clamp(1.0-length(pos), 0.0, 1.0);
    flameMask = 1.0-pow(1.0-flameMask, 4.);
    
    bodyColour = mix(vec3(0.5,0.2,0.2), vec3(0.55,0.25,0.0), uv.y + flameMask);
    highlightColour = mix(vec3(1.0,.5,0.0), vec3(1.0,2.0,0.0), uv.y * (1. - flameMask * flameMask));
    
    vec3 uv3d = scale*0.1*vec3(uv.x, uv.y, 0.0);
    uv3d += vec3(0.0, -u_time*0.04, u_time*0.02);
    float noise = triNoise3D(uv3d * 5. + flameMask * .05, 0., u_time);
    noise = noise * 1.5 - .2;
    
    vec3 colour;
    
    float value = flameMask*noise;    
    value += .5*flameMask;

    float flame_edge = flameMask * 0.3*(pos.y+1.0);
    float edge = clamp(value-flame_edge*2., 0.0 , 1.0);
    float hardMask = smoothstep(flame_edge,flame_edge+0.1, value);
    float highlight = 1.0-edge*edge;
        
    uv3d = vec3(uv.x, uv.y, 0.0) + vec3(0.0, -u_time*0.01, u_time*0.025);

    highlight = pow(highlight, 2.0);
        
    // colour += glow * 2.;
    colour = highlightColour*(hardMask*highlight);
    colour = mix(bgColour, colour, hardMask);
    colour += bodyColour*flameMask*flameMask;
    
    gl_FragColor = vec4(colour,1.0);
  }
</script>


<div id="container" touch-action="none"></div>
            
          
!
            
              body {
  margin: 0;
  padding: 0;
}

#container {
  position: fixed;
  touch-action: none;
}
            
          
!
            
              /*
Most of the stuff in here is just bootstrapping. Essentially it's just
setting ThreeJS up so that it renders a flat surface upon which to draw 
the shader. The only thing to see here really is the uniforms sent to 
the shader. Apart from that all of the magic happens in the HTML view
under the fragment shader.
*/

let container;
let camera, scene, renderer;
let uniforms;

let loader=new THREE.TextureLoader();
let texture;
loader.setCrossOrigin("anonymous");
loader.load(
  'https://s3-us-west-2.amazonaws.com/s.cdpn.io/982762/noise.png',
  function do_something_with_texture(tex) {
    texture = tex;
    texture.wrapS = THREE.RepeatWrapping;
    texture.wrapT = THREE.RepeatWrapping;
    texture.minFilter = THREE.LinearFilter;
    init();
    animate();
  }
);

function init() {
  container = document.getElementById( 'container' );

  camera = new THREE.Camera();
  camera.position.z = 1;

  scene = new THREE.Scene();

  var geometry = new THREE.PlaneBufferGeometry( 2, 2 );

  uniforms = {
    u_time: { type: "f", value: 1.0 },
    u_resolution: { type: "v2", value: new THREE.Vector2() },
    u_noise: { type: "t", value: texture },
    u_mouse: { type: "v2", value: new THREE.Vector2() }
  };

  var material = new THREE.ShaderMaterial( {
    uniforms: uniforms,
    vertexShader: document.getElementById( 'vertexShader' ).textContent,
    fragmentShader: document.getElementById( 'fragmentShader' ).textContent
  } );
  material.extensions.derivatives = true;

  var mesh = new THREE.Mesh( geometry, material );
  scene.add( mesh );

  renderer = new THREE.WebGLRenderer();
  renderer.setPixelRatio( window.devicePixelRatio );

  container.appendChild( renderer.domElement );

  onWindowResize();
  window.addEventListener( 'resize', onWindowResize, false );

  document.addEventListener('pointermove', (e)=> {
    let ratio = window.innerHeight / window.innerWidth;
    uniforms.u_mouse.value.x = (e.pageX - window.innerWidth / 2) / window.innerWidth / ratio;
    uniforms.u_mouse.value.y = (e.pageY - window.innerHeight / 2) / window.innerHeight * -1;
    
    e.preventDefault();
  });
}

function onWindowResize( event ) {
  renderer.setSize( window.innerWidth, window.innerHeight );
  uniforms.u_resolution.value.x = renderer.domElement.width;
  uniforms.u_resolution.value.y = renderer.domElement.height;
}

function animate(delta) {
  requestAnimationFrame( animate );
  render(delta);
}






let capturer = new CCapture( { 
  verbose: true, 
  framerate: 60,
  // motionBlurFrames: 4,
  quality: 90,
  format: 'webm',
  workersPath: 'js/'
 } );
let capturing = false;

isCapturing = function(val) {
  if(val === false && window.capturing === true) {
    capturer.stop();
    capturer.save();
  } else if(val === true && window.capturing === false) {
    capturer.start();
  }
  capturing = val;
}
toggleCapture = function() {
  isCapturing(!capturing);
}

window.addEventListener('keyup', function(e) { if(e.keyCode == 68) toggleCapture(); });

let then = 0;
function render(delta) {
  
  uniforms.u_time.value = delta * 0.0005;
  renderer.render( scene, camera );
  
  if(capturing) {
    capturer.capture( renderer.domElement );
  }
}
            
          
!
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