This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
class MyCustomMaterial extends THREE.ShaderMaterial { | |
// constructor takes appropriate parameters. | |
// Default values using object destructuring (ES6) | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring | |
constructor({ | |
color = 0xffffff, | |
emissive = 0x000000, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperty( | |
Object.prototype, | |
'let', | |
{ | |
value: function (callback) { | |
return callback(this); | |
}, | |
enumerable: false, | |
writable: false | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface SingleChannelImage { | |
width: number; | |
height: number; | |
data: Uint8ClampedArray | |
} | |
function mipmaps(source: SingleChannelImage, fn = Math.max): SingleChannelImage[] { | |
if (source.width === 1 && source.height === 1) { | |
return [source]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Fetches the texel at x by mapping it to the texel-coords of the relevant mipmap level. | |
*/ | |
float textureUnpack1D_texelFetch(sampler2D map, int x, int level) { | |
if (level > 0) { | |
/* | |
Adjusts x to the appropriate mipmap level: | |
For example, a sample at position 6 in level 0, will be at positions: | |
- level 1: 6/4¹ = 1.5 = 1 | |
- level 2: 6/4² = 0.375 = 0 |