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.

            
              <canvas id="view"></canvas>

<script id="flame-frag" type="x-shader/x-vertex">
    
  /**
   * Original shader by @kuvkar (https://www.shadertoy.com/view/4tXXRn) 
   */
  
  varying vec2 vTextureCoord;  
  
  uniform sampler2D uSampler;
  uniform sampler2D mapSampler;  
  uniform vec4 filterArea;  
  uniform vec2 dimensions;
  uniform float time;
  
  float rand(vec2 co) {
    return fract(sin(dot(co.xy ,vec2(12.9898, 78.233))) * 43758.5453);
  }
  
  mat2 rotz(float angle) {
    mat2 m;
    m[0][0] = cos(angle); m[0][1] = -sin(angle);
    m[1][0] = sin(angle); m[1][1] = cos(angle);
    return m;
  }  
  
  // Fractal Brownian Motion
  float fbm(vec2 uv) {        
    
    float n = (texture2D(mapSampler, uv).r - 0.5) * 0.5;
    n += (texture2D(mapSampler, uv * 2.0).r - 0.5) * 0.5 * 0.5;
    n += (texture2D(mapSampler, uv * 3.0).r - 0.5) * 0.5 * 0.5 * 0.5;    
    return n + 0.5;    
  }
  
  void main() {
    
    vec2 uv = (vTextureCoord * filterArea.xy) / dimensions;
    uv.y = 1.0 - uv.y;
    
    vec2 _uv = uv;
    uv -= vec2(0.5);
    uv.y /= dimensions.x / dimensions.y;      
    
    vec2 centerUV = uv;
    
    // height variation from fbm
    float variationH = fbm(vec2(time * 0.3)) * 1.1;
    
    // flame "speed"
    vec2 offset = vec2(0.0, -time * 0.05);
        
    // flame turbulence
    float f = fbm(uv * 0.1 + offset); // rotation from fbm        
    float l = max(0.1, length(uv)); // rotation amount normalized over distance
	  uv += rotz(((f - 0.5) / l) * smoothstep(-0.2, 0.4, _uv.y) * 0.45) * uv;    
    
    // flame thickness
    float flame = 1.3 - length(uv.x) * 5.0;
    
    // bottom of flame 
    float blueflame = pow(flame * 0.9, 15.0);
    blueflame *= smoothstep(0.2, -1.0, _uv.y);
    blueflame /= abs(uv.x * 2.0);
    blueflame = clamp(blueflame, 0.0, 1.0);
    
    // flame
    flame *= smoothstep(1.0, variationH * 0.5, _uv.y);
	  flame = clamp(flame, 0.0, 1.0);
    flame = pow(flame, 3.0);
    flame /= smoothstep(1.1, -0.1, _uv.y);    
	
    // colors
    vec4 col = mix(vec4(1.0, 1.0, 0.0, 0.0), vec4(1.0, 1.0, 0.6, 0.0), flame);
    col = mix(vec4(1.0, 0.0, 0.0, 0.0), col, smoothstep(0.0, 1.6, flame));
    gl_FragColor = col;
    
	  // a bit blueness on the bottom
    vec4 bluecolor = mix(vec4(0.0, 0.0, 1.0, 0.0), gl_FragColor, 0.95);
    gl_FragColor = mix(gl_FragColor, bluecolor, blueflame);
    
    // clear bg outside of the flame
    gl_FragColor *= flame;
    gl_FragColor.a = flame;
    
    // bg halo
    float haloSize = 0.5;
    float centerL = 1.0 - (length(centerUV + vec2(0.0, 0.1)) / haloSize);
    vec4 halo = vec4(0.8, 0.3, 0.3, 0.0) * 1.0 * fbm(vec2(time * 0.035)) * centerL + 0.02;
    vec4 finalCol = mix(halo, gl_FragColor, gl_FragColor.a);
    gl_FragColor = finalCol;

    // just a hint of noise
    gl_FragColor *= mix(rand(uv) + rand(uv * 0.45), 1.0, 0.9);
    gl_FragColor = clamp(gl_FragColor, 0.0, 1.0);
  }
</script>
            
          
!
            
              body {
  background: #000;
}

#view {
  position: fixed;
  top: 0;
  left: 0;
}
            
          
!
            
              console.clear();

const flameFrag = document.querySelector("#flame-frag").textContent;
const baseUrl = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/106114/";

const manifest = [
  { name: "noise", url: "noise-texture-11.png?v=9" }
];


//
// FLAME FILTER
// ===========================================================================
class FlameFilter extends PIXI.Filter {
  
  constructor(texture, time = 0.0) {    
    super(null, flameFrag);
       
    this.uniforms.dimensions = new Float32Array(2);   
    this.texture = texture;
    this.time = time;
  }
  
  get texture() {
    return this.uniforms.mapSampler;
  }
  
  set texture(texture) {
    texture.baseTexture.wrapMode = PIXI.WRAP_MODES.REPEAT;
    this.uniforms.mapSampler = texture;
  }
  
  apply(filterManager, input, output, clear) {
          
    this.uniforms.dimensions[0] = input.sourceFrame.width;
    this.uniforms.dimensions[1] = input.sourceFrame.height;    
    this.uniforms.time = this.time;

    filterManager.applyFilter(this, input, output, clear);
  }
}


//
// APPLICATION
// ===========================================================================
class Application extends PIXI.Application {
    
  constructor() {
    
    if (window.devicePixelRatio > 1) {
      PIXI.settings.RESOLUTION = 2;
    }
    
    PIXI.settings.PRECISION_FRAGMENT = "highp";
    
    super({
      view: document.querySelector("#view"),
      width: window.innerWidth,
      height: window.innerHeight,
      backgroundColor: 0x000000,
      autoResize: true
    });   
    
    this.isResized = true;    
    this.loader.baseUrl = baseUrl;   
  }
    
  load(manifest) {
    
    this.loader
      .add(manifest)
      .load((l, r) => this.init(r));   
  }
    
  init(resources) {     
        
    this.flame = new FlameFilter(resources.noise.texture);
       
    this.stage.filterArea = this.screen;
    this.stage.filters = [this.flame];
       
    this.ticker.add(this.update, this);                     
    window.addEventListener("resize", () => this.isResized = true);
  }
   
  update(delta) {
    
    if (this.isResized) {
      this.renderer.resize(window.innerWidth, window.innerHeight);
      this.isResized = false;
    }
    
    this.flame.time += 0.1 * delta;
  }
}

const app = new Application();
app.load(manifest);

            
          
!
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