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

              
                
              
            
!

CSS

              
                canvas
{
  position:fixed;
  top:0px;
  width:100vw;
  height:100vh;
  left:0px
}
body
{
  background-color:black;
}
              
            
!

JS

              
                var scene = new THREE.Scene();
var renderer = new THREE.WebGLRenderer({antialias:true,transparent:false});
renderer.setClearColor(0x000000,0);
renderer.setClearAlpha(0);
document.body.appendChild(renderer.domElement);

var dpr = window.devicePixelRatio|| 1;
renderer.setSize(innerWidth*dpr,innerHeight*dpr);
renderer.domElement.style.width = "100%";
renderer.domElement.style.height = "100%";
var persp = new THREE.PerspectiveCamera(30, innerWidth/innerHeight, .1, 1000);

persp.position.z = -10;
persp.position.x = -10;
persp.lookAt(new THREE.Vector3());


var light = new THREE.PointLight(0xffffff,1,3);
scene.add(light);
light.position.z = -1;

var light = new THREE.PointLight(0xffffff,2,4);
scene.add(light);
light.position.z = 2;
light.position.y = 3;

var gradCanvas = document.createElement('canvas');
var gc = gradCanvas.getContext('2d');
gradCanvas.width = gradCanvas.height = 128;
var grad = gc.createLinearGradient(0,0, 128,0);
grad.addColorStop(0,'black');
grad.addColorStop(1,'black');
grad.addColorStop(.2,'white');
grad.addColorStop(.8,'#80aff0');
gc.fillStyle = grad;
gc.fillRect(0,0,128,128);
grad = gc.createLinearGradient(0,0,0,128);
grad.addColorStop(0, "rgba(255,255,0,0.0)");
grad.addColorStop(1, "black");
gc.fillStyle = grad;
gc.fillRect(0,0,128,128);

var gradTex = new THREE.Texture(gradCanvas);
gradTex.needsUpdate = true;

var cube = new THREE.CubeGeometry(2.9,.025,.3);
var mat = new THREE.MeshPhongMaterial({color:0xffffff,
                                      emissive:0x200000
                                   
                                      });
var gradRay = new THREE.MeshBasicMaterial({
  color:0xffffff,
    blending:THREE.AdditiveBlending,                                           transparent:true,
   map:gradTex,
  depthTest:false,
  side:THREE.DoubleSide,
  opacity:0.08});
var gradGeo = new THREE.PlaneGeometry(2.9, 4);
var windowFrame = new THREE.Object3D();

for(var i =0;i<20;i++ ){
  var slat = new THREE.Mesh(cube,mat);
  slat.position.y = 0.2*i-.9;
  slat.rotation.x = -Math.PI/5;
  var ray = new THREE.Mesh(gradGeo, gradRay);
  slat.add(ray);
	ray.position.z = -2;
  ray.rotation.x = Math.PI/2;
  windowFrame.add(slat);
}

addWhiteBacking();
addInnerFrame();


function makeDust() {
  var dustMat = new THREE.ShaderMaterial({
    uniforms:{},
    fragmentShader:""+
    "																																							\n"+
    "		varying vec3 vPos;																												\n"+
    "																																							\n"+
    "		void main() {																															\n"+
    "		 																				\n"+
    "		 float zy = max(0.,-vPos.y+vPos.z/1.4+3.);							\n"+
    "		 if(zy>4.) { zy =9.;}																				\n"+
    "		 float grey  = pow(abs(sin((zy)*7.)),1.);					\n"+
    "		 																				\n"+
    "		 																				\n"+
   // "		grey = 1.; 																				\n"+
    "		grey *= pow(1.+vPos.z/4.,0.7);															\n"+
    "		 gl_FragColor = vec4(1.,1.,1.,grey/2.);																										\n"+
    "		}																																					\n"+
    "																																							\n"+
    "																																							\n",
    vertexShader:""+
    "																																							\n"+
    "																																							\n"+
    "		varying vec3 vPos;																												\n"+
    "																																							\n"+
    "																																							\n"+
    "		void main() {																															\n"+
    "			gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.);	\n"+
    "		gl_PointSize = 2./gl_Position.z;																														\n"+
    "		vPos = position;																													\n"+
    "																																							\n"+
    "																																							\n"+
    "		}																																					\n"
    ,
    blending:THREE.AdditiveBlending,
    transparent:true,
    depthtest:false
    
    
    
    });var dustGeo = window.dustGeo =  new THREE.Geometry();
  for(var i =0;i<30000;i++) {
    var v3 = new THREE.Vector3((Math.random()-0.5)*3, 
                               (Math.random()-0.5)*7-1,
                               Math.random()*4-4 );
    dustGeo.vertices.push(v3);
   
    
  }
	var dust = new THREE.PointCloud(dustGeo, dustMat);
  scene.add(dust);
}
makeDust();



function addInnerFrame() {
  var cGrad = document.createElement('canvas');
  var cG = cGrad.getContext('2d');
  cGrad.width = cGrad.height = 128;
  
  var grad = cG.createLinearGradient(0,0, 0,128);
  grad.addColorStop(0,"black");
  grad.addColorStop(0.75,"#a00000");
  grad.addColorStop(1,"white");
  cG.fillStyle = grad;
  cG.fillRect(0,0,cGrad.width, cGrad.height);
  var tex = new THREE.Texture(cGrad);
  tex.needsUpdate = true;
  
  
  var texMat = new THREE.MeshBasicMaterial({map:tex});
  
  
  var plane = new THREE.PlaneGeometry(4,0.2);
  
  var side = new THREE.Mesh(plane,texMat);
  
  windowFrame.add(side);
  side.rotation.y = Math.PI/2;
  side.rotation.z = -Math.PI/2;
  side.position.y =1;
  side.position.x =-1.5;

  side = new THREE.Mesh(plane,texMat);
  
  windowFrame.add(side);
  side.rotation.y = -Math.PI/2;
  side.rotation.z = Math.PI/2;
  side.position.y =1;
  side.position.x =1.5;

  side = new THREE.Mesh(plane,texMat);
  
  windowFrame.add(side);
  side.rotation.x = -Math.PI/2;
  side.position.y =-1;
	side.scale.x = 0.75;

  
  side = new THREE.Mesh(plane,texMat);
  
  windowFrame.add(side);
  side.rotation.x = Math.PI/2;
  side.rotation.z = Math.PI;
  side.position.y =3;
	side.scale.x = 0.75;

  
  var blockerMat = new THREE.MeshBasicMaterial({color:0});
  var blockerSide = new THREE.CubeGeometry(3,4,0.3);

  side = new THREE.Mesh(blockerSide, blockerMat);
  windowFrame.add(side);
  side.position.set(-3.01, 1,0);
  side = new THREE.Mesh(blockerSide, blockerMat);
  windowFrame.add(side);
  side.position.set(3.01, 1,0);
  side = new THREE.Mesh(blockerSide, blockerMat);
  windowFrame.add(side);
  side.position.set(0, 5.01,0);
  side.scale.x = 2;
  side = new THREE.Mesh(blockerSide, blockerMat);
  windowFrame.add(side);
  side.position.set(0, -3.01,0);
  side.scale.x = 2;
}

function addWhiteBacking() {
  var p = new THREE.PlaneGeometry(3,4);
  
  var white = new THREE.MeshBasicMaterial({color:0xffffff});
  var pM= new THREE.Mesh(p, white);
  windowFrame.add(pM);
  pM.rotation.x = Math.PI;
  pM.position.z = 0.1;
  pM.position.y = 1;
  
}


var mouseMoved = false;
document.body.addEventListener('mousemove',function(evt) {
  persp.position.x = 20* (evt.clientX/innerWidth-0.5);
  persp.position.z = -7;
mouseMoved = true;
    persp.position.y = 20* (evt.clientY/innerHeight-0.5);
	persp.lookAt(new THREE.Vector3(-1));

  
});
scene.add(windowFrame);

function render() {
  if(!mouseMoved) {
    
    persp.position.x = 6;
  persp.position.z = -7;
    persp.position.y = 2* Math.sin(new Date().getTime()*0.0005)-2.5;
    
  }
  	persp.lookAt(new THREE.Vector3(-1));
  var vI;
  console.log(window.dustGeo.vertices.length);
for(var i =0;i< window.dustGeo.vertices.length;i++)  {
  vI = window.dustGeo.vertices[i];
  vI.y+=0.003*(Math.random()-0.25);
  vI.x+=0.003*(Math.random()-0.5);
  vI.z+=0.003*(Math.random()-0.5);
  if(vI.y>3) vI.y-=6;
}
  window.dustGeo.verticesNeedUpdate = true;
  
  	renderer.render(scene,persp);
	requestAnimationFrame(render);
}

render();



              
            
!
999px

Console