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


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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


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.






                (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';

var myVert = require('./../shader/sample.vert');
var myFrag = require('./../shader/sample.frag');

window.onload = function () {
  var windowWidth = window.innerWidth;
  var windowHeight = window.innerHeight;
  var mouse = new THREE.Vector2(0.0, 0.0);
  var clock = new THREE.Clock();
  var time = 0.0;

  // rendererの作成
  var renderer = new THREE.WebGLRenderer();
  // canvasをbodyに追加

  // canvasをリサイズ(学習用なのでリサイズイベント登録は省略)
  renderer.setSize(windowWidth, windowHeight);

  // scene作成
  var scene = new THREE.Scene();
  // camera作成
  var camera = new THREE.PerspectiveCamera(75, windowWidth / windowHeight, 0.1, 1000);
  camera.position.z = 100;

  // Geometry作成
  var geometry = new THREE.PlaneBufferGeometry(100, 100);
  // Material作成
  var material = new THREE.ShaderMaterial({
    vertexShader: myVert,
    fragmentShader: myFrag,
    uniforms: {
      uColor: {
        type: 'c',
        value: new THREE.Color(0xFF0000)
      uMouse: {
        type: 'v2',
        value: mouse
      uTime: {
        type: 'f',
        value: time
  // Mesh作成
  var mesh = new THREE.Mesh(geometry, material);

  // Meshをシーンに追加

  renderer.domElement.addEventListener('mousemove', function (e) {
    mouse = new THREE.Vector2(e.clientX / windowWidth, e.clientY / windowHeight);
  }, false);

  // draw

  function render() {
    renderer.render(scene, camera);

    material.uniforms.uMouse.value = mouse;
    material.uniforms.uTime.value = clock.getElapsedTime();

    // animation

module.exports = "precision mediump float;\n\n uniform vec3 uColor;\n uniform vec2 uMouse;\n uniform float uTime;\n\nvoid main(){\n  float t = abs(cos(uTime));\n  gl_FragColor =vec4(t,t,t, 1.0);\n}\n";

module.exports = "varying vec2 vUv;\n\nvoid main() {\n\n  vUv = uv;\n\n  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n";