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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <canvas id="heightmap" width="256" height="256" style="position:absolute;"></canvas>
<canvas id="heightgrd" width="64" height="256" style="position:absolute;left:257px;"></canvas>
<script src="https://cdn.jsdelivr.net/npm/three@0.117.0/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.117.0/examples/js/controls/OrbitControls.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.2/dat.gui.min.js"></script>
<script>
  var heatVertex = `
    uniform sampler2D heightMap;
    uniform float heightRatio;
    uniform float heightBias;
    varying vec2 vUv;
    varying float hValue;
    void main() {
      vUv = uv;
      vec3 pos = position;
      hValue = texture2D(heightMap, vUv).r;
      pos.y = hValue * heightRatio;
      pos.y += heightBias;

      vec4 mvPosition = modelViewMatrix * vec4(pos, 1.0);

      gl_PointSize = 30. * (1. / - mvPosition.z);
      gl_Position = projectionMatrix * mvPosition;
    }
  `;
  var heatFragment = `
    uniform sampler2D gradientMap;
    varying float hValue;

    void main() {
      float v = clamp(hValue, 0., 1.);
      vec3 col = texture2D(gradientMap, vec2(0, v)).rgb;
      gl_FragColor = vec4(col, 1.) ;
    }
  `;
  
  var canvasH = document.getElementById("heightmap");
  canvasH.addEventListener("click", () => {
    createHeightMap();
  }, false);
  var heightMap = new THREE.CanvasTexture(canvasH);
  var ctx = canvasH.getContext("2d");
  
  //console.log(heightMap);
  createHeightMap();
  function createHeightMap() {
    ctx.fillStyle = "black";
    ctx.fillRect(0, 0, 256, 256);
    for (let i = 0; i < 100; i++) {
      var x = Math.floor(Math.random() * 255);
      var y = Math.floor(Math.random() * 255);
      var radius = 50;
      let grd = ctx.createRadialGradient(x, y, 1, x, y, radius);
      var h8 = Math.floor(Math.random() * 255);
      grd.addColorStop(0, "rgb(" + h8 + "," + h8 + "," + h8 + ")");
      grd.addColorStop(1, "transparent");
      ctx.fillStyle = grd;
      ctx.fillRect(0, 0, 256, 256);
    }
    heightMap.needsUpdate = true;
  }
  
  var canvasG = document.getElementById("heightgrd");
  canvasG.addEventListener("click", ()=>{
    createGradMap();
  }, false);
  var gradientMap = new THREE.CanvasTexture(canvasG);
  var ctxG = canvasG.getContext("2d");
  
  createGradMap();
  function createGradMap() {
    console.log("grad");
    let grd = ctxG.createLinearGradient(0,255, 0, 0);
    var colorAmount = 3 + THREE.MathUtils.randInt(0, 3);
    var colorStep = 1. / colorAmount; 
    for (let i = 0; i <= colorAmount; i++){
      let r = THREE.MathUtils.randInt(0,255);
      let g = THREE.MathUtils.randInt(0,255);
      let b = THREE.MathUtils.randInt(0,255);
      grd.addColorStop(colorStep * i,'rgb(' + r + ',' + g + ',' + b +')');
    }
    ctxG.fillStyle = grd;
    ctxG.fillRect(0, 0, 64, 256)
    gradientMap.needsUpdate = true;
  }
</script>
              
            
!

CSS

              
                body{
  overflow: hidden;
  margin: 0;
}
              
            
!

JS

              
                var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set(0, 20, 40);
var renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

var controls = new THREE.OrbitControls(camera, renderer.domElement);

var gC = 0x660066;
scene.add(new THREE.GridHelper(50, 25, gC, gC));

var planeGeometry = new THREE.PlaneBufferGeometry(50, 50, 500, 500);
planeGeometry.rotateX(-Math.PI * 0.5);

var heat = new THREE.Points(planeGeometry, new THREE.ShaderMaterial({
  uniforms: {
    heightMap: {value: heightMap},
    heightRatio: {value: 10},
    heightBias: {value: 0},
    gradientMap: {value: gradientMap}
  },
  vertexShader: heatVertex,
  fragmentShader: heatFragment
}));

scene.add(heat);

var gui = new dat.GUI();
gui.add(heat.material.uniforms.heightRatio, "value", 1, 15).name("heightRatio");
gui.add(heat.material.uniforms.heightBias, "value", 0, 10).name("heightBias");

window.addEventListener( 'resize', onWindowResize, false );

render();
function render(){
  requestAnimationFrame(render);
  renderer.render(scene, camera);
}

function onWindowResize() {

  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();

  renderer.setSize( window.innerWidth, window.innerHeight );

}
              
            
!
999px

Console