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

              
                <body>
  <div id="world" class="world"> </div>
 
 
   <script id="frenselVertexShader" type="x-shader/x-vertex">
    varying vec2 vUv;

    uniform float fresnelBias;
    uniform float fresnelScale;
    uniform float fresnelPower;
    uniform vec3 etaRatio;
    uniform vec3 eyePositionW;

    varying vec3 P;
    varying float reflectionFactor;
    varying vec3 R;

    varying vec3 TRed;
    varying vec3 TGreen;
    varying vec3 TBlue;


    vec3 myReflect (vec3 I, vec3 N ){
      return   I - 2.0 * N * dot(N,I);
    }

    vec3 myRefract (vec3 I, vec3 N, float etaRatio){
      float cosI = dot(-I, N);
      float cosT2 = 1.0 - etaRatio * etaRatio * (1.0 - cosI * cosI);
      vec3 T = etaRatio * I + ((etaRatio * cosI - sqrt(abs(cosT2))) * N);
      return T * vec3(cosT2 > 0.0);
    }

    void main() 
    { 
      vUv = uv; //uv is built-in
      gl_Position = projectionMatrix * modelViewMatrix* vec4( position, 1.0 );

      vec3 positionW = (modelMatrix * vec4(position, 1.0)).xyz;
      vec3 N = (mat3(modelMatrix) * normal);
      N = normalize(N);

      vec3 I =  positionW - eyePositionW  ;
      R = myReflect(I, N);  // refract(I, N, etaRation); 
      I = normalize(I);
      TRed = myRefract(I, N, etaRatio.x);
      TGreen = myRefract(I, N, etaRatio.y);
      TBlue = myRefract(I, N, etaRatio.z);

      reflectionFactor = fresnelBias + fresnelScale * pow(1.0 + dot(I, N), fresnelPower );

    }
    </script>

    <script id="frenselFragmentShader" type="x-shader/x-fragment">
    uniform sampler2D baseTexture;
    uniform samplerCube envMap;
    varying vec3 R;
    varying vec3 TRed;
    varying vec3 TGreen;
    varying vec3 TBlue;
    varying vec2 vUv;
    varying float reflectionFactor;
    void main() 
      {
          vec4 reflectedColour = textureCube(envMap, R);
          vec4 refractedColour;
          refractedColour.r = textureCube(envMap, TRed).r;
          refractedColour.g = textureCube(envMap, TGreen).g;
          refractedColour.b = textureCube(envMap, TBlue).b;
          refractedColour.a = 1.0;


          gl_FragColor = mix(refractedColour, reflectedColour,reflectionFactor );
      }  
  </script>

</body>
              
            
!

CSS

              
                
html, body {

  margin: 0;
  overflow: hidden;
  width:100%;
  height:100%;
  min-height:100%;/*for mozilla*/
  background: linear-gradient(#4286f4, #e0eaf9); 
}


.world {
  position:absolute;
  margin: 0;
  overflow: hidden;
  min-width:100%;
  width:100%;
  height:100%;
  min-height:100%;/*for mozilla*/
  background: black;
}

              
            
!

JS

              
                //Json store for models http://myjson.com/1ez4y3
//For images, use public github + rawgit https://rawgit.com/

/*
//Texture loading helper:
var textureLoader = new THREE.TextureLoader();
textureLoader.crossOrigin = "anonymous";
var stonetexture = textureLoader.load("https://cdn.rawgit.com/antu3199/WebAssets/aceb48c0/textures/stonePattern.jpg");
var normaltexture = textureLoader.load("https://cdn.rawgit.com/antu3199/WebAssets/aceb48c0/textures/normal2.jpg");
var pikachutexture = textureLoader.load("https://cdn.rawgit.com/antu3199/WebAssets/aceb48c0/textures/pikachu.png");
*/

var textureLoader = new THREE.TextureLoader();
textureLoader.crossOrigin = "anonymous";
var stonetexture = textureLoader.load(
  "https://cdn.rawgit.com/antu3199/WebAssets/aceb48c0/textures/stonePattern.jpg"
);

var format = ".jpg";

var px =
  "https://cdn.rawgit.com/antu3199/WebAssets/aceb48c0/textures/cube/px.jpg";
var nx =
  "https://cdn.rawgit.com/antu3199/WebAssets/aceb48c0/textures/cube/nx.jpg";
var py =
  "https://cdn.rawgit.com/antu3199/WebAssets/aceb48c0/textures/cube/py.jpg";
var ny =
  "https://cdn.rawgit.com/antu3199/WebAssets/aceb48c0/textures/cube/ny.jpg";
var pz =
  "https://cdn.rawgit.com/antu3199/WebAssets/aceb48c0/textures/cube/pz.jpg";
var nz =
  "https://cdn.rawgit.com/antu3199/WebAssets/aceb48c0/textures/cube/nz.jpg";

var urls = [px, nx, py, ny, pz, nz];

var loaderCube = new THREE.CubeTextureLoader();
loaderCube.crossOrigin = "anonymous";
var refractionCube = loaderCube.load(urls);

var uniforms = {
  baseTexture: { type: "t", value: stonetexture },
  envMap: { type: "t", value: refractionCube },
  eyePositionW: { value: new THREE.Vector3(0.0, 0.0, 0.5) },
  reflectivity: { value: 0.5 },
  fresnelScale: { value: 0.5 },
  fresnelPower: { value: 2.0 },
  fresnelBias: { value: 0.1 },
  etaRatio: { value: new THREE.Vector3(0.2, 0.5, 0.8) }
};

var params = {
  containerName: "world",
  uniforms: uniforms,
  vertexShader: "frenselVertexShader",
  fragmentShader: "frenselFragmentShader",
  cubeMap: refractionCube,
  sphere: true
};

var newWorld = new newThreeJSProgram(params);
newWorld.init(createWorld);

function createWorld() {
  newWorld.createScene();
  newWorld.getCubeMesh().rotation.set(0, 0, 0);
}

              
            
!
999px

Console