tsl-textures 2.5.1 → 3.0.1
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/dist/cjs/tsl-textures.js +2449 -1426
- package/dist/cjs/tsl-textures.min.js +2 -2
- package/dist/tsl-textures.js +2435 -1421
- package/dist/tsl-textures.min.js +2 -2
- package/package.json +1 -1
- package/src/brain.js +72 -21
- package/src/bricks.js +56 -23
- package/src/camouflage.js +39 -20
- package/src/caustics.js +39 -14
- package/src/cave-art.js +39 -13
- package/src/circle-decor.js +39 -13
- package/src/circles.js +36 -16
- package/src/clouds.js +69 -28
- package/src/concrete.js +57 -23
- package/src/cork.js +54 -35
- package/src/crumpled-fabric.js +39 -14
- package/src/dalmatian-spots.js +37 -12
- package/src/darth-maul.js +43 -15
- package/src/dyson-sphere.js +61 -18
- package/src/entangled.js +36 -12
- package/src/fordite.js +36 -12
- package/src/gas-giant.js +42 -16
- package/src/grid.js +45 -17
- package/src/isolayers.js +41 -15
- package/src/isolines.js +36 -10
- package/src/karst-rock.js +31 -8
- package/src/marble.js +36 -11
- package/src/melter.js +0 -1
- package/src/neon-lights.js +51 -23
- package/src/perlin-noise.js +66 -0
- package/src/photosphere.js +34 -11
- package/src/planet.js +66 -30
- package/src/polka-dots.js +42 -17
- package/src/processed-wood.js +42 -16
- package/src/protozoa.js +51 -16
- package/src/reticular-veins.js +37 -11
- package/src/roman-paving.js +30 -8
- package/src/rotator.js +71 -27
- package/src/rough-clay.js +50 -22
- package/src/runny-eggs.js +120 -44
- package/src/rust.js +81 -19
- package/src/satin.js +27 -20
- package/src/scaler.js +61 -26
- package/src/scepter-head.js +46 -20
- package/src/scream.js +29 -19
- package/src/stars.js +36 -11
- package/src/static-noise.js +36 -9
- package/src/supersphere.js +63 -26
- package/src/tiger-fur.js +41 -14
- package/src/translator.js +67 -24
- package/src/tsl-textures.js +2 -1
- package/src/tsl-utils.js +172 -623
- package/src/turbulent-smoke.js +38 -13
- package/src/voronoi-cells.js +44 -26
- package/src/water-drops.js +55 -22
- package/src/watermelon.js +43 -18
- package/src/wood.js +48 -15
- package/src/zebra-lines.js +38 -12
- package/src/simplex-noise.js +0 -41
package/src/satin.js
CHANGED
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import {
|
|
8
|
-
import { noise
|
|
7
|
+
import { Fn, mix, positionGeometry, vec3 } from 'three/tsl';
|
|
8
|
+
import { noise } from './tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
var defaults = {
|
|
13
13
|
$name: 'Satin',
|
|
14
14
|
|
|
15
|
+
position: positionGeometry,
|
|
15
16
|
scale: 2,
|
|
16
17
|
|
|
17
18
|
color: new Color( 0x7080FF ),
|
|
@@ -22,40 +23,46 @@ var defaults = {
|
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
|
|
25
|
-
var
|
|
26
|
+
var satinRaw = Fn( ([ position, scale, color, background, seed ]) => {
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var pos = positionGeometry.toVar( );
|
|
30
|
-
|
|
31
|
-
var scale = exp( params.scale.div( 3 ) ).toVar();
|
|
28
|
+
var pos = position.toVar( 'pos' ),
|
|
29
|
+
scale = scale.div( 3 ).exp( ).toVar( 'xscale' );
|
|
32
30
|
|
|
33
31
|
var k = noise(
|
|
34
32
|
vec3(
|
|
35
33
|
noise( vec3( pos.x.mul( 2 ), pos.y, pos.z ).mul( scale ) ),
|
|
36
34
|
noise( vec3( pos.x, pos.y.mul( 2 ), pos.z ).mul( scale ) ),
|
|
37
35
|
noise( vec3( pos.x, pos.y, pos.z.mul( 2 ) ).mul( scale ) ),
|
|
38
|
-
).mul( scale ).add(
|
|
39
|
-
);
|
|
36
|
+
).mul( scale ).add( seed )
|
|
37
|
+
).abs().pow( 3 ).mul( 20 ).toVar( 'k' );
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
return mix( background, color, k );
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
} ).setLayout( {
|
|
42
|
+
name: 'satinRaw',
|
|
43
|
+
type: 'vec3',
|
|
44
|
+
inputs: [
|
|
45
|
+
{ name: 'position', type: 'vec3' },
|
|
46
|
+
{ name: 'scale', type: 'float' },
|
|
47
|
+
{ name: 'color', type: 'vec3' },
|
|
48
|
+
{ name: 'background', type: 'vec3' },
|
|
49
|
+
{ name: 'seed', type: 'float' },
|
|
50
|
+
] }
|
|
51
|
+
);
|
|
44
52
|
|
|
45
|
-
}, defaults );
|
|
46
53
|
|
|
47
54
|
|
|
55
|
+
function satin( params={} ) {
|
|
48
56
|
|
|
49
|
-
|
|
50
|
-
$name: 'Satin',
|
|
57
|
+
var { position, scale, color, background, seed } = { ...defaults, ...params };
|
|
51
58
|
|
|
52
|
-
scale
|
|
59
|
+
return satinRaw( position, scale, color, background, seed );
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
background: new Color( 0x000050 ),
|
|
61
|
+
}
|
|
56
62
|
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
satin.defaults = defaults;
|
|
59
66
|
|
|
60
67
|
|
|
61
68
|
|
package/src/scaler.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Vector2, Vector3 } from "three";
|
|
7
|
-
import { cross, Fn, mix, normalLocal, positionGeometry,
|
|
8
|
-
import {
|
|
7
|
+
import { cross, Fn, mix, normalLocal, positionGeometry, tangentLocal, vec3 } from 'three/tsl';
|
|
8
|
+
import { approximateNormal, selectPlanar } from './tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
@@ -25,51 +25,86 @@ var defaults = {
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
var surfacePos = Fn( ([ pos,
|
|
28
|
+
var surfacePos = Fn( ([ pos, scales, center, selectorAngles, selectorCenter, selectorWidth ])=>{
|
|
29
29
|
|
|
30
|
-
var zone = selectPlanar( pos,
|
|
30
|
+
var zone = selectPlanar( pos, selectorAngles, selectorCenter, selectorWidth );
|
|
31
31
|
|
|
32
|
-
var S =
|
|
33
|
-
T = matTrans( params.center ),
|
|
34
|
-
TN = matTrans( params.center.negate() );
|
|
32
|
+
var S = mix( vec3( 1, 1, 1 ), scales, zone );
|
|
35
33
|
|
|
36
|
-
return
|
|
34
|
+
return pos.sub( center ).mul( S ).add( center );
|
|
37
35
|
|
|
38
36
|
} );
|
|
39
37
|
|
|
40
38
|
|
|
41
39
|
|
|
42
|
-
var
|
|
40
|
+
var scalerRaw = Fn( ([ scales, center, selectorAngles, selectorCenter, selectorWidth ])=>{
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return surfacePos( positionGeometry, params );
|
|
47
|
-
|
|
48
|
-
}, defaults );
|
|
42
|
+
return surfacePos( positionGeometry, scales, center, selectorAngles, selectorCenter, selectorWidth );
|
|
49
43
|
|
|
44
|
+
} ).setLayout( {
|
|
45
|
+
name: 'scalerRaw',
|
|
46
|
+
type: 'vec3',
|
|
47
|
+
inputs: [
|
|
48
|
+
{ name: 'scales', type: 'vec3' },
|
|
49
|
+
{ name: 'center', type: 'vec3' },
|
|
50
|
+
{ name: 'selectorAngles', type: 'vec2' },
|
|
51
|
+
{ name: 'selectorCenter', type: 'vec3' },
|
|
52
|
+
{ name: 'selectorWidth', type: 'float' },
|
|
53
|
+
]
|
|
54
|
+
} );
|
|
50
55
|
|
|
51
56
|
|
|
52
|
-
scaler.normal = TSLFn( ( params ) => {
|
|
53
57
|
|
|
54
|
-
|
|
58
|
+
var scalerNormalRaw = Fn( ([ scales, center, selectorAngles, selectorCenter, selectorWidth ]) => {
|
|
55
59
|
|
|
56
|
-
var
|
|
60
|
+
var EPS = 0.01;
|
|
57
61
|
|
|
58
62
|
var position = positionGeometry,
|
|
59
63
|
normal = normalLocal.normalize().toVar(),
|
|
60
|
-
tangent = tangentLocal.normalize().mul(
|
|
61
|
-
bitangent = cross( normal, tangent ).normalize().mul(
|
|
64
|
+
tangent = tangentLocal.normalize().mul( EPS ).toVar(),
|
|
65
|
+
bitangent = cross( normal, tangent ).normalize().mul( EPS ).toVar();
|
|
66
|
+
|
|
67
|
+
var pos = surfacePos( position, scales, center, selectorAngles, selectorCenter, selectorWidth );
|
|
68
|
+
var posU = surfacePos( position.add( tangent ), scales, center, selectorAngles, selectorCenter, selectorWidth );
|
|
69
|
+
var posV = surfacePos( position.add( bitangent ), scales, center, selectorAngles, selectorCenter, selectorWidth );
|
|
70
|
+
|
|
71
|
+
return approximateNormal( pos, posU, posV );
|
|
72
|
+
|
|
73
|
+
} ).setLayout( {
|
|
74
|
+
name: 'scalerNormalRaw',
|
|
75
|
+
type: 'vec3',
|
|
76
|
+
inputs: [
|
|
77
|
+
{ name: 'scales', type: 'vec3' },
|
|
78
|
+
{ name: 'center', type: 'vec3' },
|
|
79
|
+
{ name: 'selectorAngles', type: 'vec2' },
|
|
80
|
+
{ name: 'selectorCenter', type: 'vec3' },
|
|
81
|
+
{ name: 'selectorWidth', type: 'float' },
|
|
82
|
+
]
|
|
83
|
+
} );
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
function scaler( params={} ) {
|
|
88
|
+
|
|
89
|
+
var { scales, center, selectorAngles, selectorCenter, selectorWidth } = { ...defaults, ...params };
|
|
62
90
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
91
|
+
return scalerRaw( scales, center, selectorAngles, selectorCenter, selectorWidth );
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
scaler.normal = function ( params={} ) {
|
|
98
|
+
|
|
99
|
+
var { scales, center, selectorAngles, selectorCenter, selectorWidth } = { ...defaults, ...params };
|
|
100
|
+
|
|
101
|
+
return scalerNormalRaw( scales, center, selectorAngles, selectorCenter, selectorWidth );
|
|
102
|
+
|
|
103
|
+
};
|
|
66
104
|
|
|
67
|
-
var dU = sub( posU, pos ),
|
|
68
|
-
dV = sub( posV, pos );
|
|
69
105
|
|
|
70
|
-
return transformNormalToView( cross( dU, dV ).normalize() );
|
|
71
106
|
|
|
72
|
-
|
|
107
|
+
scaler.defaults = defaults;
|
|
73
108
|
|
|
74
109
|
|
|
75
110
|
|
package/src/scepter-head.js
CHANGED
|
@@ -4,14 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { abs, add, cos, floor, max, mix, mod, mul, positionGeometry, remapClamp, sign, tan, vec3 } from 'three/tsl';
|
|
8
|
-
import { hsl, noise,
|
|
7
|
+
import { abs, add, cos, floor, Fn, max, mix, mod, mul, positionGeometry, remapClamp, sign, tan, vec3 } from 'three/tsl';
|
|
8
|
+
import { hsl, noise, remapExp, toHsl } from './tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
var defaults = {
|
|
13
13
|
$name: 'Scepter head',
|
|
14
14
|
|
|
15
|
+
position: positionGeometry,
|
|
16
|
+
|
|
15
17
|
xFactor: 10,
|
|
16
18
|
yFactor: 22,
|
|
17
19
|
zFactor: 10,
|
|
@@ -23,27 +25,25 @@ var defaults = {
|
|
|
23
25
|
|
|
24
26
|
|
|
25
27
|
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
params = prepare( params, defaults );
|
|
28
|
+
var scepterHeadRaw = Fn( ([ position, xFactor, yFactor, zFactor, colorRim, colorA, colorB ]) => {
|
|
29
29
|
|
|
30
|
-
var pos =
|
|
30
|
+
var pos = position.toVar( 'pos' );
|
|
31
31
|
|
|
32
|
-
var fx = pos.x.mul( remapExp(
|
|
33
|
-
fy = pos.y.mul( remapExp(
|
|
34
|
-
fz = pos.z.mul( remapExp(
|
|
32
|
+
var fx = pos.x.mul( remapExp( xFactor, 0, 100, 1.35, 30 ) ).toVar( 'fx' ),
|
|
33
|
+
fy = pos.y.mul( remapExp( yFactor, 0, 100, 1.35, 30 ) ).toVar( 'fy' ),
|
|
34
|
+
fz = pos.z.mul( remapExp( zFactor, 0, 100, 1.35, 30 ) ).toVar( 'fz' );
|
|
35
35
|
|
|
36
|
-
var cosX = cos( fx )
|
|
37
|
-
cosY = cos( fy )
|
|
38
|
-
cosZ = cos( fz )
|
|
36
|
+
var cosX = cos( fx ),
|
|
37
|
+
cosY = cos( fy ),
|
|
38
|
+
cosZ = cos( fz );
|
|
39
39
|
|
|
40
40
|
var k = noise( vec3( pos.x.div( cosX ), pos.y.div( cosY ), pos.z.div( cosZ ) ) );
|
|
41
41
|
|
|
42
42
|
k = sign( k ).mul( abs( k ).pow( 0.75 ) );
|
|
43
43
|
|
|
44
|
-
var dx = abs( mul( fx, tan( fx ) ).add( 1 ).div(
|
|
45
|
-
dy = abs( mul( fy, tan( fy ) ).add( 1 ).div(
|
|
46
|
-
dz = abs( mul( fz, tan( fz ) ).add( 1 ).div(
|
|
44
|
+
var dx = abs( mul( fx, tan( fx ) ).add( 1 ).div( cosX ) ),
|
|
45
|
+
dy = abs( mul( fy, tan( fy ) ).add( 1 ).div( cosY ) ),
|
|
46
|
+
dz = abs( mul( fz, tan( fz ) ).add( 1 ).div( cosZ ) );
|
|
47
47
|
|
|
48
48
|
var HSL = vec3().toVar();
|
|
49
49
|
|
|
@@ -53,15 +53,41 @@ var scepterHead = TSLFn( ( params ) => {
|
|
|
53
53
|
|
|
54
54
|
var index = mod( ( add( indexX, indexY, indexZ ) ), 2 );
|
|
55
55
|
|
|
56
|
-
HSL.assign( toHsl( mix(
|
|
57
|
-
var color1 = hsl(
|
|
56
|
+
HSL.assign( toHsl( mix( colorA, colorB, index ) ) );
|
|
57
|
+
var color1 = hsl( vec3( HSL.xy, HSL.z.mul( k ) ) ).toVar( 'color1' );
|
|
58
58
|
|
|
59
|
-
HSL.assign( toHsl(
|
|
60
|
-
var color2 = hsl(
|
|
59
|
+
HSL.assign( toHsl( colorRim ) );
|
|
60
|
+
var color2 = hsl( vec3( HSL.xy, mul( 2, k, HSL.z ) ) ).toVar( 'color2' );
|
|
61
61
|
|
|
62
62
|
return mix( color1, color2, remapClamp( max( dx, max( dy, dz ) ), 55-10, 55+10 ) );
|
|
63
63
|
|
|
64
|
-
}
|
|
64
|
+
} ).setLayout( {
|
|
65
|
+
name: 'scepterHeadRaw',
|
|
66
|
+
type: 'vec3',
|
|
67
|
+
inputs: [
|
|
68
|
+
{ name: 'position', type: 'vec3' },
|
|
69
|
+
{ name: 'xFactor', type: 'float' },
|
|
70
|
+
{ name: 'yFactor', type: 'float' },
|
|
71
|
+
{ name: 'zFactor', type: 'float' },
|
|
72
|
+
{ name: 'colorRim', type: 'vec3' },
|
|
73
|
+
{ name: 'colorA', type: 'vec3' },
|
|
74
|
+
{ name: 'colorB', type: 'vec3' },
|
|
75
|
+
] }
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
function scepterHead( params={} ) {
|
|
81
|
+
|
|
82
|
+
var { position, xFactor, yFactor, zFactor, colorRim, colorA, colorB } = { ...defaults, ...params };
|
|
83
|
+
|
|
84
|
+
return scepterHeadRaw( position, xFactor, yFactor, zFactor, colorRim, colorA, colorB );
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
scepterHead.defaults = defaults;
|
|
65
91
|
|
|
66
92
|
|
|
67
93
|
|
package/src/scream.js
CHANGED
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { add, cos, exp, mix, positionGeometry, sin } from 'three/tsl';
|
|
8
|
-
import { hsl, noise,
|
|
7
|
+
import { add, cos, exp, Fn, mix, positionGeometry, sin, vec3 } from 'three/tsl';
|
|
8
|
+
import { hsl, noise, toHsl } from './tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
var defaults = {
|
|
13
13
|
$name: 'Scream',
|
|
14
14
|
|
|
15
|
+
position: positionGeometry,
|
|
15
16
|
scale: 2,
|
|
16
17
|
variety: 1,
|
|
17
18
|
|
|
@@ -23,39 +24,48 @@ var defaults = {
|
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
|
|
26
|
-
var
|
|
27
|
+
var screamRaw = Fn( ([ position, scale, variety, color, background, seed ]) => {
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var pos = positionGeometry.mul( exp( params.scale ) ).add( params.seed ).toVar( );
|
|
29
|
+
var pos = position.mul( exp( scale ) ).add( seed ).toVar( 'pos' );
|
|
31
30
|
|
|
32
31
|
var k = noise( add( sin( pos.xyz ), cos( pos.yzx ) ) );
|
|
33
32
|
|
|
34
|
-
pos.assign(
|
|
33
|
+
pos.assign( position.mul( exp( scale ).mul( k ) ).add( seed ) );
|
|
35
34
|
|
|
36
35
|
var k = noise( add( sin( pos.xyz ), cos( pos.yzx ) ).mul( 2 ) );
|
|
37
36
|
|
|
38
|
-
var col = mix(
|
|
37
|
+
var col = mix( background, color, k ).toVar( 'col' );
|
|
39
38
|
|
|
40
|
-
var HSL = toHsl( col ).toVar();
|
|
39
|
+
var HSL = toHsl( col ).toVar( 'HSL' );
|
|
41
40
|
|
|
42
|
-
return hsl( add( HSL.x,
|
|
41
|
+
return hsl( vec3( add( HSL.x, variety.mul( sin( k.mul( Math.PI ) ) ).mul( 0.5 ) ), HSL.yz ) );
|
|
43
42
|
|
|
44
|
-
}
|
|
43
|
+
} ).setLayout( {
|
|
44
|
+
name: 'satinRaw',
|
|
45
|
+
type: 'vec3',
|
|
46
|
+
inputs: [
|
|
47
|
+
{ name: 'position', type: 'vec3' },
|
|
48
|
+
{ name: 'scale', type: 'float' },
|
|
49
|
+
{ name: 'variety', type: 'float' },
|
|
50
|
+
{ name: 'color', type: 'vec3' },
|
|
51
|
+
{ name: 'background', type: 'vec3' },
|
|
52
|
+
{ name: 'seed', type: 'float' },
|
|
53
|
+
] }
|
|
54
|
+
);
|
|
45
55
|
|
|
46
56
|
|
|
47
57
|
|
|
48
|
-
scream
|
|
49
|
-
$name: 'Scream',
|
|
58
|
+
function scream( params={} ) {
|
|
50
59
|
|
|
51
|
-
scale
|
|
52
|
-
variety: 1,
|
|
60
|
+
var { position, scale, variety, color, background, seed } = { ...defaults, ...params };
|
|
53
61
|
|
|
54
|
-
color
|
|
55
|
-
background: new Color( 0xD09090 ),
|
|
62
|
+
return screamRaw( position, scale, variety, color, background, seed );
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
scream.defaults = defaults;
|
|
59
69
|
|
|
60
70
|
|
|
61
71
|
|
package/src/stars.js
CHANGED
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { abs, add, exp, mix, positionGeometry, select } from 'three/tsl';
|
|
8
|
-
import { hsl, noise,
|
|
7
|
+
import { abs, add, exp, Fn, mix, positionGeometry, select, vec3 } from 'three/tsl';
|
|
8
|
+
import { hsl, noise, toHsl } from './tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
var defaults = {
|
|
13
13
|
$name: 'Stars',
|
|
14
14
|
|
|
15
|
+
position: positionGeometry,
|
|
15
16
|
scale: 2,
|
|
16
17
|
density: 2,
|
|
17
18
|
variation: 0,
|
|
@@ -24,23 +25,47 @@ var defaults = {
|
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
var
|
|
28
|
+
var starsRaw = Fn( ([ position, scale, density, variation, color, background, seed ]) => {
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var pos = positionGeometry.mul( exp( params.scale.div( 2 ).add( 3 ) ) ).add( params.seed ).toVar( );
|
|
30
|
+
var pos = position.mul( exp( scale.div( 2 ).add( 3 ) ) ).add( seed ).toVar( );
|
|
32
31
|
|
|
33
32
|
var k = abs( noise( pos ) ).pow( 10 ).mul( 10 );
|
|
34
33
|
|
|
35
|
-
k = k.mul( exp(
|
|
34
|
+
k = k.mul( exp( density.sub( 2 ) ) );
|
|
35
|
+
|
|
36
|
+
var dS = select( k.greaterThan( 0.1 ), variation.mul( noise( pos ) ), 0 );
|
|
37
|
+
|
|
38
|
+
var col = toHsl( mix( background, color, k ) );
|
|
39
|
+
|
|
40
|
+
return hsl( vec3( add( col.x, dS ), col.yz ) );
|
|
41
|
+
|
|
42
|
+
} ).setLayout( {
|
|
43
|
+
name: 'starsRaw',
|
|
44
|
+
type: 'vec3',
|
|
45
|
+
inputs: [
|
|
46
|
+
{ name: 'position', type: 'vec3' },
|
|
47
|
+
{ name: 'scale', type: 'float' },
|
|
48
|
+
{ name: 'density', type: 'float' },
|
|
49
|
+
{ name: 'variation', type: 'float' },
|
|
50
|
+
{ name: 'color', type: 'vec3' },
|
|
51
|
+
{ name: 'background', type: 'vec3' },
|
|
52
|
+
{ name: 'seed', type: 'float' },
|
|
53
|
+
] }
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
function stars( params={} ) {
|
|
59
|
+
|
|
60
|
+
var { position, scale, density, variation, color, background, seed } = { ...defaults, ...params };
|
|
61
|
+
|
|
62
|
+
return starsRaw( position, scale, density, variation, color, background, seed );
|
|
36
63
|
|
|
37
|
-
|
|
64
|
+
}
|
|
38
65
|
|
|
39
|
-
var col = toHsl( mix( params.background, params.color, k ) );
|
|
40
66
|
|
|
41
|
-
return hsl( add( col.x, dS ), col.y, col.z );
|
|
42
67
|
|
|
43
|
-
|
|
68
|
+
stars.defaults = defaults;
|
|
44
69
|
|
|
45
70
|
|
|
46
71
|
|
package/src/static-noise.js
CHANGED
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import { clamp, exp, screenCoordinate, time, vec3 } from 'three/tsl';
|
|
7
|
-
import { noise,
|
|
6
|
+
import { clamp, exp, Fn, screenCoordinate, time, vec3 } from 'three/tsl';
|
|
7
|
+
import { noise, vnoise } from './tsl-utils.js';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
var defaults = {
|
|
12
12
|
$name: 'Static noise',
|
|
13
13
|
|
|
14
|
+
position: screenCoordinate,
|
|
15
|
+
time: time,
|
|
16
|
+
|
|
14
17
|
scale: 2,
|
|
15
18
|
balance: 0,
|
|
16
19
|
contrast: 0,
|
|
@@ -22,24 +25,48 @@ var defaults = {
|
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
params = prepare( params, defaults );
|
|
28
|
+
var staticNoiseRaw = Fn( ([ position, time, scale, balance, contrast, delay, seed ]) => {
|
|
28
29
|
|
|
29
|
-
var pos =
|
|
30
|
+
var pos = position.div( exp( scale ) ).add( seed );
|
|
30
31
|
|
|
31
|
-
var speed =
|
|
32
|
+
var speed = delay.sub( 1 ).mul( 5 ).exp(),
|
|
32
33
|
t = time.div( speed ).round().mul( speed );
|
|
33
34
|
|
|
34
35
|
var offset = vnoise( t.sin() ).mul( 1000 );
|
|
35
36
|
|
|
36
37
|
var k = clamp( 0, 1, noise( pos.add( offset ) ) );
|
|
37
38
|
|
|
38
|
-
k = k.mul( 0.5, exp(
|
|
39
|
+
k = k.mul( 0.5, exp( contrast ) ).add( 0.5, balance );
|
|
39
40
|
|
|
40
41
|
return vec3( k );
|
|
41
42
|
|
|
42
|
-
}
|
|
43
|
+
} ).setLayout( {
|
|
44
|
+
name: 'staticNoiseRaw',
|
|
45
|
+
type: 'vec3',
|
|
46
|
+
inputs: [
|
|
47
|
+
{ name: 'position', type: 'vec2' },
|
|
48
|
+
{ name: 'time', type: 'float' },
|
|
49
|
+
{ name: 'scale', type: 'float' },
|
|
50
|
+
{ name: 'balance', type: 'float' },
|
|
51
|
+
{ name: 'contrast', type: 'float' },
|
|
52
|
+
{ name: 'delay', type: 'float' },
|
|
53
|
+
{ name: 'seed', type: 'float' },
|
|
54
|
+
] }
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
function staticNoise( params={} ) {
|
|
60
|
+
|
|
61
|
+
var { position, time, scale, balance, contrast, delay, seed } = { ...defaults, ...params };
|
|
62
|
+
|
|
63
|
+
return staticNoiseRaw( position, time, scale, balance, contrast, delay, seed );
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
staticNoise.defaults = defaults;
|
|
43
70
|
|
|
44
71
|
|
|
45
72
|
|
package/src/supersphere.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import { cross, float, Fn, normalLocal, positionGeometry,
|
|
7
|
-
import {
|
|
6
|
+
import { cross, float, Fn, normalLocal, positionGeometry, tangentLocal } from 'three/tsl';
|
|
7
|
+
import { approximateNormal } from './tsl-utils.js';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -18,53 +18,90 @@ var defaults = {
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var surfacePos = Fn( ([ pos,
|
|
21
|
+
var surfacePos = Fn( ([ pos, exponent ])=>{
|
|
22
22
|
|
|
23
|
-
var
|
|
23
|
+
var xexponent = float( 2 ).pow( exponent );
|
|
24
24
|
var equPos = pos.div( pos.length() ).toVar();
|
|
25
|
+
var equPos2 = equPos.abs().pow( xexponent ).toVar();
|
|
25
26
|
|
|
26
|
-
var p =
|
|
27
|
-
.add(
|
|
28
|
-
.add(
|
|
29
|
-
.pow(
|
|
27
|
+
var p = equPos2.x
|
|
28
|
+
.add( equPos2.y )
|
|
29
|
+
.add( equPos2.z )
|
|
30
|
+
.pow( xexponent.reciprocal( ) );
|
|
30
31
|
|
|
31
32
|
return equPos.div( p );
|
|
32
33
|
|
|
34
|
+
} ).setLayout( {
|
|
35
|
+
name: 'surfacePos',
|
|
36
|
+
type: 'vec3',
|
|
37
|
+
inputs: [
|
|
38
|
+
{ name: 'pos', type: 'vec3' },
|
|
39
|
+
{ name: 'exponent', type: 'float' },
|
|
40
|
+
]
|
|
33
41
|
} );
|
|
34
42
|
|
|
35
43
|
|
|
36
44
|
|
|
37
|
-
var
|
|
45
|
+
var supersphereRaw = Fn( ([ exponent ])=>{
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return surfacePos( positionGeometry, params );
|
|
42
|
-
|
|
43
|
-
}, defaults );
|
|
47
|
+
return surfacePos( positionGeometry, exponent );
|
|
44
48
|
|
|
49
|
+
} ).setLayout( {
|
|
50
|
+
name: 'supersphereRaw',
|
|
51
|
+
type: 'vec3',
|
|
52
|
+
inputs: [
|
|
53
|
+
{ name: 'exponent', type: 'float' },
|
|
54
|
+
]
|
|
55
|
+
} );
|
|
45
56
|
|
|
46
57
|
|
|
47
|
-
supersphere.normal = TSLFn( ( params ) => {
|
|
48
58
|
|
|
49
|
-
|
|
59
|
+
var supersphereNormalRaw = Fn( ([ exponent ]) => {
|
|
50
60
|
|
|
51
|
-
|
|
61
|
+
const EPS = 0.01;
|
|
52
62
|
|
|
53
63
|
var position = positionGeometry,
|
|
54
64
|
normal = normalLocal.normalize().toVar(),
|
|
55
|
-
tangent = tangentLocal.normalize().mul(
|
|
56
|
-
bitangent = cross( normal, tangent ).normalize().mul(
|
|
65
|
+
tangent = tangentLocal.normalize().mul( EPS ).toVar(),
|
|
66
|
+
bitangent = cross( normal, tangent ).normalize().mul( EPS ).toVar();
|
|
67
|
+
|
|
68
|
+
var pos = surfacePos( position, exponent );
|
|
69
|
+
var posU = surfacePos( position.add( tangent ), exponent );
|
|
70
|
+
var posV = surfacePos( position.add( bitangent ), exponent );
|
|
71
|
+
|
|
72
|
+
return approximateNormal( pos, posU, posV );
|
|
73
|
+
|
|
74
|
+
} ).setLayout( {
|
|
75
|
+
name: 'supersphereRaw',
|
|
76
|
+
type: 'vec3',
|
|
77
|
+
inputs: [
|
|
78
|
+
{ name: 'exponent', type: 'float' },
|
|
79
|
+
]
|
|
80
|
+
} );
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
function supersphere( params={} ) {
|
|
57
85
|
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
86
|
+
var { exponent } = { ...defaults, ...params };
|
|
87
|
+
|
|
88
|
+
return supersphereRaw( exponent );
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
supersphere.normal = function ( params={} ) {
|
|
95
|
+
|
|
96
|
+
var { exponent } = { ...defaults, ...params };
|
|
97
|
+
|
|
98
|
+
return supersphereNormalRaw( exponent );
|
|
99
|
+
|
|
100
|
+
};
|
|
61
101
|
|
|
62
|
-
var dU = sub( posU, pos ),
|
|
63
|
-
dV = sub( posV, pos );
|
|
64
102
|
|
|
65
|
-
return transformNormalToView( cross( dU, dV ).normalize() );
|
|
66
103
|
|
|
67
|
-
|
|
104
|
+
supersphere.defaults = defaults;
|
|
68
105
|
|
|
69
106
|
|
|
70
107
|
|