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 type="x-shader/x-vertex" id="vert">
attribute vec3 offset;
attribute vec2 uvOffset;
attribute vec2 uvScale;
varying vec2 vUv;
void main() {

    //HERE ! !

        vUv = uv * uvScale + uvOffset;

    // STOP.

    vec3 pos = position + offset;
    gl_Position = projectionMatrix * modelViewMatrix * vec4( pos, 1.0 );
}</script>

    <script type="x-shader/x-fragment" id="frag">
uniform sampler2D texture;
varying vec2 vUv;
void main() {
    gl_FragColor = texture2D( texture, vUv );
}</script>
              
            
!

CSS

              
                html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  top: 0;
  left: 0;
  margin: 0;
  padding: 0;
}

              
            
!

JS

              
                var scene, camera, renderer, mesh, width, height;

function init3D(w, h) {
  scene = new THREE.Scene();
  camera = new THREE.PerspectiveCamera(60, w / h, 0.1, 10000);

  renderer = new THREE.WebGLRenderer({ antialias: true });
  renderer.setSize(w, h);
  renderer.setPixelRatio(window.devicePixelRatio);
  document.body.appendChild(renderer.domElement);

  window.addEventListener("resize", onResizeHandler);
  onResize(w, h);
  window.camera = camera;
}

function onResizeHandler(e) {
  var w = window.innerWidth;
  var h = window.innerHeight;
  onResize(w, h);
}

function onResize(w, h) {
  camera.aspect = w / h;
  camera.updateProjectionMatrix();
  renderer.setSize(w, h);
}

function init() {
  init3D(window.innerWidth, window.innerHeight);

  camera.position.z = 500;
  camera.lookAt(new THREE.Vector3(0, 0, 0));

  var size = new THREE.Vector3(10, 10);
  src = new THREE.BufferGeometry().fromGeometry(
    new THREE.PlaneGeometry(size.x, size.y, 1, 1)
  );

  //instances geometry
  var geometry = new THREE.InstancedBufferGeometry();
  geometry.addAttribute(
    "position",
    new THREE.BufferAttribute(src.getAttribute("position").array, 3)
  );
  geometry.addAttribute(
    "uv",
    new THREE.BufferAttribute(src.getAttribute("uv").array, 2)
  );

  var count = width * height;
  var offsets = new Float32Array(count * 3);
  var uvOffset = new Float32Array(count * 2);
  var uvScales = new Float32Array(count * 2);

  //iterators
  var offsetIterator = 0;
  var uvOffsetIterator = 0;
  var uvScalesIterator = 0;

  var center = new THREE.Vector2(width * size.x * 0.5, height * size.y * 0.5);

  var uvScale = new THREE.Vector2(1 / width, 1 / height);

  for (var i = 0; i < width; i++) {
    for (var j = 0; j < height; j++) {
      offsets[offsetIterator++] = i * size.x * 1.1 - center.x;
      offsets[offsetIterator++] = j * size.y * 1.1 - center.y;
      offsets[offsetIterator++] = (Math.random() - 0.5) * 20;

      uvOffset[uvOffsetIterator++] = i * uvScale.x;
      uvOffset[uvOffsetIterator++] = j * uvScale.y;

      uvScales[uvScalesIterator++] = uvScale.x;
      uvScales[uvScalesIterator++] = uvScale.y;
    }
  }

  //add buffers
  geometry.addAttribute(
    "offset",
    new THREE.InstancedBufferAttribute(offsets, 3, 1)
  );
  geometry.addAttribute(
    "uvOffset",
    new THREE.InstancedBufferAttribute(uvOffset, 2, 1)
  );
  geometry.addAttribute(
    "uvScale",
    new THREE.InstancedBufferAttribute(uvScales, 2, 1)
  );

  //material
  material = new THREE.ShaderMaterial({
    uniforms: {
      texture: { type: "t", value: null }
    },
    vertexShader: document.getElementById("vert").innerText,
    fragmentShader: document.getElementById("frag").innerText,
    side: THREE.DoubleSide
  });

  //loads a texture
  var tl = new THREE.TextureLoader();
  tl.setCrossOrigin( "Anonymous" );
  tl.load("https://lonelyplanetwpnews.imgix.net/2015/06/lemur1.jpg", function( t ) {
    mesh.material.uniforms.texture.value = t;
  });

  //mesh
  mesh = new THREE.Mesh(geometry, material);
  scene.add(mesh);
  update();
}

function update() {
  requestAnimationFrame(update);
  mesh.rotation.y += 0.01;
  renderer.render(scene, camera);
}

window.onload = function() {
  width = 60;
  height = 42;
  init();
};

              
            
!
999px

Console