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

var notWebGL = function notWebGL() {
  // webGL非対応時の記述
  console.log('this browser does not support webGL');

if (document.getElementsByTagName('html')[0].classList.contains('no-webgl')) {

// three.jsのとき
try {
  var renderer = new THREE.WebGLRenderer();
} catch (e) {

window.onload = function () {
  var windowWidth = window.innerWidth;
  var windowHeight = window.innerHeight;

  // 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 = 1;

  // Geometry作成
  var geometry = new THREE.SphereBufferGeometry(0.5, 10, 10);

  // Material作成
  var material = new THREE.RawShaderMaterial({
    vertexShader: myVert,
    fragmentShader: myFrag

  // Mesh作成
  var mesh = new THREE.Mesh(geometry, material);

  // Meshをシーンに追加

  // draw

  var r = 0;

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

    r += 0.01;

    mesh.rotation.set(0, r, r);

    // animation

module.exports = "  precision mediump float;\n  varying vec4 vColor;\n\n  void main(){\n    gl_FragColor = vColor;\n  }\n";

module.exports = "\nattribute vec3 normal;\nattribute vec3 position;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat3 normalMatrix;\nvarying vec4 vColor;\nconst vec3 lightDirection = normalize(vec3(0.0, 0.0, 1.0));\n\nvoid main() {\n  vec3 n = normalMatrix * normal;\n  float diffuse = max(dot(n,lightDirection),0.0);\n\n  vColor = vec4(vec3(0.5),1.0) * vec4(vec3(diffuse), 1.0);\n  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n";