Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                
<script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>

<script type="importmap">
    {
        "imports": {
            "three": "https://cdn.jsdelivr.net/npm/three@0.169.0/build/three.module.js",
            "addons/": "https://cdn.jsdelivr.net/npm/three@0.169.0/examples/jsm/"
        }
    }

</script>

<div class="container" id="container"></div>

              
            
!

CSS

              
                html, body{
    width: 100vw;
    height: 100vh;
    padding: 0;
    margin: 0;
    background-color: black;
    margin: 0;
    padding: 0;
    font-family:'mono45-headline';
}

.container{
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 100vw;
    padding: 0;
    margin: 0;
    z-index: 3;
  background: linear-gradient(0deg, rgba(74,74,74,0.2) 0%, rgba(173,173,173,0.5) 53%, rgba(240,240,240,0.7) 100%);
}
              
            
!

JS

              
                import * as THREE from 'three';

import { OrbitControls } from 'addons/controls/OrbitControls.js'
import { KTX2Loader } from 'addons/loaders/KTX2Loader.js';
import { FullScreenQuad } from 'addons/postprocessing/Pass.js';

const container = document.querySelector('.container');
const sizes = {
  width:container.offsetWidth,
  height:container.offsetHeight
}

const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(50, sizes.width / sizes.height, 0.1, 1500)
// const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
const renderer = new THREE.WebGLRenderer( { antialias: true, gammaOutput: true, alpha: true } );
const orbit = new OrbitControls(camera, renderer.domElement)
const mouse = new THREE.Vector2();

const textureLoader = new THREE.TextureLoader();

let quad

const ktx2Loader = new KTX2Loader();
ktx2Loader.setTranscoderPath('https://raw.githubusercontent.com/forerunrun/extends/main/basis/');
ktx2Loader.detectSupport(renderer);

let textureVector
let textureVectorA
let materialZ
// ktx2Loader.load( 'https://raw.githubusercontent.com/forerunrun/extends/main/motion_vector_grid.ktx2', function (ta) {
//   textureVector = ta


// });

const load2 = () => {
    ktx2Loader.load( 'https://raw.githubusercontent.com/forerunrun/extends/main/watch_movec_2.ktx2', function (tb) {
      console.log(tb)
    textureVectorA = tb
      init()
  })
}
load2()
				
// https://raw.githubusercontent.com/forerunrun/extends/main/

function init(){

  camera.position.set(0,0,2)
  
  // scene.environment = textureEquirec
  
  
  renderer.setSize(sizes.width, sizes.height)
  renderer.setClearColor( 0xfb97e6, 0.0 );
  container.appendChild(renderer.domElement)
  
  const vert = `
  	uniform vec2 size;
    out vec2 vUv;

    void main() {

      gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );

      // Convert position.xy to 1.0-0.0

      vUv.xy = position.xy / size + 0.5;
      vUv.y = 1.0 - vUv.y; // original data is upside down
    }
  `
  
  const frag = `
  	precision highp float;
    precision highp int;
    precision highp sampler2DArray;

    uniform sampler2DArray diffuse;
    in vec2 vUv;
    uniform int depth;

    out vec4 outColor;

    void main() {

      vec4 color = texture( diffuse, vec3( vUv, depth ) );

      // lighten a bit
      outColor = vec4( color.rgb, 1.0 );
	}
  `
  
    materialZ = new THREE.ShaderMaterial({
        uniforms: {
            texArray: { value: textureVectorA },
            numLayers: { value: textureVectorA.source.data.depth }, // Set the number of layers
          currentLayer: { value: 0 },
        },
        vertexShader: `
        varying vec2 vUv;
        void main() {
            vUv = uv;
            gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
        }
    `,
    fragmentShader: `
        uniform sampler2DArray texArray;
        uniform int numLayers;
        uniform int currentLayer;
        varying vec2 vUv;

        void main() {
            int layer = currentLayer % numLayers;
            vec4 color = texture(texArray, vec3(vUv, float(layer)));
            float depth = color.r;// + color.g;
            gl_FragColor = vec4(vec3(color.r, color.g, color.b), 1.0);
        }
    `,
    });
  
    const material = new THREE.MeshBasicMaterial({
      map: textureVector
    });
  
  const geo = new THREE.PlaneGeometry(1,1)
  const mesh = new THREE.Mesh(geo, material)
  scene.add(mesh)
  
  const material2 = new THREE.MeshBasicMaterial({
      map: textureVectorA
  });
  const mesh2 = new THREE.Mesh(geo, materialZ)
  scene.add(mesh2)
  
  mesh.position.x = -0.51
  mesh2.position.x = 0.51
    // Create a full-screen quad
    //quad = new FullScreenQuad(material);

  
  window.addEventListener('resize', onWindowResize, false)
  
  animate()
}

function onWindowResize() {
    sizes.width = container.offsetWidth;
    sizes.height = container.offsetHeight;
    camera.aspect = sizes.width / sizes.height;
    camera.updateProjectionMatrix()
    renderer.setSize(sizes.width, sizes.height)
    render()
}

function animate(t) {
    window.requestAnimationFrame(animate)
    render(t)
}

function render(t) {
  renderer.render(scene, camera)
  if(materialZ.uniforms.currentLayer.value < materialZ.uniforms.numLayers.value){
      materialZ.uniforms.currentLayer.value += 1
  }
 else{
   materialZ.uniforms.currentLayer.value = 0
 }
  //renderer.clear();
  //quad.render(renderer);
} 

              
            
!
999px

Console