tsl-textures 0.21.0 → 1.1.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 +11 -0
- package/package.json +1 -1
- package/src/camouflage.js +4 -4
- package/src/cave-art.js +11 -11
- package/src/circles.js +6 -2
- package/src/clouds.js +1 -1
- package/src/concrete.js +1 -1
- package/src/cork.js +1 -1
- package/src/dalmatian-spots.js +1 -1
- package/src/dyson-sphere.js +1 -1
- package/src/entangled.js +1 -1
- package/src/fordite.js +1 -1
- package/src/gas-giant.js +1 -1
- package/src/grid.js +1 -1
- package/src/isolines.js +1 -1
- package/src/karst-rock.js +1 -1
- package/src/marble.js +2 -2
- package/src/neon-lights.js +1 -1
- package/src/photosphere.js +1 -1
- package/src/planet.js +1 -1
- package/src/polka-dots.js +1 -1
- package/src/processed-wood.js +1 -1
- package/src/protozoa.js +1 -1
- package/src/rotator.js +72 -0
- package/src/rust.js +1 -1
- package/src/satin.js +1 -1
- package/src/scepter-head.js +1 -1
- package/src/scream.js +1 -1
- package/src/simplex-noise.js +1 -1
- package/src/stars.js +1 -1
- package/src/tiger-fur.js +1 -1
- package/src/tsl-utils.js +193 -32
- package/src/voronoi-cells.js +1 -1
- package/src/water-drops.js +1 -1
- package/src/wood.js +1 -1
- package/src/zebra-lines.js +1 -1
package/README.md
CHANGED
|
@@ -42,3 +42,14 @@ station is constructed arounnd the blob. The surface of the station is made of
|
|
|
42
42
|
a Dyson sphere texture from [dyson-texture.js](https://boytchev.github.io/tsl-textures/docs/dyson-sphere.html).
|
|
43
43
|
|
|
44
44
|
[<img src="https://boytchev.github.io/tsl-textures/examples/example-protozoa.jpg">](https://boytchev.github.io/tsl-textures/examples/example-protozoa.html)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
#### Example "Neck Massage"
|
|
48
|
+
|
|
49
|
+
Uses [rotator.js](https://boytchev.github.io/tsl-textures/docs/rotator.html)
|
|
50
|
+
texture that applies soft matrices on model vertices. This allows to make
|
|
51
|
+
gradual rotation that looks like stretching skin and flexing muscles. The
|
|
52
|
+
animation does not use skinning or morphing, the model is not preprocessed
|
|
53
|
+
in any way, and no additional vertex data is added.
|
|
54
|
+
|
|
55
|
+
[<img src="https://boytchev.github.io/tsl-textures/examples/example-neck-massage.jpg">](https://boytchev.github.io/tsl-textures/examples/example-neck-massage.html)
|
package/package.json
CHANGED
package/src/camouflage.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from 'three';
|
|
7
|
-
import { exp, If, positionLocal, round, tslFn, vec3 } from 'three
|
|
7
|
+
import { exp, If, positionLocal, round, tslFn, vec3 } from 'three';
|
|
8
8
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
|
@@ -15,19 +15,19 @@ var camouflage = tslFn( ( params )=>{
|
|
|
15
15
|
|
|
16
16
|
var color = vec3( 0, 0, 0 ).toVar( );
|
|
17
17
|
|
|
18
|
-
If( round( noise( pos
|
|
18
|
+
If( round( noise( pos, 1, 0.2 ) ).greaterThanEqual( 1 ), () => {
|
|
19
19
|
|
|
20
20
|
color.assign( params.colorA );
|
|
21
21
|
|
|
22
22
|
}
|
|
23
23
|
)
|
|
24
|
-
.elseif( round( noise( pos.yzx
|
|
24
|
+
.elseif( round( noise( pos.yzx, 1, 0.3 ) ).greaterThanEqual( 1 ), () => {
|
|
25
25
|
|
|
26
26
|
color.assign( params.colorB );
|
|
27
27
|
|
|
28
28
|
}
|
|
29
29
|
)
|
|
30
|
-
.elseif( round( noise( pos.zxy
|
|
30
|
+
.elseif( round( noise( pos.zxy, 1, 0.4 ) ).greaterThanEqual( 1 ), () => {
|
|
31
31
|
|
|
32
32
|
color.assign( params.colorC );
|
|
33
33
|
|
package/src/cave-art.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { abs, add, exp, float, If, mix, or, positionLocal, pow2, sub, tslFn } from 'three
|
|
7
|
+
import { abs, add, exp, float, If, mix, or, positionLocal, pow2, sub, tslFn } from 'three';
|
|
8
8
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
|
@@ -12,22 +12,22 @@ var caveArt = tslFn( ( params ) => {
|
|
|
12
12
|
|
|
13
13
|
var pos = positionLocal.mul( exp( params.scale ) ).add( params.seed ).toVar( );
|
|
14
14
|
|
|
15
|
-
var k1 = noise( pos
|
|
16
|
-
var k2 = noise( pos.mul( 1.5 )
|
|
15
|
+
var k1 = noise( pos, 4 ).sin().toVar();
|
|
16
|
+
var k2 = noise( pos.mul( 1.5 ), 4 ).cos().toVar();
|
|
17
17
|
|
|
18
18
|
var thinness = exp( sub( float( 3 ), params.thinness ) );
|
|
19
19
|
var k = sub( thinness, pow2( abs( add( k1, k2 ) ) ).mul( 20 ) ).toVar();
|
|
20
20
|
|
|
21
|
-
If( or( k1.greaterThan( k2 ), k.lessThan( 0 ) ), ()=>{
|
|
22
|
-
|
|
23
|
-
k.assign( 0 );
|
|
24
|
-
|
|
21
|
+
If( or( k1.greaterThan( k2 ), k.lessThan( 0 ) ), ()=>{
|
|
22
|
+
|
|
23
|
+
k.assign( 0 );
|
|
24
|
+
|
|
25
25
|
} );
|
|
26
26
|
|
|
27
|
-
If( k.lessThanEqual( 0 ), ()=>{
|
|
28
|
-
|
|
29
|
-
k.assign( params.noise.mul( pow2( noise( pos.mul( 30 ) ) ) ) );
|
|
30
|
-
|
|
27
|
+
If( k.lessThanEqual( 0 ), ()=>{
|
|
28
|
+
|
|
29
|
+
k.assign( params.noise.mul( pow2( noise( pos.mul( 30 ) ) ) ) );
|
|
30
|
+
|
|
31
31
|
} );
|
|
32
32
|
|
|
33
33
|
return mix( params.background, params.color, k );
|
package/src/circles.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { acos, clamp, cond, exp, float, positionLocal, sin, tslFn } from 'three
|
|
7
|
+
import { acos, clamp, cond, exp, float, positionLocal, sin, tslFn } from 'three';
|
|
8
8
|
import { hsl, toHsl } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
|
@@ -20,8 +20,12 @@ var circles = tslFn( ( params ) => {
|
|
|
20
20
|
var x = angle.div( 3000 ).mul( scale );
|
|
21
21
|
|
|
22
22
|
var k = float( params.seed.sin().mul( 100 ) ).toVar();
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
for ( var n=0; n<=10; n++ ) {
|
|
25
|
+
|
|
24
26
|
k.addAssign( sin( x.mul( 2**n ).sub( Math.PI*n/2 ) ).mul( -n*( n+1 )/2 ) );
|
|
27
|
+
|
|
28
|
+
}
|
|
25
29
|
|
|
26
30
|
k.assign( k.div( 200 ).clamp( -2, 2 ) );
|
|
27
31
|
|
package/src/clouds.js
CHANGED
package/src/concrete.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import { abs, cos, cross, exp, modelNormalMatrix, normalLocal, positionLocal, pow, remap, sin, sub, tangentLocal, tslFn, vec3 } from 'three
|
|
6
|
+
import { abs, cos, cross, exp, modelNormalMatrix, normalLocal, positionLocal, pow, remap, sin, sub, tangentLocal, tslFn, vec3 } from 'three';
|
|
7
7
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
8
8
|
|
|
9
9
|
|
package/src/cork.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from 'three';
|
|
7
|
-
import { exp, float, If, loop, mix, positionLocal, tslFn, vec3 } from 'three
|
|
7
|
+
import { exp, float, If, loop, mix, positionLocal, tslFn, vec3 } from 'three';
|
|
8
8
|
import { noise, vnoise } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
package/src/dalmatian-spots.js
CHANGED
package/src/dyson-sphere.js
CHANGED
package/src/entangled.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { abs, exp, float, floor, loop, max, mix, mul, oneMinus, positionLocal, pow, sin, tslFn } from 'three
|
|
7
|
+
import { abs, exp, float, floor, loop, max, mix, mul, oneMinus, positionLocal, pow, sin, tslFn } from 'three';
|
|
8
8
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
package/src/fordite.js
CHANGED
package/src/gas-giant.js
CHANGED
package/src/grid.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { abs, add, div, equirectUV, min, mix, mul, oneMinus, positionLocal, pow, remapClamp, round, sin, smoothstep, sub, tslFn } from 'three
|
|
7
|
+
import { abs, add, div, equirectUV, min, mix, mul, oneMinus, positionLocal, pow, remapClamp, round, sin, smoothstep, sub, tslFn } from 'three';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
package/src/isolines.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { add, exp, mix, oneMinus, positionLocal, sin, smoothstep, sub, tslFn } from 'three
|
|
7
|
+
import { add, exp, mix, oneMinus, positionLocal, sin, smoothstep, sub, tslFn } from 'three';
|
|
8
8
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
package/src/karst-rock.js
CHANGED
package/src/marble.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { add, div, exp, If, mix, mul, oneMinus, positionLocal, pow, tslFn } from 'three
|
|
7
|
+
import { add, div, exp, If, mix, mul, oneMinus, positionLocal, pow, tslFn } from 'three';
|
|
8
8
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
|
@@ -19,7 +19,7 @@ var marble = tslFn( ( params ) => {
|
|
|
19
19
|
noise( pos.mul( 6 ) ).mul( 0.1 )
|
|
20
20
|
);
|
|
21
21
|
|
|
22
|
-
var k = oneMinus( k.abs().pow( 2.5 ) );
|
|
22
|
+
var k = oneMinus( k.abs().pow( 2.5 ) ).toVar();
|
|
23
23
|
|
|
24
24
|
var maxSmooth = oneMinus( pow( 0.5, params.thinness.add( 7 ) ) ).toVar(),
|
|
25
25
|
minSmooth = oneMinus( pow( 0.5, params.thinness.add( 7 ).mul( 0.5 ) ) ).toVar();
|
package/src/neon-lights.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { abs, cond, exp, oneMinus, positionLocal, sqrt, tslFn, vec3 } from 'three
|
|
7
|
+
import { abs, cond, exp, oneMinus, positionLocal, sqrt, tslFn, vec3 } from 'three';
|
|
8
8
|
import { hsl, noise, toHsl } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
package/src/photosphere.js
CHANGED
package/src/planet.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from 'three';
|
|
7
|
-
import { exp, float, If, loop, mix, mul, positionLocal, remap, smoothstep, tslFn, vec3 } from 'three
|
|
7
|
+
import { exp, float, If, loop, mix, mul, positionLocal, remap, smoothstep, tslFn, vec3 } from 'three';
|
|
8
8
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
package/src/polka-dots.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { acos, add, distance, exp, float, loop, max, min, mix, mod, mul, oneMinus, positionLocal, pow, smoothstep, tslFn, } from 'three
|
|
7
|
+
import { acos, add, distance, exp, float, loop, max, min, mix, mod, mul, oneMinus, positionLocal, pow, smoothstep, tslFn, } from 'three';
|
|
8
8
|
import { spherical } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
package/src/processed-wood.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { add, cos, exp, mix, positionLocal, radians, sin, sub, tslFn, vec3 } from 'three
|
|
7
|
+
import { add, cos, exp, mix, positionLocal, radians, sin, sub, tslFn, vec3 } from 'three';
|
|
8
8
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
package/src/protozoa.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { exp, float, loop, matcapUV, mix, positionLocal, tslFn, vec3 } from 'three
|
|
7
|
+
import { exp, float, loop, matcapUV, mix, positionLocal, tslFn, vec3 } from 'three';
|
|
8
8
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
package/src/rotator.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Rotator
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Vector2, Vector3 } from "three";
|
|
7
|
+
import { cross, modelNormalMatrix, normalLocal, positionLocal, sub, tangentLocal, tslFn, vec4 } from 'three';
|
|
8
|
+
import { matRotYXZ, matTrans, selectPlanar } from 'tsl-textures/tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var surfacePos = tslFn( ([ pos, params ])=>{
|
|
13
|
+
|
|
14
|
+
var zone = selectPlanar( pos, params.selectorAngles, params.selectorCenter, params.selectorWidth );
|
|
15
|
+
|
|
16
|
+
var R = matRotYXZ( params.angles.mul( zone ) ),
|
|
17
|
+
T = matTrans( params.center ),
|
|
18
|
+
TN = matTrans( params.center.negate() );
|
|
19
|
+
|
|
20
|
+
return T.mul( R ).mul( TN ).mul( vec4( pos, 1 ) ).xyz;
|
|
21
|
+
|
|
22
|
+
} );
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var rotator = tslFn( ( params )=>{
|
|
27
|
+
|
|
28
|
+
return surfacePos( positionLocal, params );
|
|
29
|
+
|
|
30
|
+
} );
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
rotator.normal = tslFn( ( params ) => {
|
|
35
|
+
|
|
36
|
+
var eps = 0.01;
|
|
37
|
+
|
|
38
|
+
var position = positionLocal,
|
|
39
|
+
normal = normalLocal.normalize().toVar(),
|
|
40
|
+
tangent = tangentLocal.normalize().mul( eps ).toVar(),
|
|
41
|
+
bitangent = cross( normal, tangent ).normalize().mul( eps ).toVar();
|
|
42
|
+
|
|
43
|
+
var pos = surfacePos( position, params );
|
|
44
|
+
var posU = surfacePos( position.add( tangent ), params );
|
|
45
|
+
var posV = surfacePos( position.add( bitangent ), params );
|
|
46
|
+
|
|
47
|
+
var dU = sub( posU, pos ),
|
|
48
|
+
dV = sub( posV, pos );
|
|
49
|
+
|
|
50
|
+
return modelNormalMatrix.mul( cross( dU, dV ).normalize() );
|
|
51
|
+
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
rotator.defaults = {
|
|
57
|
+
$name: 'Rotator',
|
|
58
|
+
$positionNode: true,
|
|
59
|
+
$selectorPlanar: true,
|
|
60
|
+
|
|
61
|
+
angles: new Vector3( 0, 0, 0 ),
|
|
62
|
+
center: new Vector3( 0, 0, 0 ),
|
|
63
|
+
|
|
64
|
+
selectorCenter: new Vector3( 0, 0, 0 ),
|
|
65
|
+
selectorAngles: new Vector2( 0, 0 ),
|
|
66
|
+
selectorWidth: 2,
|
|
67
|
+
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
export { rotator };
|
package/src/rust.js
CHANGED
package/src/satin.js
CHANGED
package/src/scepter-head.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { abs, add, cos, floor, max, mix, mod, mul, positionLocal, remapClamp, sign, tan, tslFn, vec3 } from 'three
|
|
7
|
+
import { abs, add, cos, floor, max, mix, mod, mul, positionLocal, remapClamp, sign, tan, tslFn, vec3 } from 'three';
|
|
8
8
|
import { hsl, noise, remapExp, toHsl } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
package/src/scream.js
CHANGED
package/src/simplex-noise.js
CHANGED
package/src/stars.js
CHANGED
package/src/tiger-fur.js
CHANGED
package/src/tsl-utils.js
CHANGED
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
import { add, cond, cos, cross, float, If, log2, max, min, mul, pow, remap, sin, sub, tslFn, uniform, vec3, vec4 } from 'three
|
|
12
|
-
import { mx_perlin_noise_float as noise } from 'three/
|
|
11
|
+
import { add, cond, cos, cross, float, If, log2, mat4, max, min, mul, positionLocal, pow, remap, sin, smoothstep, sub, tslFn, uniform, vec3, vec4, Vector3 } from 'three';
|
|
12
|
+
//import { mx_perlin_noise_float as noise } from 'https://cdn.jsdelivr.net/npm/three@0.167.0/src/nodes/materialx/lib/mx_noise.js';
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
// helper function - convert hsl to rgb, ported to TSL from:
|
|
16
16
|
// https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative
|
|
17
17
|
|
|
18
|
-
const hslHelper = tslFn( ([ h, s, l, n ])=>{
|
|
18
|
+
const hslHelper = tslFn( ([ h, s, l, n ])=>{
|
|
19
19
|
|
|
20
20
|
var k = n.add( h.mul( 12 ) ).mod( 12 );
|
|
21
21
|
var a = s.mul( min( l, sub( 1, l ) ) );
|
|
22
22
|
return l.sub( a.mul( max( -1, min( min( k.sub( 3 ), sub( 9, k ) ), 1 ) ) ) );
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
} );
|
|
25
25
|
|
|
26
26
|
hslHelper.setLayout( {
|
|
@@ -48,7 +48,7 @@ const hsl = tslFn( ([ h, s, l ]) => {
|
|
|
48
48
|
var b = hslHelper( h, s, l, 4 );
|
|
49
49
|
|
|
50
50
|
return vec3( r, g, b );
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
} );
|
|
53
53
|
|
|
54
54
|
hsl.setLayout( {
|
|
@@ -63,7 +63,7 @@ hsl.setLayout( {
|
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
// convert from rgb to hsl
|
|
66
|
-
const toHsl = tslFn( ([ rgb ]) => {
|
|
66
|
+
const toHsl = tslFn( ([ rgb ]) => {
|
|
67
67
|
|
|
68
68
|
var R = float( rgb.x ).toVar(),
|
|
69
69
|
G = float( rgb.y ).toVar(),
|
|
@@ -81,26 +81,26 @@ const toHsl = tslFn( ([ rgb ]) => {
|
|
|
81
81
|
const delta = sub( mx, mn ).toVar();
|
|
82
82
|
|
|
83
83
|
S.assign( cond( L.lessThanEqual( 0.5 ), delta.div( add( mn, mx ) ), delta.div( sub( 2, add( mn, mx ) ) ) ) );
|
|
84
|
-
If( mx.equal( R ), ()=>{
|
|
85
|
-
|
|
86
|
-
H.assign( sub( G, B ).div( delta ).add( cond( G.lessThanEqual( B ), 6, 0 ) ) );
|
|
87
|
-
|
|
84
|
+
If( mx.equal( R ), ()=>{
|
|
85
|
+
|
|
86
|
+
H.assign( sub( G, B ).div( delta ).add( cond( G.lessThanEqual( B ), 6, 0 ) ) );
|
|
87
|
+
|
|
88
88
|
} )
|
|
89
|
-
.elseif( mx.equal( G ), ()=>{
|
|
90
|
-
|
|
91
|
-
H.assign( sub( B, R ).div( delta ).add( 2 ) );
|
|
92
|
-
|
|
89
|
+
.elseif( mx.equal( G ), ()=>{
|
|
90
|
+
|
|
91
|
+
H.assign( sub( B, R ).div( delta ).add( 2 ) );
|
|
92
|
+
|
|
93
93
|
} )
|
|
94
|
-
.else( ()=>{
|
|
95
|
-
|
|
96
|
-
H.assign( sub( R, G ).div( delta ).add( 4 ) );
|
|
97
|
-
|
|
94
|
+
.else( ()=>{
|
|
95
|
+
|
|
96
|
+
H.assign( sub( R, G ).div( delta ).add( 4 ) );
|
|
97
|
+
|
|
98
98
|
} );
|
|
99
99
|
H.divAssign( 6 );
|
|
100
100
|
|
|
101
101
|
} );
|
|
102
102
|
return vec3( H, S, L );
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
} );
|
|
105
105
|
|
|
106
106
|
|
|
@@ -108,32 +108,38 @@ const toHsl = tslFn( ([ rgb ]) => {
|
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
// make all elements dynamic (i.e. uniform)
|
|
111
|
-
function dynamic( params ) {
|
|
111
|
+
function dynamic( params ) {
|
|
112
112
|
|
|
113
113
|
var result = {};
|
|
114
114
|
|
|
115
115
|
for ( var [ key, value ] of Object.entries( params ) ) {
|
|
116
116
|
|
|
117
|
-
if ( key[ 0 ]!='$' )
|
|
118
|
-
|
|
117
|
+
if ( key[ 0 ]!='$' ) {
|
|
118
|
+
|
|
119
|
+
if ( value instanceof Vector3 )
|
|
120
|
+
result[ key ] = uniform( value, 'vec3' );
|
|
121
|
+
else
|
|
122
|
+
result[ key ] = uniform( value );
|
|
123
|
+
|
|
124
|
+
}
|
|
119
125
|
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
return result;
|
|
123
|
-
|
|
129
|
+
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
|
|
127
133
|
|
|
128
134
|
// convert phi-theta angles to position on unit sphere
|
|
129
|
-
const spherical = tslFn( ([ phi, theta ]) => {
|
|
135
|
+
const spherical = tslFn( ([ phi, theta ]) => {
|
|
130
136
|
|
|
131
137
|
return vec3(
|
|
132
138
|
sin( theta ).mul( sin( phi ) ),
|
|
133
139
|
cos( phi ),
|
|
134
140
|
cos( theta ).mul( sin( phi ) )
|
|
135
141
|
);
|
|
136
|
-
|
|
142
|
+
|
|
137
143
|
} );
|
|
138
144
|
|
|
139
145
|
spherical.setLayout( {
|
|
@@ -148,11 +154,11 @@ spherical.setLayout( {
|
|
|
148
154
|
|
|
149
155
|
|
|
150
156
|
// apply Euler rotation to a vector
|
|
151
|
-
const applyEuler = tslFn( ([ vec, eu ]) => {
|
|
157
|
+
const applyEuler = tslFn( ([ vec, eu ]) => {
|
|
152
158
|
|
|
153
159
|
var quat = quaternionFromEuler( eu );
|
|
154
160
|
return applyQuaternion( vec, quat );
|
|
155
|
-
|
|
161
|
+
|
|
156
162
|
} );
|
|
157
163
|
|
|
158
164
|
|
|
@@ -183,7 +189,7 @@ const applyQuaternion = tslFn( ([ vec, quat ]) => {
|
|
|
183
189
|
var t = cross( quat, vec ).mul( 2 ).toVar( );
|
|
184
190
|
|
|
185
191
|
return add( vec, t.mul( quat.w ), cross( quat.xyz, t ) );
|
|
186
|
-
|
|
192
|
+
|
|
187
193
|
} );
|
|
188
194
|
|
|
189
195
|
|
|
@@ -205,7 +211,7 @@ function mapExp( x, toMin, toMax, fromMin=0, fromMax=100 ) {
|
|
|
205
211
|
|
|
206
212
|
}
|
|
207
213
|
*/
|
|
208
|
-
|
|
214
|
+
|
|
209
215
|
} );
|
|
210
216
|
|
|
211
217
|
|
|
@@ -218,14 +224,169 @@ const vnoise = tslFn( ([ v ])=>{
|
|
|
218
224
|
} );
|
|
219
225
|
|
|
220
226
|
|
|
227
|
+
|
|
228
|
+
// generate X-rotation matrix
|
|
229
|
+
const matRotX = tslFn( ([ angle ])=>{
|
|
230
|
+
|
|
231
|
+
var cos = angle.cos().toVar(),
|
|
232
|
+
sin = angle.sin().toVar();
|
|
233
|
+
|
|
234
|
+
return mat4(
|
|
235
|
+
1, 0, 0, 0,
|
|
236
|
+
0, cos, sin, 0,
|
|
237
|
+
0, sin.negate(), cos, 0,
|
|
238
|
+
0, 0, 0, 1 );
|
|
239
|
+
|
|
240
|
+
} );
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
// generate Y-rotation matrix
|
|
245
|
+
const matRotY = tslFn( ([ angle ])=>{
|
|
246
|
+
|
|
247
|
+
var cos = angle.cos().toVar(),
|
|
248
|
+
sin = angle.sin().toVar();
|
|
249
|
+
|
|
250
|
+
return mat4(
|
|
251
|
+
cos, 0, sin.negate(), 0,
|
|
252
|
+
0, 1, 0, 0,
|
|
253
|
+
sin, 0, cos, 0,
|
|
254
|
+
0, 0, 0, 1 );
|
|
255
|
+
|
|
256
|
+
} );
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
// generate Z-rotation matrix
|
|
261
|
+
const matRotZ = tslFn( ([ angle ])=>{
|
|
262
|
+
|
|
263
|
+
var cos = angle.cos().toVar(),
|
|
264
|
+
sin = angle.sin().toVar();
|
|
265
|
+
|
|
266
|
+
return mat4(
|
|
267
|
+
cos, sin, 0, 0,
|
|
268
|
+
sin.negate(), cos, 0, 0,
|
|
269
|
+
0, 0, 1, 0,
|
|
270
|
+
0, 0, 0, 1 );
|
|
271
|
+
|
|
272
|
+
} );
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
// generate YXZ rotation matrix
|
|
277
|
+
const matRotYXZ = tslFn( ([ angles ])=>{
|
|
278
|
+
|
|
279
|
+
var RX = matRotX( angles.x ),
|
|
280
|
+
RY = matRotY( angles.y ),
|
|
281
|
+
RZ = matRotZ( angles.z );
|
|
282
|
+
|
|
283
|
+
return RY.mul( RX ).mul( RZ );
|
|
284
|
+
|
|
285
|
+
} );
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
// generate translation matrix
|
|
290
|
+
const matTrans = tslFn( ([ vector ])=>{
|
|
291
|
+
|
|
292
|
+
return mat4(
|
|
293
|
+
1, 0, 0, 0,
|
|
294
|
+
0, 1, 0, 0,
|
|
295
|
+
0, 0, 1, 0,
|
|
296
|
+
vector.x, vector.y, vector.z, 1 );
|
|
297
|
+
|
|
298
|
+
} );
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
/*
|
|
302
|
+
const selectLinear = tslFn( ( [c,a,b] )=>{
|
|
303
|
+
|
|
304
|
+
// C is projected on segment AB
|
|
305
|
+
// result is [0,1] inside AB, 0 before A, 1 after B
|
|
306
|
+
|
|
307
|
+
var ca = a.sub(c),
|
|
308
|
+
ab = b.sub(a).toVar();
|
|
309
|
+
|
|
310
|
+
var caab = ca.dot(ab),
|
|
311
|
+
abab = ab.dot(ab);
|
|
312
|
+
|
|
313
|
+
var k = caab.div(abab).negate();
|
|
314
|
+
|
|
315
|
+
return smoothstep(0,1,k);
|
|
316
|
+
|
|
317
|
+
} );
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
const selectPlanar = tslFn( ([ pos, selAngles, selCenter, selWidth ])=>{
|
|
321
|
+
|
|
322
|
+
// select zone in a plane through point selCenter,
|
|
323
|
+
// rotated according to selAngles and selWidth thick
|
|
324
|
+
// result is [0,1] inside plane, 0 below plane, 1 above plane
|
|
325
|
+
|
|
326
|
+
// C is projected on segment AB
|
|
327
|
+
// result is [0,1] inside AB, 0 before A, 1 after B
|
|
328
|
+
|
|
329
|
+
/* non-optimized version
|
|
330
|
+
var s = spherical(selAngles.x,selAngles.y).mul(selWidth).toVar(),
|
|
331
|
+
c = pos,
|
|
332
|
+
a = selCenter.sub(s.div(2)),
|
|
333
|
+
b = selCenter.add(s.div(2));
|
|
334
|
+
|
|
335
|
+
var ca = a.sub(c),
|
|
336
|
+
ab = b.sub(a).toVar();
|
|
337
|
+
|
|
338
|
+
var caab = ca.dot(s),
|
|
339
|
+
abab = ab.dot(ab);
|
|
340
|
+
|
|
341
|
+
var k = caab.div(abab).negate();
|
|
342
|
+
*/
|
|
343
|
+
|
|
344
|
+
var s = spherical( selAngles.x, selAngles.y ).mul( selWidth ).toVar();
|
|
345
|
+
|
|
346
|
+
var k = selCenter.sub( s.div( 2 ) ).sub( pos ).dot( s ).div( s.dot( s ) ).negate();
|
|
347
|
+
|
|
348
|
+
return smoothstep( 0, 1, k );
|
|
349
|
+
|
|
350
|
+
} );
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
const overlayPlanar = tslFn( ( params )=>{
|
|
355
|
+
|
|
356
|
+
var zone = selectPlanar(
|
|
357
|
+
positionLocal,
|
|
358
|
+
params.selectorAngles,
|
|
359
|
+
params.selectorCenter,
|
|
360
|
+
params.selectorWidth
|
|
361
|
+
).sub( 0.5 ).mul( 2 ).abs().oneMinus().pow( 0.25 ).negate().mul(
|
|
362
|
+
params.selectorShow
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
return vec3( 0, zone, zone );
|
|
366
|
+
|
|
367
|
+
} );
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
export
|
|
372
|
+
{
|
|
373
|
+
mx_noise_float as noise
|
|
374
|
+
} from 'three';
|
|
375
|
+
|
|
221
376
|
export
|
|
222
377
|
{
|
|
223
|
-
noise,
|
|
224
378
|
vnoise,
|
|
225
379
|
hsl,
|
|
226
380
|
toHsl,
|
|
227
381
|
dynamic,
|
|
228
382
|
spherical,
|
|
229
383
|
applyEuler,
|
|
230
|
-
remapExp
|
|
231
|
-
|
|
384
|
+
remapExp,
|
|
385
|
+
matRotX,
|
|
386
|
+
matRotY,
|
|
387
|
+
matRotZ,
|
|
388
|
+
matRotYXZ,
|
|
389
|
+
matTrans,
|
|
390
|
+
selectPlanar,
|
|
391
|
+
overlayPlanar
|
|
392
|
+
};
|
package/src/voronoi-cells.js
CHANGED
package/src/water-drops.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import { cos, cross, exp, modelNormalMatrix, normalLocal, positionLocal, remap, sin, sub, tangentLocal, tslFn, vec3 } from 'three
|
|
6
|
+
import { cos, cross, exp, modelNormalMatrix, normalLocal, positionLocal, remap, sin, sub, tangentLocal, tslFn, vec3 } from 'three';
|
|
7
7
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
8
8
|
|
|
9
9
|
|
package/src/wood.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from 'three';
|
|
7
|
-
import { add, cos, exp, float, loop, mix, mul, positionLocal, radians, reciprocal, sin, sub, tslFn, vec3 } from 'three
|
|
7
|
+
import { add, cos, exp, float, loop, mix, mul, positionLocal, radians, reciprocal, sin, sub, tslFn, vec3 } from 'three';
|
|
8
8
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
package/src/zebra-lines.js
CHANGED