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

              
                <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/three.min.js"></script>
<script id="vertexShader" type="x-shader/x-vertex">
    void main() {
        gl_Position = vec4( position, 1.0 );
    }
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
    uniform vec2 u_resolution;
    uniform float u_time;
    uniform vec2 u_mouse;
    uniform float u_zoom ;
    uniform float u_nx;
    uniform float u_ny;
    uniform float u_nz;
  
    void main() {
      
      vec2 aspect = vec2(u_resolution.x/u_resolution.y,1.0) ;
      vec2 coord = aspect.xy*(gl_FragCoord.xy-u_resolution.xy/2.0)/u_resolution.xy*2.0*u_zoom ;
      vec2 mouseUnzoomed = aspect.xy*(2.0*u_mouse.xy-u_resolution.xy/2.0)/u_resolution.xy*2.0 ;
      vec2 mouse = mouseUnzoomed*u_zoom ;
      
      if (length(mouseUnzoomed) > 1.){
        mouseUnzoomed = normalize(mouseUnzoomed) ;
      }
            
      float sqrt2 = sqrt(2.0) ;
      float sqrt6 = sqrt(6.0) ;
      
      // isometric view vector
      vec3 x111 = vec3(1.,1.,1.)  ;
      // viewpoint
      vec3 v = x111 + coord.x*vec3(1.0/sqrt2,0.0,-1.0/sqrt2)
                    + coord.y*vec3(-1.0/sqrt6,2.0/sqrt6,-1.0/sqrt6);
      
      // normal of cut plane
      //vec3 n = vec3(u_nx,u_ny,u_nz) ;
      vec3 n = x111 + mouseUnzoomed.x*vec3(1.0/sqrt2,0.0,-1.0/sqrt2)
                    + mouseUnzoomed.y*vec3(-1.0/sqrt6,2.0/sqrt6,-1.0/sqrt6);
      
      // point of intersection of view vector and plane
      vec3 p = v + -x111*dot(n,v)/dot(n,x111) ;

      // data for revealed surface
      vec4 color = vec4(0.,0.,0.,1.) ;
      float dist = 10. ;
      bool edge = false ;
      float eps = 0.02 ;
      
      vec4 locolor = vec4(0.4,0.4,0.4,1.) ;
      vec4 medcolor = vec4(0.6,0.6,0.6,1.) ;
      vec4 hicolor = vec4(0.9,0.9,0.9,1.) ;
      vec4 xcolor = medcolor ; //med
      vec4 ycolor = hicolor ; //hi
      vec4 zcolor = locolor ; //lo
      
      // intersect with next x=int plane
      float fpx = fract(p.x) ;
      vec3 px = p-vec3(fpx,fpx,fpx) ;
      float distx = distance(p,px) ;
      bool beyondx = dot(n,vec3(px.x,ceil(px.y),ceil(px.z)))<0. ;
      if (beyondx){
        if (distx<dist){
          color = xcolor ;
          dist = distx ;
          edge = fract(px.y)<eps || fract(px.y)>1.-eps ||
            fract(px.z)<eps || fract(px.z)>1.-eps;
        }
      }
          
      
      // intersect with next y=int plane
      float fpy = fract(p.y) ;
      vec3 py = p-vec3(fpy,fpy,fpy) ;
      float disty = distance(p,py) ; 
      bool beyondy = dot(n,vec3(ceil(py.x),py.y,ceil(py.z)))<0. ; 
      if (beyondy){
        if (disty<dist){
          color = ycolor ;
          dist = disty ;
          edge = fract(py.x)<eps || fract(py.x)>1.-eps ||
            fract(py.z)<eps || fract(py.z)>1.-eps;
        }
      } 
          
      
      // intersect with next y=int plane
      float fpz = fract(p.z) ;
      vec3 pz = p-vec3(fpz,fpz,fpz) ;
      float distz = distance(p,pz) ;
      bool beyondz = dot(n,vec3(ceil(pz.x),ceil(pz.y),pz.z))<0. ;
      if (beyondz){
        if (distz<dist){
          color = zcolor ;
          dist = distz ;
          edge = fract(pz.x)<eps || fract(pz.x)>1.-eps ||
            fract(pz.y)<eps || fract(pz.y)>1.-eps;

        }
      }
          
      
      gl_FragColor = color ;
      if (edge){
        gl_FragColor = vec4(0.,0.,0.,1.) ;
      }
      
    }
  
</script>


<div id="container" touch-action="none"></div>
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 0;
}

#container {
  position: fixed;
  touch-action: none;
}
              
            
!

JS

              
                

let container;
let camera, scene, renderer;
let uniforms;

var gui = new dat.GUI()  ;
  
    init();
    animate();

function init() {
  container = document.getElementById( 'container' );

  camera = new THREE.Camera();
  camera.position.z = 1;

  scene = new THREE.Scene();

  var geometry = new THREE.PlaneBufferGeometry( 2, 2 );

  uniforms = {
    u_time: { type: "f", value: 1.0 },
    u_resolution: { type: "v2", value: new THREE.Vector2() },
    u_mouse: { type: "v2", value: new THREE.Vector2() },
    u_zoom: { value: 5 },
    u_nx: { value: 1.0 },
    u_ny: { value: 1.0 },
    u_nz: { value: 1.0 },
  };
  defaultView() ;
  
  // Dat gui
  gui.add(uniforms.u_nx, 'value').name("nx").step(.001);
  gui.add(uniforms.u_ny, 'value').name("ny").step(.001);
  gui.add(uniforms.u_nz, 'value').name("nz").step(.001);
  
  gui.close();

  var material = new THREE.ShaderMaterial( {
    uniforms: uniforms,
    vertexShader: document.getElementById( 'vertexShader' ).textContent,
    fragmentShader: document.getElementById( 'fragmentShader' ).textContent
  } );
  material.extensions.derivatives = true;

  var mesh = new THREE.Mesh( geometry, material );
  scene.add( mesh );

  renderer = new THREE.WebGLRenderer();
  renderer.setPixelRatio( window.devicePixelRatio );

  container.appendChild( renderer.domElement );

  onWindowResize();
  window.addEventListener( 'resize', onWindowResize, false );
  container.addEventListener( 'wheel', onWheelEvent, false );

  document.addEventListener('pointermove', pointerMove);
  document.addEventListener('mouseout', mouseOut);
}

function pointerMove(e){
    setMouseUniform(e.pageX, window.innerHeight-e.pageY) ;
    e.preventDefault();
}

function mouseOut(e){
   defaultView() ;
   e.preventDefault();
}

function defaultView(){
    setMouseUniform (window.innerWidth/2, window.innerHeight/2)  ;
}

function setMouseUniform(x,y){
  uniforms.u_mouse.value.x = x ;
  uniforms.u_mouse.value.y = y ;
  
  if (uniforms.u_resolution.value.x){
    let aspect = {} ;
    let mouseUnzoomed = {} ;
    aspect.x = uniforms.u_resolution.value.x/uniforms.u_resolution.value.y ;
    aspect.y = 1.0 ;
    mouseUnzoomed.x = aspect.x*(2*uniforms.u_mouse.value.x-uniforms.u_resolution.value.x/2)/uniforms.u_resolution.value.x*2 ;
    mouseUnzoomed.y = aspect.y*(2*uniforms.u_mouse.value.y-uniforms.u_resolution.value.y/2)/uniforms.u_resolution.value.y*2 ;
    let n = {} ;
    const sqrt2 = Math.sqrt(2) ;
    const sqrt6 = Math.sqrt(6) ;
    n.x = 1 + mouseUnzoomed.x/sqrt2 - mouseUnzoomed.y/sqrt6 ;
    n.y = 1 + mouseUnzoomed.y*2/sqrt6 ;
    n.z = 1 - mouseUnzoomed.x/sqrt2 - mouseUnzoomed.y/sqrt6 ;

    uniforms.u_nx.value = n.x ;
    uniforms.u_ny.value = n.y ;
    uniforms.u_nz.value = n.z ;
    // Iterate over all controllers
    for (var i in gui.__controllers) {
      gui.__controllers[i].updateDisplay();
    }
  }

}

function onWindowResize( event ) {
  renderer.setSize( window.innerWidth, window.innerHeight );
  uniforms.u_resolution.value.x = renderer.domElement.width;
  uniforms.u_resolution.value.y = renderer.domElement.height;
}

function onWheelEvent (event){
  console.log (event) ;
  event.preventDefault() ;
  uniforms.u_zoom.value *= 1.005**(event.deltaY) ;
  console.log(`deltaY=${event.deltaY}zoom=${uniforms.u_zoom.value}`) ;
}


function animate(delta) {
  requestAnimationFrame( animate );
  render(delta);
}

function render(delta) {
  uniforms.u_time.value = delta * .0005 - 10000;
  renderer.render( scene, camera );
}
              
            
!
999px

Console