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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console