Pen Settings



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


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


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.


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.


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


                .container {
  position: absolute;
  width: 100%;
  height: 100%;



I have been struggling with this a lot. So I summarized everything I know now below.


// Setup
var renderer, camera, scene, $container;
var w = 750;
var h = 750;

scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, w/h, 0.1, 10000);

renderer = new THREE.WebGLRenderer({ antialias: true });

$container = document.querySelector('.container');

/*Data texture*/
var side = 32; // power of two textures are better cause powers of two are required by some algorithms. Like ones that decide what color will pixel have if amount of pixels is less than amount of textels (see three.js console error when given non-power-of-two texture)

var amount = Math.pow(side, 2); // you need 4 values for every pixel in side*side plane
var data = new Uint8Array(amount);
  You can also use any js typed array or ArrayBuffer itself
  Most popular is Uint8Array (it can contain itegers from 0 to 255)
for (var i = 0; i < amount; i++) {
  data[i] = Math.random()*256; // generates random r,g,b,a values from 0 to 1
    When using Uint8Array multiply the random value by 255 to get same results
    'cause in that case you use integers from 0 to 255 to represent colors
    which is limiting but is more widely supported (see comment below)
   If you got nothing, check console to see if you have this extension
   If not: use Uint8Array instead of Float32Array and THREE.UnsignedByteType istead of 
   THREE.FloatType in texture constructor
var dataTex = new THREE.DataTexture(data, side, side, THREE.LuminanceFormat, THREE.UnsignedByteType);
  In order to use the types THREE.FloatType and THREE.HalfFloatType, the WebGL implementation must support the respective extensions OES_texture_float and OES_texture_half_float.
dataTex.magFilter = THREE.NearestFilter; // also check out THREE.LinearFilter just to see the results
dataTex.needsUpdate = true; // somehow this line is required for this demo to work. I have not figured that out yet. 

var planeGeo = new THREE.PlaneBufferGeometry(15, 15);
var planeMat = new THREE.MeshBasicMaterial({ color: 0x4422ff, alphaMap: dataTex, transparent: true });
var plane = new THREE.Mesh(planeGeo, planeMat);

renderer.render(scene, camera);