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 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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                (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 baseVert = require('./../shader/base.vert');
var baseFrag = require('./../shader/base.frag');
var postVert = require('./../shader/post.vert');
var postFrag = require('./../shader/post.frag');

window.onload = function () {

    var renderer;
    var postCamera, postScene;
    var baseCamera, baseScene;
    var renderTarget;
    var theta = 0;
    var clock = new THREE.Clock();
    var time = 0.0;

    var windowWidth = window.innerWidth;
    var windowHeight = window.innerHeight;

    var aspect = windowWidth / windowHeight;

    // rendererの作成
    var renderer = new THREE.WebGLRenderer();
    renderer.setClearColor('#CCC');

    // canvasをbodyに追加
    document.body.appendChild(renderer.domElement);

    // canvasをリサイズ
    renderer.setSize(windowWidth, windowHeight);

    // ベースの描画処理(renderTarget への描画用)
    baseScene = new THREE.Scene();

    //ベースの描画処理用カメラ
    baseCamera = new THREE.PerspectiveCamera(50, windowWidth / windowHeight, 0.1, 1000);
    baseCamera.position.z = 20;

    var baseUniforms = {

        'uResolution': {
            type: 'v2',
            value: new THREE.Vector2(windowWidth, windowHeight)
        }
    };

    //ベース用のマテリアルとジオメトリ
    var baseGeometry = new THREE.BoxGeometry(5, 5, 5);
    var baseMaterial = new THREE.ShaderMaterial({
        uniforms: baseUniforms,
        vertexShader: baseVert,
        fragmentShader: baseFrag
    });
    var baseMesh = new THREE.Mesh(baseGeometry, baseMaterial);
    baseScene.add(baseMesh);

    //オフスクリーンレンダリング用
    renderTarget = new THREE.WebGLRenderTarget(windowWidth, windowHeight, {
        magFilter: THREE.NearestFilter,
        minFilter: THREE.NearestFilter,
        wrapS: THREE.ClampToEdgeWrapping,
        wrapT: THREE.ClampToEdgeWrapping
    });

    //ポストプロセス用
    postScene = new THREE.Scene();
    postCamera = new THREE.PerspectiveCamera(60, windowWidth / windowHeight, 0.1, 1000);
    postCamera.position.z = 20;

    //ポストプロセス用ジオメトリ、マテリアル
    var postGeometry = new THREE.Geometry();

    postGeometry.vertices = [new THREE.Vector3(-1.0 * aspect, 1.0, 0.0), new THREE.Vector3(1.0 * aspect, 1.0, 0.0), new THREE.Vector3(-1.0 * aspect, -1.0, 0.0), new THREE.Vector3(1.0 * aspect, -1.0, 0.0)];

    postGeometry.faces = [new THREE.Face3(0, 2, 1), new THREE.Face3(1, 2, 3)];

    var postUniforms = {
        'uTex': {
            type: 't',
            value: renderTarget
        },
        'uTime': {
            type: 'f',
            value: time
        }
    };

    var postMaterial = new THREE.ShaderMaterial({
        uniforms: postUniforms,
        vertexShader: postVert,
        fragmentShader: postFrag
    });

    var postMesh = new THREE.Mesh(postGeometry, postMaterial);
    postScene.add(postMesh);

    render();

    function render() {

        theta += 0.01;

        baseMesh.rotation.set(theta, theta, 0);

        time = clock.getElapsedTime();
        postMaterial.uniforms.uTime.value = time;

        //オフスクリーンレンダリング
        renderer.setClearColor(new THREE.Color(0xffffff), 1.0);
        renderer.render(baseScene, baseCamera, renderTarget);

        //画面にレンダリング
        renderer.setClearColor(new THREE.Color(0x000000), 1.0);
        renderer.render(postScene, postCamera);

        requestAnimationFrame(render);
    }
};

},{"./../shader/base.frag":2,"./../shader/base.vert":3,"./../shader/post.frag":4,"./../shader/post.vert":5}],2:[function(require,module,exports){
module.exports = "precision mediump float;\n\nvarying vec3 vNormal;\n\nvoid main(){\n    gl_FragColor = vec4(vec3(vNormal),1.0) ; \n}";

},{}],3:[function(require,module,exports){
module.exports = "\n\nvarying vec3 vNormal;\n\nvoid main() {\n  vNormal = normalMatrix * normal;\n  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";

},{}],4:[function(require,module,exports){
module.exports = "precision mediump float;\nvarying vec2 vUv;\nuniform sampler2D uTex;\nuniform float uTime;\n\nfloat rnd(vec2 n){\n    return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n}\n\nvoid main(){\n\n    float n = rnd(gl_FragCoord.st + mod(uTime, 10.0)) * 0.5 + 0.7;\n\n    gl_FragColor = texture2D(uTex, vUv) * vec4(vec3(n),1.0); \n}";

},{}],5:[function(require,module,exports){
module.exports = "\nvarying vec2 vUv;\n\nvoid main() {\n  gl_Position = vec4( position, 1.0 );\n  //uv座標はpositionをそのまま使う。中央の座標の(0.0,0.0)にする為 +1.0) * 0.5する \n   vUv = (position.xy + 1.0) * 0.5;\n}";

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


              
            
!
999px

Console