@dailies-studio/tsl-textures 3.0.4
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/LICENSE +21 -0
- package/README.md +142 -0
- package/dist/cjs/tsl-textures.cjs +4749 -0
- package/dist/cjs/tsl-textures.min.cjs +2 -0
- package/dist/tsl-textures.js +4659 -0
- package/dist/tsl-textures.min.js +2 -0
- package/package.json +36 -0
- package/src/brain.js +116 -0
- package/src/bricks.js +116 -0
- package/src/camouflage.js +85 -0
- package/src/caustics.js +75 -0
- package/src/cave-art.js +83 -0
- package/src/circle-decor.js +76 -0
- package/src/circles.js +83 -0
- package/src/clouds.js +114 -0
- package/src/concrete.js +95 -0
- package/src/cork.js +104 -0
- package/src/crumpled-fabric.js +81 -0
- package/src/dalmatian-spots.js +80 -0
- package/src/darth-maul.js +84 -0
- package/src/dyson-sphere.js +144 -0
- package/src/entangled.js +75 -0
- package/src/fordite.js +69 -0
- package/src/gas-giant.js +94 -0
- package/src/grid.js +84 -0
- package/src/halftone.js +252 -0
- package/src/isolayers.js +79 -0
- package/src/isolines.js +72 -0
- package/src/karst-rock.js +67 -0
- package/src/marble.js +96 -0
- package/src/melter.js +76 -0
- package/src/neon-lights.js +107 -0
- package/src/perlin-noise.js +66 -0
- package/src/photosphere.js +73 -0
- package/src/planet.js +168 -0
- package/src/polka-dots.js +106 -0
- package/src/processed-wood.js +80 -0
- package/src/protozoa.js +110 -0
- package/src/reticular-veins.js +72 -0
- package/src/roman-paving.js +58 -0
- package/src/rotator.js +120 -0
- package/src/rough-clay.js +90 -0
- package/src/runny-eggs.js +180 -0
- package/src/rust.js +144 -0
- package/src/satin.js +69 -0
- package/src/scaler.js +111 -0
- package/src/scepter-head.js +94 -0
- package/src/scream.js +72 -0
- package/src/stars.js +72 -0
- package/src/static-noise.js +73 -0
- package/src/supersphere.js +108 -0
- package/src/tiger-fur.js +77 -0
- package/src/translator.js +116 -0
- package/src/tsl-textures.js +63 -0
- package/src/tsl-utils.js +344 -0
- package/src/turbulent-smoke.js +73 -0
- package/src/voronoi-cells.js +99 -0
- package/src/water-drops.js +96 -0
- package/src/watermelon.js +87 -0
- package/src/waves.js +150 -0
- package/src/wood.js +99 -0
- package/src/zebra-lines.js +77 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Neon Lights
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from "three";
|
|
7
|
+
import { abs, exp, Fn, oneMinus, positionGeometry, select, sqrt, vec3 } from 'three/tsl';
|
|
8
|
+
import { hsl, noise, toHsl } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var defaults = {
|
|
13
|
+
$name: 'Neon Lights',
|
|
14
|
+
|
|
15
|
+
position: positionGeometry,
|
|
16
|
+
|
|
17
|
+
scale: 2,
|
|
18
|
+
thinness: 0.8,
|
|
19
|
+
mode: 0, // 0=additive, 1=subtractive
|
|
20
|
+
|
|
21
|
+
colorA: new Color( 0xFF0000 ),
|
|
22
|
+
colorB: new Color( 0x00FF00 ),
|
|
23
|
+
colorC: new Color( 0x0000FF ),
|
|
24
|
+
background: new Color( 0x000000 ),
|
|
25
|
+
|
|
26
|
+
seed: 0,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
var neonLightsRaw = Fn( ([ position, scale, thinness, mode, colorA, colorB, colorC, background, seed ]) => {
|
|
32
|
+
|
|
33
|
+
var pos = position;
|
|
34
|
+
|
|
35
|
+
var xscale = exp( scale.remap( 0, 4, -2, 2 ) ).toVar();
|
|
36
|
+
var xthinness = exp( thinness.remap( 0, 1, 1.5, 0 ) ).toVar();
|
|
37
|
+
|
|
38
|
+
var color = background.toVar();
|
|
39
|
+
var neon = vec3( 0 ).toVar();
|
|
40
|
+
|
|
41
|
+
var x = noise( pos.xyz ).toVar();
|
|
42
|
+
var y = noise( pos.yzx ).toVar();
|
|
43
|
+
var z = noise( pos.zxy ).toVar();
|
|
44
|
+
|
|
45
|
+
var k = noise( vec3( x, y, z ).mul( xscale ).add( seed ) ).toVar();
|
|
46
|
+
k.assign( oneMinus( sqrt( abs( k ) ) ).pow( 3 ) );
|
|
47
|
+
|
|
48
|
+
neon.assign( colorA );
|
|
49
|
+
var HSL = toHsl( neon );
|
|
50
|
+
neon.assign( hsl( vec3( HSL.xy, HSL.z.mul( k ) ) ) );
|
|
51
|
+
|
|
52
|
+
color.addAssign( select( mode.equal( 0 ), neon, neon.negate() ).mul( xthinness ) );
|
|
53
|
+
|
|
54
|
+
k.assign( noise( vec3( y, z, x ).mul( xscale ).sub( seed ) ) );
|
|
55
|
+
k.assign( oneMinus( sqrt( abs( k ) ) ).pow( 3 ) );
|
|
56
|
+
|
|
57
|
+
neon.assign( colorB );
|
|
58
|
+
var HSL = toHsl( neon );
|
|
59
|
+
neon.assign( hsl( vec3( HSL.xy, HSL.z.mul( k ) ) ) );
|
|
60
|
+
|
|
61
|
+
color.addAssign( select( mode.equal( 0 ), neon, neon.negate() ).mul( xthinness ) );
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
k.assign( noise( vec3( z, x, y.negate() ).mul( xscale ).add( seed ) ) );
|
|
65
|
+
k.assign( oneMinus( sqrt( abs( k ) ) ).pow( 3 ) );
|
|
66
|
+
|
|
67
|
+
neon.assign( colorC );
|
|
68
|
+
var HSL = toHsl( neon );
|
|
69
|
+
neon.assign( hsl( vec3( HSL.xy, HSL.z.mul( k ) ) ) );
|
|
70
|
+
|
|
71
|
+
color.addAssign( select( mode.equal( 0 ), neon, neon.negate() ).mul( xthinness ) );
|
|
72
|
+
|
|
73
|
+
return color;
|
|
74
|
+
|
|
75
|
+
} ).setLayout( {
|
|
76
|
+
name: 'neonLightsRaw',
|
|
77
|
+
type: 'vec3',
|
|
78
|
+
inputs: [
|
|
79
|
+
{ name: 'position', type: 'vec3' },
|
|
80
|
+
{ name: 'scale', type: 'float' },
|
|
81
|
+
{ name: 'thinness', type: 'float' },
|
|
82
|
+
{ name: 'node', type: 'float' },
|
|
83
|
+
{ name: 'colorA', type: 'vec3' },
|
|
84
|
+
{ name: 'colorB', type: 'vec3' },
|
|
85
|
+
{ name: 'colorC', type: 'vec3' },
|
|
86
|
+
{ name: 'background', type: 'vec3' },
|
|
87
|
+
{ name: 'seed', type: 'float' },
|
|
88
|
+
] }
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
function neonLights( params={} ) {
|
|
94
|
+
|
|
95
|
+
var { position, scale, thinness, mode, colorA, colorB, colorC, background, seed } = { ...defaults, ...params };
|
|
96
|
+
|
|
97
|
+
return neonLightsRaw( position, scale, thinness, mode, colorA, colorB, colorC, background, seed );
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
neonLights.defaults = defaults;
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
export { neonLights };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Perlin Noise
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from "three";
|
|
7
|
+
import { clamp, exp, Fn, mix, positionGeometry } from 'three/tsl';
|
|
8
|
+
import { noise } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var defaults = {
|
|
13
|
+
$name: 'Perlin noise',
|
|
14
|
+
|
|
15
|
+
position: positionGeometry,
|
|
16
|
+
scale: 2,
|
|
17
|
+
balance: 0,
|
|
18
|
+
contrast: 0,
|
|
19
|
+
|
|
20
|
+
color: new Color( 0xFFFFFF ),
|
|
21
|
+
background: new Color( 0x000000 ),
|
|
22
|
+
|
|
23
|
+
seed: 0,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var perlinNoiseRaw = Fn( ([ position, scale, balance, contrast, color, background, seed ]) => {
|
|
29
|
+
|
|
30
|
+
var pos = position.mul( exp( scale ) ).add( seed );
|
|
31
|
+
|
|
32
|
+
var k = noise( pos ).mul( 0.5, exp( contrast ) ).add( 0.5, balance ).min( 1 );
|
|
33
|
+
|
|
34
|
+
return mix( background, color, k );
|
|
35
|
+
|
|
36
|
+
} ).setLayout( {
|
|
37
|
+
name: 'perlinNoiseRaw',
|
|
38
|
+
type: 'vec3',
|
|
39
|
+
inputs: [
|
|
40
|
+
{ name: 'position', type: 'vec3' },
|
|
41
|
+
{ name: 'scale', type: 'float' },
|
|
42
|
+
{ name: 'balance', type: 'float' },
|
|
43
|
+
{ name: 'contrast', type: 'float' },
|
|
44
|
+
{ name: 'color', type: 'vec3' },
|
|
45
|
+
{ name: 'background', type: 'vec3' },
|
|
46
|
+
{ name: 'seed', type: 'float' },
|
|
47
|
+
] }
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
function perlinNoise( params={} ) {
|
|
53
|
+
|
|
54
|
+
var { position, scale, balance, contrast, color, background, seed } = { ...defaults, ...params };
|
|
55
|
+
|
|
56
|
+
return perlinNoiseRaw( position, scale, balance, contrast, color, background, seed );
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
perlinNoise.defaults = defaults;
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
export { perlinNoise };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Photosphere
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from "three";
|
|
7
|
+
import { exp, Fn, Loop, mix, positionGeometry, rotate, vec3 } from 'three/tsl';
|
|
8
|
+
import { noise } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var defaults = {
|
|
13
|
+
$name: 'Photosphere',
|
|
14
|
+
|
|
15
|
+
position: positionGeometry,
|
|
16
|
+
scale: 2,
|
|
17
|
+
|
|
18
|
+
color: new Color( 0xFFFF00 ),
|
|
19
|
+
background: new Color( 0xFF0000 ),
|
|
20
|
+
|
|
21
|
+
seed: 0,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var photosphereRaw = Fn( ([ position, scale, color, background, seed ]) => {
|
|
27
|
+
|
|
28
|
+
var xscale = exp( scale.add( 1 ) ).toVar( );
|
|
29
|
+
var pos = position.toVar( );
|
|
30
|
+
|
|
31
|
+
var vec = vec3( pos ).toVar();
|
|
32
|
+
|
|
33
|
+
Loop( 6, () => {
|
|
34
|
+
|
|
35
|
+
vec.assign( rotate( vec, pos.mul( xscale ) ) );
|
|
36
|
+
xscale.mulAssign( seed.mul( xscale ).sin().mul( 0.05 ).add( 1.1 ) );
|
|
37
|
+
|
|
38
|
+
} );
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
var k = noise( vec ).add( 1 ).div( 2 );
|
|
42
|
+
|
|
43
|
+
return mix( background, color, k );
|
|
44
|
+
|
|
45
|
+
} ).setLayout( {
|
|
46
|
+
name: 'photosphereRaw',
|
|
47
|
+
type: 'vec3',
|
|
48
|
+
inputs: [
|
|
49
|
+
{ name: 'position', type: 'vec3' },
|
|
50
|
+
{ name: 'scale', type: 'float' },
|
|
51
|
+
{ name: 'color', type: 'vec3' },
|
|
52
|
+
{ name: 'background', type: 'vec3' },
|
|
53
|
+
{ name: 'seed', type: 'float' },
|
|
54
|
+
] }
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
function photosphere( params={} ) {
|
|
60
|
+
|
|
61
|
+
var { position, scale, color, background, seed } = { ...defaults, ...params };
|
|
62
|
+
|
|
63
|
+
return photosphereRaw( position, scale, color, background, seed );
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
photosphere.defaults = defaults;
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
export { photosphere };
|
package/src/planet.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Planet
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from 'three';
|
|
7
|
+
import { exp, float, Fn, If, Loop, mix, mul, positionGeometry, remap, smoothstep, vec3 } from 'three/tsl';
|
|
8
|
+
import { noise } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var defaults = {
|
|
14
|
+
$name: 'Planet',
|
|
15
|
+
|
|
16
|
+
position: positionGeometry,
|
|
17
|
+
scale: 2,
|
|
18
|
+
|
|
19
|
+
iterations: 5,
|
|
20
|
+
|
|
21
|
+
levelSea: 0.3,
|
|
22
|
+
levelMountain: 0.7,
|
|
23
|
+
|
|
24
|
+
balanceWater: 0.3,
|
|
25
|
+
balanceSand: 0.2,
|
|
26
|
+
balanceSnow: 0.8,
|
|
27
|
+
|
|
28
|
+
colorDeep: new Color( 0x123a59 ).convertLinearToSRGB(), // SteelBlue
|
|
29
|
+
colorShallow: new Color( 0x87CEEB ).convertLinearToSRGB(), // SkyBlue
|
|
30
|
+
colorBeach: new Color( 0xFFFACD ).convertLinearToSRGB(), // LemonChiffon
|
|
31
|
+
colorGrass: new Color( 0x3CB371 ).convertLinearToSRGB(), // MediumSeaGreen
|
|
32
|
+
colorForest: new Color( 0x003000 ).convertLinearToSRGB(), // Dark green
|
|
33
|
+
colorSnow: new Color( 0xF0FFFF ).convertLinearToSRGB(), // Azure
|
|
34
|
+
|
|
35
|
+
seed: 0,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
var planetRaw = Fn( ([ position, scale, iterations, levelSea, levelMountain, balanceWater, balanceSand, balanceSnow, colorDeep, colorShallow, colorBeach, colorGrass, colorForest, colorSnow, seed ])=>{
|
|
41
|
+
|
|
42
|
+
var k = float( 0 ).toVar(),
|
|
43
|
+
sum = float( 0 ).toVar(),
|
|
44
|
+
xscale = exp( scale.sub( 2 ) ).toVar(),
|
|
45
|
+
xpower = float( 2 ).toVar();
|
|
46
|
+
|
|
47
|
+
Loop( iterations.add( 10 ), ()=>{
|
|
48
|
+
|
|
49
|
+
k.addAssign( mul( xpower, noise( position.mul( xscale ).add( seed ) ) ) );
|
|
50
|
+
sum.addAssign( xpower );
|
|
51
|
+
xscale.mulAssign( 1.5 );
|
|
52
|
+
xpower.mulAssign( 0.8 );
|
|
53
|
+
|
|
54
|
+
} );
|
|
55
|
+
|
|
56
|
+
k.assign( mul( k, k, 0.5 ).div( sum ) );
|
|
57
|
+
|
|
58
|
+
var levelSea = levelSea.pow( 2 ).toVar();
|
|
59
|
+
var levelMountain = levelMountain.pow( 2 ).toVar();
|
|
60
|
+
var levelSand = mix( levelSea, levelMountain, balanceSand ).toVar();
|
|
61
|
+
var levelCoast = mix( levelSea, levelSand, 0.4 ).toVar();
|
|
62
|
+
var levelGrass = mix( levelSea, levelSand, 0.6 ).toVar();
|
|
63
|
+
|
|
64
|
+
var color = vec3().toVar();
|
|
65
|
+
|
|
66
|
+
// process water
|
|
67
|
+
If( k.lessThan( levelSea ), ()=>{
|
|
68
|
+
|
|
69
|
+
// deep-shallow
|
|
70
|
+
color.assign( mix(
|
|
71
|
+
colorDeep,
|
|
72
|
+
colorShallow,
|
|
73
|
+
remap( k, 0, levelSea, 0, 1 ).pow( exp( balanceWater.mul( -8 ).add( 4 ) ) )
|
|
74
|
+
) );
|
|
75
|
+
|
|
76
|
+
} )
|
|
77
|
+
.ElseIf( k.lessThan( levelCoast ), ()=>{
|
|
78
|
+
|
|
79
|
+
// shallow-sand
|
|
80
|
+
color.assign( mix(
|
|
81
|
+
colorShallow,
|
|
82
|
+
colorBeach,
|
|
83
|
+
remap( k, levelSea, levelCoast )
|
|
84
|
+
) );
|
|
85
|
+
|
|
86
|
+
} )
|
|
87
|
+
.ElseIf( k.lessThan( levelGrass ), ()=>{
|
|
88
|
+
|
|
89
|
+
// sand
|
|
90
|
+
color.assign( colorBeach );
|
|
91
|
+
|
|
92
|
+
} )
|
|
93
|
+
.ElseIf( k.lessThan( levelSand ), ()=>{
|
|
94
|
+
|
|
95
|
+
// shallow-sand-grass
|
|
96
|
+
color.assign( mix(
|
|
97
|
+
colorBeach,
|
|
98
|
+
colorGrass,
|
|
99
|
+
remap( k, levelGrass, levelSand )
|
|
100
|
+
) );
|
|
101
|
+
|
|
102
|
+
} )
|
|
103
|
+
.ElseIf( k.lessThan( levelMountain ), ()=>{
|
|
104
|
+
|
|
105
|
+
// grass-forest
|
|
106
|
+
color.assign( mix(
|
|
107
|
+
colorGrass,
|
|
108
|
+
colorForest,
|
|
109
|
+
remap( k, levelSand, levelMountain ).pow( 0.75 )
|
|
110
|
+
) );
|
|
111
|
+
|
|
112
|
+
} )
|
|
113
|
+
.Else( ()=>{
|
|
114
|
+
|
|
115
|
+
// forest-snow
|
|
116
|
+
var levelSnow = mix( 1, levelMountain, balanceSnow );
|
|
117
|
+
color.assign( mix(
|
|
118
|
+
colorForest,
|
|
119
|
+
colorSnow,
|
|
120
|
+
smoothstep( mix( levelSnow, levelMountain, balanceSnow.pow( 0.5 ) ), levelSnow, k )
|
|
121
|
+
) );
|
|
122
|
+
|
|
123
|
+
} );
|
|
124
|
+
|
|
125
|
+
return color;
|
|
126
|
+
|
|
127
|
+
} ).setLayout( {
|
|
128
|
+
name: 'planetRaw',
|
|
129
|
+
type: 'vec3',
|
|
130
|
+
inputs: [
|
|
131
|
+
{ name: 'position', type: 'vec3' },
|
|
132
|
+
{ name: 'scale', type: 'float' },
|
|
133
|
+
|
|
134
|
+
{ name: 'iterations', type: 'int' },
|
|
135
|
+
{ name: 'levelSea', type: 'float' },
|
|
136
|
+
{ name: 'levelMountain', type: 'float' },
|
|
137
|
+
{ name: 'balanceWater', type: 'float' },
|
|
138
|
+
{ name: 'balanceSand', type: 'float' },
|
|
139
|
+
{ name: 'balanceSnow', type: 'float' },
|
|
140
|
+
|
|
141
|
+
{ name: 'colorDeep', type: 'vec3' },
|
|
142
|
+
{ name: 'colorShallow', type: 'vec3' },
|
|
143
|
+
{ name: 'colorBeach', type: 'vec3' },
|
|
144
|
+
{ name: 'colorGrass', type: 'vec3' },
|
|
145
|
+
{ name: 'colorForest', type: 'vec3' },
|
|
146
|
+
{ name: 'colorSnow', type: 'vec3' },
|
|
147
|
+
|
|
148
|
+
{ name: 'seed', type: 'float' },
|
|
149
|
+
] }
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
function planet( params={} ) {
|
|
155
|
+
|
|
156
|
+
var { position, scale, iterations, levelSea, levelMountain, balanceWater, balanceSand, balanceSnow, colorDeep, colorShallow, colorBeach, colorGrass, colorForest, colorSnow, seed } = { ...defaults, ...params };
|
|
157
|
+
|
|
158
|
+
return planetRaw( position, scale, iterations, levelSea, levelMountain, balanceWater, balanceSand, balanceSnow, colorDeep, colorShallow, colorBeach, colorGrass, colorForest, colorSnow, seed );
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
planet.defaults = defaults;
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
export { planet };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Polka Dots
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from "three";
|
|
7
|
+
import { acos, add, distance, exp, float, Fn, If, Loop, mat2, max, min, mix, mod, mul, oneMinus, positionGeometry, pow, smoothstep, } from 'three/tsl';
|
|
8
|
+
import { spherical } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var defaults = {
|
|
13
|
+
$name: 'Polka dots',
|
|
14
|
+
|
|
15
|
+
position: positionGeometry,
|
|
16
|
+
count: 2,
|
|
17
|
+
size: 0.5,
|
|
18
|
+
blur: 0.25,
|
|
19
|
+
|
|
20
|
+
color: new Color( 0x000000 ),
|
|
21
|
+
background: new Color( 0xFFFFFF ),
|
|
22
|
+
|
|
23
|
+
flat: 0,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var goldenRatio = ( 1+5**0.5 )/2;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var polkaDotsRaw = Fn( ([ position, count, size, blur, color, background, xflat ]) => {
|
|
33
|
+
|
|
34
|
+
var dist = float( 1 ).toVar();
|
|
35
|
+
|
|
36
|
+
If( xflat.equal( 1 ), ()=>{
|
|
37
|
+
|
|
38
|
+
var cnt = count.pow( 2 ).sub( 0.5 ).toVar();
|
|
39
|
+
var pos = position.xy.mul( cnt ).mul( mat2( 1, 1, -1, 1 ) );
|
|
40
|
+
var posTo = pos.round().toVar();
|
|
41
|
+
|
|
42
|
+
dist.assign( pos.distance( posTo ).div( cnt ) );
|
|
43
|
+
|
|
44
|
+
} ).Else( ()=>{
|
|
45
|
+
|
|
46
|
+
var cnt = pow( 10, count ).toVar();
|
|
47
|
+
var vec = position.normalize().toVar();
|
|
48
|
+
|
|
49
|
+
var besti = oneMinus( vec.y ).mul( cnt ).sub( 1 ).div( 2 );
|
|
50
|
+
|
|
51
|
+
var span = max( 10, cnt.pow( 0.5 ) );
|
|
52
|
+
|
|
53
|
+
var mini = besti.sub( span ).floor().clamp( 0, cnt );
|
|
54
|
+
var maxi = besti.add( span ).floor().clamp( 0, cnt );
|
|
55
|
+
|
|
56
|
+
dist.assign( 1 ).toVar();
|
|
57
|
+
|
|
58
|
+
Loop( maxi.sub( mini ), ( { i } )=> {
|
|
59
|
+
|
|
60
|
+
var j = add( i, mini );
|
|
61
|
+
var theta = mod( mul( 2*Math.PI/goldenRatio, j ), 2*Math.PI );
|
|
62
|
+
var phi = acos( oneMinus( float( j ).mul( 2 ).add( 1 ).div( cnt ) ) );
|
|
63
|
+
var pnt = spherical( phi, theta );//.normalize();
|
|
64
|
+
dist.assign( min( dist, distance( vec, pnt ) ) );
|
|
65
|
+
|
|
66
|
+
} ); // Loop
|
|
67
|
+
|
|
68
|
+
} ); // Else
|
|
69
|
+
|
|
70
|
+
var xsize = exp( size.mul( 5 ).sub( 5 ) ).toVar();
|
|
71
|
+
var xblur = blur.pow( 4 ).toVar();
|
|
72
|
+
var k = smoothstep( xsize.sub( xblur ), xsize.add( xblur ), dist );
|
|
73
|
+
|
|
74
|
+
return mix( color, background, k );
|
|
75
|
+
|
|
76
|
+
} ).setLayout( {
|
|
77
|
+
name: 'polkaDotsRaw',
|
|
78
|
+
type: 'vec3',
|
|
79
|
+
inputs: [
|
|
80
|
+
{ name: 'position', type: 'vec3' },
|
|
81
|
+
{ name: 'count', type: 'float' },
|
|
82
|
+
{ name: 'size', type: 'float' },
|
|
83
|
+
{ name: 'blur', type: 'float' },
|
|
84
|
+
{ name: 'color', type: 'vec3' },
|
|
85
|
+
{ name: 'background', type: 'vec3' },
|
|
86
|
+
{ name: 'xflat', type: 'int' },
|
|
87
|
+
] }
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
function polkaDots( params={} ) {
|
|
93
|
+
|
|
94
|
+
var { position, count, size, blur, color, background, flat } = { ...defaults, ...params };
|
|
95
|
+
|
|
96
|
+
return polkaDotsRaw( position, count, size, blur, color, background, flat );
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
polkaDots.defaults = defaults;
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
export { polkaDots };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Processed wood
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from "three";
|
|
7
|
+
import { add, cos, exp, Fn, mix, positionGeometry, radians, sin, sub, vec3 } from 'three/tsl';
|
|
8
|
+
import { noise } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var defaults = {
|
|
13
|
+
$name: 'Processed wood',
|
|
14
|
+
$width: 260,
|
|
15
|
+
|
|
16
|
+
position: positionGeometry,
|
|
17
|
+
scale: 2,
|
|
18
|
+
lengths: 4,
|
|
19
|
+
strength: 0.3,
|
|
20
|
+
angle: 0,
|
|
21
|
+
|
|
22
|
+
color: new Color( 0x702020 ),
|
|
23
|
+
background: new Color( 0xF0D0A0 ),
|
|
24
|
+
|
|
25
|
+
seed: 0,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var processedWoodRaw = Fn( ([ position, scale, lengths, strength, angle, color, background, seed ])=>{
|
|
31
|
+
|
|
32
|
+
var angle = radians( angle ).toVar();
|
|
33
|
+
var posLocal = vec3(
|
|
34
|
+
sub( position.x.mul( cos( angle ) ), position.y.mul( sin( angle ) ) ),
|
|
35
|
+
add( position.x.mul( sin( angle ) ), position.y.mul( cos( angle ) ) ),
|
|
36
|
+
position.z,
|
|
37
|
+
).toVar();
|
|
38
|
+
|
|
39
|
+
var xscale = scale.div( 2 ).add( 1 ).toVar();
|
|
40
|
+
var pos = posLocal.mul( exp( scale ) ).add( seed ).toVar( );
|
|
41
|
+
|
|
42
|
+
var len = lengths.add( 5 ).reciprocal().toVar();
|
|
43
|
+
var k = noise( pos.mul( xscale, vec3( 1, len, len ) ) );
|
|
44
|
+
k = k.mul( noise( pos.mul( vec3( 25, 1, 1 ) ) ).add( -1 ).mul( 0.2 ) );
|
|
45
|
+
k = k.add( strength.sub( 0.5 ) ).smoothstep( -0.3, 0.3 ).oneMinus();
|
|
46
|
+
|
|
47
|
+
return mix( color, background, k );
|
|
48
|
+
|
|
49
|
+
} ).setLayout( {
|
|
50
|
+
name: 'processedWoodRaw',
|
|
51
|
+
type: 'vec3',
|
|
52
|
+
inputs: [
|
|
53
|
+
{ name: 'position', type: 'vec3' },
|
|
54
|
+
{ name: 'scale', type: 'float' },
|
|
55
|
+
{ name: 'lengths', type: 'float' },
|
|
56
|
+
{ name: 'strength', type: 'float' },
|
|
57
|
+
{ name: 'angle', type: 'float' },
|
|
58
|
+
{ name: 'color', type: 'vec3' },
|
|
59
|
+
{ name: 'background', type: 'vec3' },
|
|
60
|
+
{ name: 'seed', type: 'float' },
|
|
61
|
+
] }
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
function processedWood( params={} ) {
|
|
67
|
+
|
|
68
|
+
var { position, scale, lengths, strength, angle, color, background, seed } = { ...defaults, ...params };
|
|
69
|
+
|
|
70
|
+
return processedWoodRaw( position, scale, lengths, strength, angle, color, background, seed );
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
processedWood.defaults = defaults;
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
export { processedWood };
|
package/src/protozoa.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Protozoa
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from "three";
|
|
7
|
+
import { exp, float, Fn, Loop, matcapUV, mix, positionGeometry, vec3 } from 'three/tsl';
|
|
8
|
+
import { noise } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var defaults = {
|
|
13
|
+
$name: 'Protozoa',
|
|
14
|
+
|
|
15
|
+
position: positionGeometry,
|
|
16
|
+
matcap: matcapUV,
|
|
17
|
+
scale: 1.5,
|
|
18
|
+
fat: 0.7,
|
|
19
|
+
amount: 0.4,
|
|
20
|
+
|
|
21
|
+
color: new Color( 0xA0A0A0 ),
|
|
22
|
+
subcolor: new Color( 0xE0E8FF ),
|
|
23
|
+
background: new Color( 0xF0F8FF ),
|
|
24
|
+
|
|
25
|
+
seed: 0,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var pnoise = Fn( ([ pos, fat ])=>{
|
|
31
|
+
|
|
32
|
+
return noise( pos ).mul( fat ).clamp( -3.14, 3.14 ).cos().add( 1 ).div( 2 );
|
|
33
|
+
|
|
34
|
+
} ).setLayout( {
|
|
35
|
+
name: 'pnoise',
|
|
36
|
+
type: 'float',
|
|
37
|
+
inputs: [
|
|
38
|
+
{ name: 'pos', type: 'vec3' },
|
|
39
|
+
{ name: 'fat', type: 'float' },
|
|
40
|
+
] }
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
var protozoaRaw = Fn( ([ position, matcap, scale, fat, amount, color, subcolor, background, seed ])=>{
|
|
46
|
+
|
|
47
|
+
var pos = position.mul( exp( scale.sub( 1 ) ) ).add( seed ).toVar( );
|
|
48
|
+
|
|
49
|
+
var xmatcap = vec3( matcap, matcap.length() ).toVar();
|
|
50
|
+
|
|
51
|
+
var rings1 = float( 0 ).toVar();
|
|
52
|
+
var rings2 = float( 0 ).toVar();
|
|
53
|
+
|
|
54
|
+
var n1 = float( 0 ).toVar();
|
|
55
|
+
var n2 = float( 0 ).toVar();
|
|
56
|
+
|
|
57
|
+
var fat = fat.add( 0.2 ).oneMinus().mul( 60 ).add( 30 ).toVar();
|
|
58
|
+
var xscale = float( 2 ).toVar();
|
|
59
|
+
|
|
60
|
+
var dPos = amount.div( 2 ).add( 0.5 ).exp().toVar();
|
|
61
|
+
|
|
62
|
+
Loop( 10, ()=>{
|
|
63
|
+
|
|
64
|
+
rings1.assign( pnoise( pos.xyz.add( xmatcap ), fat ) );
|
|
65
|
+
rings2.assign( pnoise( pos.yzx.add( xmatcap ), fat ) );
|
|
66
|
+
|
|
67
|
+
n1.addAssign( rings1.mul( rings2 ).mul( xscale ) );
|
|
68
|
+
n2.addAssign( rings1.max( rings2 ).mul( xscale ) );
|
|
69
|
+
|
|
70
|
+
pos.assign( mix( pos.mul( dPos ), 0, 0.4 ) );
|
|
71
|
+
|
|
72
|
+
xscale.mulAssign( 0.9 );
|
|
73
|
+
|
|
74
|
+
} );
|
|
75
|
+
|
|
76
|
+
return mix( background, mix( color, subcolor, n2.mul( 0.1 ) ), n1 );
|
|
77
|
+
|
|
78
|
+
} ).setLayout( {
|
|
79
|
+
name: 'protozoaRaw',
|
|
80
|
+
type: 'vec3',
|
|
81
|
+
inputs: [
|
|
82
|
+
{ name: 'position', type: 'vec3' },
|
|
83
|
+
{ name: 'matcap', type: 'vec2' },
|
|
84
|
+
{ name: 'scale', type: 'float' },
|
|
85
|
+
{ name: 'fat', type: 'float' },
|
|
86
|
+
{ name: 'amount', type: 'float' },
|
|
87
|
+
{ name: 'color', type: 'vec3' },
|
|
88
|
+
{ name: 'subcolor', type: 'vec3' },
|
|
89
|
+
{ name: 'background', type: 'vec3' },
|
|
90
|
+
{ name: 'seed', type: 'float' },
|
|
91
|
+
] }
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
function protozoa( params={} ) {
|
|
97
|
+
|
|
98
|
+
var { position, matcap, scale, fat, amount, color, subcolor, background, seed } = { ...defaults, ...params };
|
|
99
|
+
|
|
100
|
+
return protozoaRaw( position, matcap, scale, fat, amount, color, subcolor, background, seed );
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
protozoa.defaults = defaults;
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
export { protozoa };
|