cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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.

            
              (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);

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

  // 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
      }
    }
  });
  // Mesh作成
  var mesh = new THREE.Mesh(geometry, material);

  // Meshをシーンに追加
  scene.add(mesh);

  //マウス座標を取得
  renderer.domElement.addEventListener('mousemove', function (e) {
    mouse = new THREE.Vector2(e.clientX / windowWidth, e.clientY / windowHeight);
  }, false);

  // draw
  render();

  //描画
  function render() {
    renderer.render(scene, camera);

    material.uniforms.uMouse.value = mouse;

    // animation
    requestAnimationFrame(render);
  }
};

},{"./../shader/sample.frag":2,"./../shader/sample.vert":3}],2:[function(require,module,exports){
module.exports = "precision mediump float;\n\n uniform vec3 uColor;\n uniform vec2 uMouse;\n\nvoid main(){\n  // テクスチャ座標をカラーに出力\n  gl_FragColor =vec4(uMouse.x,uMouse.y,0.0, 1.0);\n}\n";

},{}],3:[function(require,module,exports){
module.exports = "varying vec2 vUv;\n\nvoid main() {\n  //uv => テクスチャを貼るためのUV座標\n  vUv = uv;\n  //projectionMatrix => カメラの各種パラメータから3次元を2次元に射影し、クリップ座標系に変換する行列\n  //modelViewMatrix => modelMatrix(オブジェクト座標からワールド座標へ変換する行列)とviewMatrix(ワールド座標から視点座標へ変換する行列)の積算\n  //position => 頂点座標\n  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n";

},{}]},{},[1]);

            
          
!
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.
Loading ..................

Console