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

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.

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

              
                <!-- Particle animation ideas using Curl noise are from this great turotial video by Yuri Artiukh
* FBO Particles with Three.js #10
https://www.youtube.com/watch?v=oLH00MXTqNg -->

<script id="vs" type="x-shader/x-vertex">
uniform float time;
uniform float progress;
varying vec2 vUv;
varying vec3 vPosition;
uniform sampler2D texture;
float PI = 3.141592653589793238462643383279;
  
  

//
// Description : Array and textureless GLSL 2D simplex noise function.
//      Author : Ian McEwan, Ashima Arts.
//  Maintainer : ijm
//     Lastmod : 20110822 (ijm)
//     License : Copyright (C) 2011 Ashima Arts. All rights reserved.
//               Distributed under the MIT License. See LICENSE file.
//               https://github.com/ashima/webgl-noise
//

vec3 mod289(vec3 x) {
    return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec2 mod289(vec2 x) {
    return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec3 permute(vec3 x) {
    return mod289(((x*34.0)+1.0)*x);
}

float noise(vec2 v)
{
    const vec4 C = vec4(0.211324865405187,  // (3.0-sqrt(3.0))/6.0
    0.366025403784439,  // 0.5*(sqrt(3.0)-1.0)
    -0.577350269189626,  // -1.0 + 2.0 * C.x
    0.024390243902439); // 1.0 / 41.0
    // First corner
    vec2 i  = floor(v + dot(v, C.yy) );
    vec2 x0 = v -   i + dot(i, C.xx);

    // Other corners
    vec2 i1;
    //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
    //i1.y = 1.0 - i1.x;
    i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
    // x0 = x0 - 0.0 + 0.0 * C.xx ;
    // x1 = x0 - i1 + 1.0 * C.xx ;
    // x2 = x0 - 1.0 + 2.0 * C.xx ;
    vec4 x12 = x0.xyxy + C.xxzz;
    x12.xy -= i1;

    // Permutations
    i = mod289(i); // Avoid truncation effects in permutation
    vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
    + i.x + vec3(0.0, i1.x, 1.0 ));

    vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
    m = m*m ;
    m = m*m ;

    // Gradients: 41 points uniformly over a line, mapped onto a diamond.
    // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)

    vec3 x = 2.0 * fract(p * C.www) - 1.0;
    vec3 h = abs(x) - 0.5;
    vec3 ox = floor(x + 0.5);
    vec3 a0 = x - ox;

    // Normalise gradients implicitly by scaling m
    // Approximation of: m *= inversesqrt( a0*a0 + h*h );
    m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );

    // Compute final noise value at P
    vec3 g;
    g.x  = a0.x  * x0.x  + h.x  * x0.y;
    g.yz = a0.yz * x12.xz + h.yz * x12.yw;
    return 130.0 * dot(m, g);
}

vec3 curl(float	x,	float	y,	float	z)
{

    float	eps	= 1., eps2 = 2. * eps;
    float	n1,	n2,	a,	b;

    x += time * .05;
    y += time * .05;
    z += time * .05;

    vec3	curl = vec3(0.);

    n1	=	noise(vec2( x,	y	+	eps ));
    n2	=	noise(vec2( x,	y	-	eps ));
    a	=	(n1	-	n2)/eps2;

    n1	=	noise(vec2( x,	z	+	eps));
    n2	=	noise(vec2( x,	z	-	eps));
    b	=	(n1	-	n2)/eps2;

    curl.x	=	a	-	b;

    n1	=	noise(vec2( y,	z	+	eps));
    n2	=	noise(vec2( y,	z	-	eps));
    a	=	(n1	-	n2)/eps2;

    n1	=	noise(vec2( x	+	eps,	z));
    n2	=	noise(vec2( x	+	eps,	z));
    b	=	(n1	-	n2)/eps2;

    curl.y	=	a	-	b;

    n1	=	noise(vec2( x	+	eps,	y));
    n2	=	noise(vec2( x	-	eps,	y));
    a	=	(n1	-	n2)/eps2;

    n1	=	noise(vec2(  y	+	eps,	z));
    n2	=	noise(vec2(  y	-	eps,	z));
    b	=	(n1	-	n2)/eps2;

    curl.z	=	a	-	b;

    return	curl;
}
  

void main() {
    vUv = uv;
    // vec4 mvPosition = modelViewMatrix * vec4(position, 1.);
  
    vec3 t = position
         + curl(
            2. * position.x,
            2. * position.y,
            2. * position.z
        ) * 10. * progress;
    float d = length(position - t) / 2.;
    vec3 np = mix(position, t, pow(d, 5.));
  
    vec4 mvPosition = modelViewMatrix * vec4(np, 1.);
  
  
    gl_PointSize = 7.;
    gl_Position = projectionMatrix * mvPosition;
}
</script>

<script id="fs" type="x-shader/x-fragment">
uniform float time;
  uniform vec4 resolution;
  varying vec2 vUv;
  varying vec3 vPosition;
float PI = 3.141592653589793238462643383279;

void main() {
  float alpha = 1. - smoothstep(-0.2, 0.5, length(gl_PointCoord - vec2(0.5)));
    alpha *= 0.5;

    gl_FragColor = vec4( vUv, 1.0, 1.0 * alpha );
}
</script>
              
            
!

CSS

              
                /* CSS files add styling rules to your content */

body {
  margin: 0;
  padding: 0;
  background-color: #000000; 
  height: 100vh;
  overflow: hidden; 
}

h1 {
  font-style: italic;
  color: #373fff;
}

              
            
!

JS

              
                // LPS Head
// https://casual-effects.com/data/
// Triangles: 9923
// Vertices: 17684
// Updated: 2012-02-23
// License: CC BY 3.0
// © I-R Entertainment Ltd.

import { GLTFLoader } from 'https://unpkg.com/[email protected]/examples/jsm/loaders/GLTFLoader.js';
import { OrbitControls } from "https://unpkg.com/[email protected]/examples/jsm/controls/OrbitControls";
import {Pane} from "https://cdn.skypack.dev/[email protected]";
import * as EssentialsPlugin from "https://cdn.skypack.dev/@tweakpane/[email protected]"

class App {
  constructor() {
    this.scene = new THREE.Scene()
    this.renderer = new THREE.WebGLRenderer()
    this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
    this.renderer.setSize(this.width, this.height)
    this.renderer.setClearColor (0xffffff, 1)
    this.renderer.physicallyCorrectLights = true
    this.renderer.outputEncoding = THREE.sRGBEncoding
    document.body.appendChild(this.renderer.domElement)
    this.camera = new THREE.PerspectiveCamera (
      70,
      this.width / this.height,
      0.001,
      1000
    )
    this.camera.position.set(0, 0, 2)
    this.controls = new OrbitControls(this.camera, this.renderer.domElement)
    this.loader = new GLTFLoader()
    this.width = window.innerWidth
    this.height = window.innerHeight
    this.time = 0
    
    this.initTweakPane()
    this.init()
    this.resize()
    window.addEventListener('resize',this.resize.bind(this))
  }
  
  /**
  * set tweakpane
  */
  initTweakPane() {
    this.PARAMS = {
      progress: 0.7,
    }

    this.pane = new Pane()
    this.pane.addInput(this.PARAMS, 'progress', {
      min: 0.0, max: 1.0,
    })
  }
  
  init() {
    // this.scene.add(new THREE.AmbientLight(0x404040)) 

    const gltfUrl = 'https://dl.dropbox.com/s/w3llei92gnqqrw2/LeePerrySmith.glb?dl=0'
    this.loader.load(gltfUrl, (gltf) => {
      // console.log('gltf: ', gltf.scene.children[0])
      
      this.material = new THREE.ShaderMaterial({
        extensions: {
          derivatives: '#extension GL_OES_standard_derivatives: enable'
        },
        side: THREE.DoubleSide,
        uniforms: {
          time: { type: 'f', value: 1.0 },
          progress: { type: 'f', value: 0.0 },
        },
        transparent: true,
        vertexShader: document.getElementById('vs').textContent,
        fragmentShader: document.getElementById('fs').textContent,
        depthTest: false,
        depthWrite: false
      })
      // this.material = new THREE.PointsMaterial({ color: 0xFFFFFF, size: 0.25 })
      
      this.mesh = new THREE.Points(gltf.scene.children[0].geometry, this.material)
      this.mesh.position.set(0, -5, -40)
      this.mesh.scale.set(7, 7, 7)
      // console.log('this.mesh: ', this.mesh)
      this.scene.add(this.mesh)
      this.render()
    },
    (xhr) => {
      console.log(xhr)
    },
    (err) => {
      console.error("loading .obj went wrong, ", err)
    })
  }
  
  resize() {
    this.width = window.innerWidth
    this.height = window.innerHeight
    this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
    this.renderer.setSize( this.width, this.height )
    this.camera.aspect = this.width / this.height
    this.camera.updateProjectionMatrix()
  }
  
  render() {
    console.log('this.material: ', this.material)
    
    this.time += 0.05;
    this.material.uniforms.time.value = this.time;
    this.material.uniforms.progress.value = this.PARAMS.progress;
    
    if (this.mesh) {
      this.mesh.rotation.y = this.time * 0.1
    }
    
    requestAnimationFrame(this.render.bind(this))

    this.renderer.render( this.scene, this.camera )
  }
}

new App()

              
            
!
999px

Console