tsl-textures 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/package.json +1 -1
- package/src/planet.js +130 -0
- package/src/polka-dots.js +62 -0
- package/src/polka-dots.js.bak +62 -0
- package/src/temp.js +59 -0
- package/src/temp.js.bak +59 -0
- package/src/tsl-utils.js +3 -0
package/README.md
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
# tsl-textures
|
|
2
|
-
A collection of Three.js Shading Language (TSL) textures
|
|
2
|
+
A collection of Three.js Shading Language (TSL) textures –
|
|
3
|
+
these are online real-time procedural generators of 3D textures.
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
Pick a texture from the [Project home page](https://boytchev.github.io/tsl-textures/).
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
#### Example "Planet"
|
|
9
|
+
|
|
10
|
+
Uses [planet.js](https://boytchev.github.io/tsl-textures/docs/planet.html)
|
|
11
|
+
for both the planet and its moon; and [stars.js](https://boytchev.github.io/tsl-textures/docs/stars.html)
|
|
12
|
+
for the stars. Click on the image for a live demo.
|
|
13
|
+
|
|
14
|
+
[<img src="https://boytchev.github.io/tsl-textures/examples/example-planet.jpg">](https://boytchev.github.io/tsl-textures/examples/example-planet.html)
|
package/package.json
CHANGED
package/src/planet.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Planet
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from 'three';
|
|
7
|
+
import { exp, float, If, loop, mix, mul, positionLocal, remap, smoothstep, tslFn, vec3 } from 'three/nodes';
|
|
8
|
+
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var planet = tslFn( ( params )=>{
|
|
14
|
+
|
|
15
|
+
var k = float( 0 ).toVar(),
|
|
16
|
+
sum = float( 0 ).toVar(),
|
|
17
|
+
scale = exp( params.scale.sub( 2 ) ).toVar(),
|
|
18
|
+
power = float( 2 ).toVar();
|
|
19
|
+
|
|
20
|
+
loop( params.iterations.add( 10 ), ()=>{
|
|
21
|
+
|
|
22
|
+
k.addAssign( mul( power, noise( positionLocal.mul( scale ).add( params.seed ) ) ) );
|
|
23
|
+
sum.addAssign( power );
|
|
24
|
+
scale.mulAssign( 1.5 );
|
|
25
|
+
power.mulAssign( 0.8 );
|
|
26
|
+
|
|
27
|
+
} );
|
|
28
|
+
|
|
29
|
+
k.assign( mul( k, k, 0.5 ).div( sum ) );
|
|
30
|
+
|
|
31
|
+
var levelSea = params.levelSea.pow( 2 ).toVar();
|
|
32
|
+
var levelMountain = params.levelMountain.pow( 2 ).toVar();
|
|
33
|
+
var levelSand = mix( levelSea, levelMountain, params.balanceSand ).toVar();
|
|
34
|
+
var levelCoast = mix( levelSea, levelSand, 0.4 ).toVar();
|
|
35
|
+
var levelGrass = mix( levelSea, levelSand, 0.6 ).toVar();
|
|
36
|
+
|
|
37
|
+
var color = vec3().toVar();
|
|
38
|
+
|
|
39
|
+
// process water
|
|
40
|
+
If( k.lessThan( levelSea ), ()=>{
|
|
41
|
+
|
|
42
|
+
// deep-shallow
|
|
43
|
+
color.assign( mix(
|
|
44
|
+
params.colorDeep,
|
|
45
|
+
params.colorShallow,
|
|
46
|
+
remap( k, 0, levelSea, 0, 1 ).pow( exp( params.balanceWater.mul( -8 ).add( 4 ) ) )
|
|
47
|
+
) );
|
|
48
|
+
|
|
49
|
+
} )
|
|
50
|
+
.elseif( k.lessThan( levelCoast ), ()=>{
|
|
51
|
+
|
|
52
|
+
// shallow-sand
|
|
53
|
+
color.assign( mix(
|
|
54
|
+
params.colorShallow,
|
|
55
|
+
params.colorBeach,
|
|
56
|
+
remap( k, levelSea, levelCoast )
|
|
57
|
+
) );
|
|
58
|
+
|
|
59
|
+
} )
|
|
60
|
+
.elseif( k.lessThan( levelGrass ), ()=>{
|
|
61
|
+
|
|
62
|
+
// sand
|
|
63
|
+
color.assign( params.colorBeach );
|
|
64
|
+
|
|
65
|
+
} )
|
|
66
|
+
.elseif( k.lessThan( levelSand ), ()=>{
|
|
67
|
+
|
|
68
|
+
// shallow-sand-grass
|
|
69
|
+
color.assign( mix(
|
|
70
|
+
params.colorBeach,
|
|
71
|
+
params.colorGrass,
|
|
72
|
+
remap( k, levelGrass, levelSand )
|
|
73
|
+
) );
|
|
74
|
+
|
|
75
|
+
} )
|
|
76
|
+
.elseif( k.lessThan( levelMountain ), ()=>{
|
|
77
|
+
|
|
78
|
+
// grass-forest
|
|
79
|
+
color.assign( mix(
|
|
80
|
+
params.colorGrass,
|
|
81
|
+
params.colorForest,
|
|
82
|
+
remap( k, levelSand, levelMountain ).pow( 0.75 )
|
|
83
|
+
) );
|
|
84
|
+
|
|
85
|
+
} )
|
|
86
|
+
.else( ()=>{
|
|
87
|
+
|
|
88
|
+
// forest-snow
|
|
89
|
+
var levelSnow = mix( 1, levelMountain, params.balanceSnow );
|
|
90
|
+
color.assign( mix(
|
|
91
|
+
params.colorForest,
|
|
92
|
+
params.colorSnow,
|
|
93
|
+
smoothstep( mix( levelSnow, levelMountain, params.balanceSnow.pow( 0.5 ) ), levelSnow, k )
|
|
94
|
+
) );
|
|
95
|
+
|
|
96
|
+
} );
|
|
97
|
+
|
|
98
|
+
return color;
|
|
99
|
+
|
|
100
|
+
} );
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
planet.defaults = {
|
|
105
|
+
$name: 'Planet',
|
|
106
|
+
|
|
107
|
+
scale: 2,
|
|
108
|
+
|
|
109
|
+
iterations: 5,
|
|
110
|
+
|
|
111
|
+
levelSea: 0.3,
|
|
112
|
+
levelMountain: 0.7,
|
|
113
|
+
|
|
114
|
+
balanceWater: 0.3,
|
|
115
|
+
balanceSand: 0.2,
|
|
116
|
+
balanceSnow: 0.8,
|
|
117
|
+
|
|
118
|
+
colorDeep: new Color( 0x123a59 ).convertLinearToSRGB(), // SteelBlue
|
|
119
|
+
colorShallow: new Color( 0x87CEEB ).convertLinearToSRGB(), // SkyBlue
|
|
120
|
+
colorBeach: new Color( 0xFFFACD ).convertLinearToSRGB(), // LemonChiffon
|
|
121
|
+
colorGrass: new Color( 0x3CB371 ).convertLinearToSRGB(), // MediumSeaGreen
|
|
122
|
+
colorForest: new Color( 0x003000 ).convertLinearToSRGB(), // Dark green
|
|
123
|
+
colorSnow: new Color( 0xF0FFFF ).convertLinearToSRGB(), // Azure
|
|
124
|
+
|
|
125
|
+
seed: 0,
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
export { planet };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Polka Dots
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from "three";
|
|
7
|
+
import { acos, add, distance, exp, float, loop, max, min, mix, mul, oneMinus, positionLocal, pow, smoothstep, tslFn, } from 'three/nodes';
|
|
8
|
+
import { mod, spherical } from 'tsl-textures/tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var goldenRatio = ( 1+5**0.5 )/2;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var polkaDots = tslFn( ( params ) => {
|
|
17
|
+
|
|
18
|
+
var cnt = pow( 10, params.count ).toVar();
|
|
19
|
+
var vec = positionLocal.normalize().toVar();
|
|
20
|
+
|
|
21
|
+
var besti = oneMinus( vec.y ).mul( cnt ).sub( 1 ).div( 2 );
|
|
22
|
+
|
|
23
|
+
var span = max( 10, cnt.pow( 0.5 ) );
|
|
24
|
+
|
|
25
|
+
var mini = besti.sub( span ).floor().clamp( 0, cnt );
|
|
26
|
+
var maxi = besti.add( span ).floor().clamp( 0, cnt );
|
|
27
|
+
|
|
28
|
+
var dist = float( 1 ).toVar();
|
|
29
|
+
loop( maxi.sub( mini ), ( { i } )=> {
|
|
30
|
+
|
|
31
|
+
var j = add( i, mini );
|
|
32
|
+
var theta = mod( mul( 2*Math.PI/goldenRatio, j ), 2*Math.PI );
|
|
33
|
+
var phi = acos( oneMinus( float( j ).mul( 2 ).add( 1 ).div( cnt ) ) );
|
|
34
|
+
var pnt = spherical( phi, theta );//.normalize();
|
|
35
|
+
dist.assign( min( dist, distance( vec, pnt ) ) );
|
|
36
|
+
|
|
37
|
+
} );
|
|
38
|
+
|
|
39
|
+
var size = exp( params.size.mul( 5 ).sub( 5 ) ).toVar();
|
|
40
|
+
var blur = params.blur.pow( 4 ).toVar();
|
|
41
|
+
var k = smoothstep( size.sub( blur ), size.add( blur ), dist );
|
|
42
|
+
|
|
43
|
+
return mix( params.color, params.background, k );
|
|
44
|
+
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
polkaDots.defaults = {
|
|
50
|
+
$name: 'Polka dots',
|
|
51
|
+
|
|
52
|
+
count: 2,
|
|
53
|
+
size: 0.5,
|
|
54
|
+
blur: 0.25,
|
|
55
|
+
|
|
56
|
+
color: new Color( 0x000000 ),
|
|
57
|
+
background: new Color( 0xFFFFFF ),
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
export { polkaDots };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Polka Dots
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color, Vector3 } from "three";
|
|
7
|
+
import { acos, add, distance, exp, float, loop, max, min, mix, mul, oneMinus, positionLocal, pow, smoothstep, tslFn, } from 'three/nodes';
|
|
8
|
+
import { mod, spherical } from 'tsl-textures/tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var goldenRatio = ( 1+5**0.5 )/2;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var polkaDots = tslFn( ( params ) => {
|
|
17
|
+
|
|
18
|
+
var cnt = pow( 10, params.count ).toVar();
|
|
19
|
+
var vec = positionLocal.normalize().toVar();
|
|
20
|
+
|
|
21
|
+
var besti = oneMinus( vec.y ).mul( cnt ).sub( 1 ).div( 2 );
|
|
22
|
+
|
|
23
|
+
var span = max( 10, cnt.pow( 0.5 ) );
|
|
24
|
+
|
|
25
|
+
var mini = besti.sub( span ).floor().clamp( 0, cnt );
|
|
26
|
+
var maxi = besti.add( span ).floor().clamp( 0, cnt );
|
|
27
|
+
|
|
28
|
+
var dist = float( 1 ).toVar();
|
|
29
|
+
loop( maxi.sub( mini ), ( { i } )=> {
|
|
30
|
+
|
|
31
|
+
var j = add( i, mini );
|
|
32
|
+
var theta = mod( mul( 2*Math.PI/goldenRatio, j ), 2*Math.PI );
|
|
33
|
+
var phi = acos( oneMinus( float( j ).mul( 2 ).add( 1 ).div( cnt ) ) );
|
|
34
|
+
var pnt = spherical( phi, theta );//.normalize();
|
|
35
|
+
dist.assign( min( dist, distance( vec, pnt ) ) );
|
|
36
|
+
|
|
37
|
+
} );
|
|
38
|
+
|
|
39
|
+
var size = exp( params.size.mul( 5 ).sub( 5 ) ).toVar();
|
|
40
|
+
var blur = params.blur.pow( 4 ).toVar();
|
|
41
|
+
var k = smoothstep( size.sub( blur ), size.add( blur ), dist );
|
|
42
|
+
|
|
43
|
+
return mix( params.color, params.background, k );
|
|
44
|
+
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
polkaDots.defaults = {
|
|
50
|
+
$name: 'Polka dots',
|
|
51
|
+
|
|
52
|
+
count: 2,
|
|
53
|
+
size: 0.5,
|
|
54
|
+
blur: 0.25,
|
|
55
|
+
|
|
56
|
+
color: new Color( 0x000000 ),
|
|
57
|
+
background: new Color( 0xFFFFFF ),
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
export { polkaDots };
|
package/src/temp.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Noise Pattern
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
//import { Color } from "three";
|
|
7
|
+
import { /*clamp, exp,*/ loop, mix, positionLocal, /*storage,*/ storageObject, tslFn /*uniforms, vec3*/ } from 'three/nodes';
|
|
8
|
+
//import StorageBufferAttribute from 'three/addons/renderers/common/StorageBufferAttribute.js';
|
|
9
|
+
import StorageInstancedBufferAttribute from 'three/addons/renderers/common/StorageInstancedBufferAttribute.js';
|
|
10
|
+
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
11
|
+
|
|
12
|
+
/* workign version via uniforms
|
|
13
|
+
|
|
14
|
+
var colorGradient = uniforms( [new Color('red'),new Color('blue')] );
|
|
15
|
+
var color1 = colorGradient.element(0);
|
|
16
|
+
var color2 = colorGradient.element(1);
|
|
17
|
+
|
|
18
|
+
return mix( color1, color2, k);
|
|
19
|
+
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
var count = 2;
|
|
23
|
+
var array = [ 1, 0, 0, 1, 1, 0, 0, 0, 1 ];
|
|
24
|
+
var arrayBuffer = new StorageInstancedBufferAttribute( new Float32Array( array ), 3 );
|
|
25
|
+
var colorGradient = storageObject( arrayBuffer, 'vec3', count );
|
|
26
|
+
|
|
27
|
+
console.log( colorGradient.value.count );
|
|
28
|
+
|
|
29
|
+
var temp = tslFn( ( /*params*/ ) => {
|
|
30
|
+
|
|
31
|
+
var pos = positionLocal.mul( 2 );
|
|
32
|
+
|
|
33
|
+
var k = noise( pos ).mul( 0.5 ).add( 0.5 );
|
|
34
|
+
|
|
35
|
+
var color1 = colorGradient.element( 0 ).toVar();
|
|
36
|
+
loop( 2, ( { i } )=>{
|
|
37
|
+
|
|
38
|
+
color1.assign( colorGradient.element( i ) );
|
|
39
|
+
|
|
40
|
+
} );
|
|
41
|
+
var color2 = colorGradient.element( colorGradient.value.count-1 );
|
|
42
|
+
|
|
43
|
+
return mix( color1, color2, k );
|
|
44
|
+
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
temp.defaults = {
|
|
50
|
+
$name: 'temp',
|
|
51
|
+
|
|
52
|
+
scale: 2,
|
|
53
|
+
|
|
54
|
+
seed: 0,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export { temp };
|
package/src/temp.js.bak
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Noise Pattern
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
//import { Color } from "three";
|
|
7
|
+
import { /*clamp, exp,*/ loop, mix, positionLocal, /*storage,*/ storageObject, tslFn /*uniforms, vec3*/ } from 'three/nodes';
|
|
8
|
+
//import StorageBufferAttribute from 'three/addons/renderers/common/StorageBufferAttribute.js';
|
|
9
|
+
import StorageInstancedBufferAttribute from 'three/addons/renderers/common/StorageInstancedBufferAttribute.js';
|
|
10
|
+
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
11
|
+
|
|
12
|
+
/* workign version via uniforms
|
|
13
|
+
|
|
14
|
+
var colorGradient = uniforms( [new Color('red'),new Color('blue')] );
|
|
15
|
+
var color1 = colorGradient.element(0);
|
|
16
|
+
var color2 = colorGradient.element(1);
|
|
17
|
+
|
|
18
|
+
return mix( color1, color2, k);
|
|
19
|
+
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
var count = 2;
|
|
23
|
+
var array = [ 1, 0, 0, 1, 1, 0, 0, 0, 1 ];
|
|
24
|
+
var arrayBuffer = new StorageInstancedBufferAttribute( new Float32Array( array ), 3 );
|
|
25
|
+
var colorGradient = storageObject( arrayBuffer, 'vec3', count );
|
|
26
|
+
|
|
27
|
+
console.log( colorGradient.value.count );
|
|
28
|
+
|
|
29
|
+
var temp = tslFn( ( params ) => {
|
|
30
|
+
|
|
31
|
+
var pos = positionLocal.mul( 2 );
|
|
32
|
+
|
|
33
|
+
var k = noise( pos ).mul( 0.5 ).add( 0.5 );
|
|
34
|
+
|
|
35
|
+
var color1 = colorGradient.element( 0 ).toVar();
|
|
36
|
+
loop( 2, ( { i } )=>{
|
|
37
|
+
|
|
38
|
+
color1.assign( colorGradient.element( i ) );
|
|
39
|
+
|
|
40
|
+
} );
|
|
41
|
+
var color2 = colorGradient.element( colorGradient.value.count-1 );
|
|
42
|
+
|
|
43
|
+
return mix( color1, color2, k );
|
|
44
|
+
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
temp.defaults = {
|
|
50
|
+
$name: 'temp',
|
|
51
|
+
|
|
52
|
+
scale: 2,
|
|
53
|
+
|
|
54
|
+
seed: 0,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export { temp };
|