Pen Settings

HTML

CSS

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

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

              
                <script id="perlin-shader" type="text/v-shader">
  vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }

  float snoise(vec2 v){
    const vec4 C = vec4(0.211324865405187, 0.366025403784439,
           -0.577350269189626, 0.024390243902439);
    vec2 i  = floor(v + dot(v, C.yy) );
    vec2 x0 = v -   i + dot(i, C.xx);
    vec2 i1;
    i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
    vec4 x12 = x0.xyxy + C.xxzz;
    x12.xy -= i1;
    i = mod(i, 289.0);
    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 ;
    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;
    m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
    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);
  }
</script>
              
            
!

CSS

              
                
              
            
!

JS

              
                const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000)
const renderer = new THREE.WebGLRenderer()
const clock = new THREE.Clock()

const perlinNoiseShaderFrag = document.querySelector('#perlin-shader').text

const uniforms = {
  uTime: { value: 0.0 }
}

const vertexShader = `
  uniform float vOffset;
  uniform float uTime;

  varying vec4 vNewPosition;
  varying vec3 vNormal;

  ${perlinNoiseShaderFrag}

  void main () {
    vec4 newPosition = vec4(position, 1.0);

    vec4 displacement = vec4(0.0);
    displacement.x = snoise(vec2(normal.x * 0.15, uTime)) * 10.0;
    displacement.y = snoise(vec2(normal.x * 0.2,  2.5 + uTime)) * 20.0;
    displacement.z = snoise(vec2(normal.x * 0.25, 5.0 + uTime)) * 30.0;

    newPosition += displacement;
    vec4 mvPosition = modelViewMatrix * newPosition;
    gl_Position = projectionMatrix * mvPosition;

    vNewPosition = newPosition;
    vNormal = normal;
  }
`
const fragmentShader = `
  varying vec4 vNewPosition;
  varying vec3 vNormal;

  void main () {
    vec4 center = vec4(0.5);
    float dist = distance(vNewPosition, center);
    gl_FragColor = vec4(vNormal.x * 2.0 + sin(dist * 0.2) * 0.4, vNormal.y * 0.8 + cos(dist * 0.45) * 0.5, 0.8, 1.0);
  }
`

let sphereMesh

function init () {
  setScene()
  renderFrame()
}

function setScene () {
  renderer.setSize(window.innerWidth, window.innerHeight)
  renderer.setClearColor(0xffffff)
  renderer.setPixelRatio(window.devicePixelRatio || 1)
  document.body.appendChild(renderer.domElement)

  camera.position.set(0, 50, 100)
  camera.lookAt(new THREE.Vector3())

  let geo = new THREE.SphereBufferGeometry(20, 20, 50, 50)
  let mat = new THREE.ShaderMaterial({
    uniforms,
    vertexShader,
    fragmentShader
  })
  sphereMesh = new THREE.Mesh(geo, mat)
  scene.add(sphereMesh)
}

let time = 0
function renderFrame () {
  window.requestAnimationFrame(renderFrame)

  time += clock.getDelta()
  uniforms.uTime.value = time
  renderer.render(scene, camera)
}

init()
              
            
!
999px

Console