tsl-textures 0.10.0 → 0.12.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/voronoi-cells.js +79 -0
- package/src/wood.js +64 -0
- package/src/circles.js.bak +0 -56
package/README.md
CHANGED
|
@@ -21,3 +21,14 @@ The normal are created directly without using any of the TSL texture generators.
|
|
|
21
21
|
Click on the image for a live demo.
|
|
22
22
|
|
|
23
23
|
[<img src="https://boytchev.github.io/tsl-textures/examples/example-normal-map.jpg">](https://boytchev.github.io/tsl-textures/examples/example-normal-map.html)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
#### Example "Wooden toys"
|
|
27
|
+
|
|
28
|
+
Uses [wood.js](https://boytchev.github.io/tsl-textures/docs/wood.html) texture
|
|
29
|
+
to convert flat-color 3D models (an ambulance, a race car and a luxury SUV from
|
|
30
|
+
Car Kit (1.4) by Kenney [www.kenney.nl](https://www.kenney.nl/)) into wooden toys.
|
|
31
|
+
All the wood textures are procedurally generated in real-time. Click on the image
|
|
32
|
+
for a live demo. (Note: non-WebGPU browsers might need 30+ seconds to start up.)
|
|
33
|
+
|
|
34
|
+
[<img src="https://boytchev.github.io/tsl-textures/examples/example-wooden-toys.jpg">](https://boytchev.github.io/tsl-textures/examples/example-wooden-toys.html)
|
package/package.json
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Voronoi Cells
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from 'three';
|
|
7
|
+
import { exp, float, If, loop, mix, positionLocal, tslFn, vec3 } from 'three/nodes';
|
|
8
|
+
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var cellCenter = tslFn( ([ cell ])=>{
|
|
13
|
+
|
|
14
|
+
return cell.add( noise( cell.mul( Math.PI ) ) );
|
|
15
|
+
|
|
16
|
+
} );
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
var voronoiCells = tslFn( ( params )=>{
|
|
20
|
+
|
|
21
|
+
var pos = positionLocal.mul( exp( params.scale.div( 2 ).add( 0.5 ) ) ).add( params.seed ).toVar( );
|
|
22
|
+
|
|
23
|
+
var midCell = pos.round().toVar();
|
|
24
|
+
|
|
25
|
+
var minCell = midCell.toVar();
|
|
26
|
+
var minDist = float( 1 ).toVar();
|
|
27
|
+
|
|
28
|
+
var cell = vec3().toVar();
|
|
29
|
+
var dist = float().toVar();
|
|
30
|
+
|
|
31
|
+
var i = float( 0 ).toVar();
|
|
32
|
+
|
|
33
|
+
loop( 27, () => {
|
|
34
|
+
|
|
35
|
+
var ix = i.mod( 3 ).sub( 1 );
|
|
36
|
+
var iy = i.div( 3 ).floor().mod( 3 ).sub( 1 );
|
|
37
|
+
var iz = i.div( 9 ).floor().sub( 1 );
|
|
38
|
+
cell.assign( midCell.add( vec3( ix, iy, iz ) ) );
|
|
39
|
+
dist.assign( pos.distance( cellCenter( cell ) ).add( noise( pos ).div( 5 ) ) );
|
|
40
|
+
|
|
41
|
+
If( dist.lessThan( minDist ), ()=>{
|
|
42
|
+
|
|
43
|
+
minDist.assign( dist );
|
|
44
|
+
minCell.assign( cell );
|
|
45
|
+
|
|
46
|
+
} );
|
|
47
|
+
i.addAssign( 1 );
|
|
48
|
+
|
|
49
|
+
} );
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
var n = noise( minCell.mul( Math.PI ) ).toVar();
|
|
53
|
+
var k = mix( minDist, n.add( 1 ).div( 2 ), params.flat );
|
|
54
|
+
|
|
55
|
+
var color = mix( params.color, params.background, k ).toVar();
|
|
56
|
+
var randomColor = vec3( n.mul( 16.8 ), n.mul( 31.4159 ), n.mul( 27.1828 ) ).sin().add( 1 ).div( 2 );
|
|
57
|
+
|
|
58
|
+
return mix( color, mix( color, randomColor, params.variation ), params.variation );
|
|
59
|
+
|
|
60
|
+
} );
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
voronoiCells.defaults = {
|
|
65
|
+
$name: 'Voronoi cells',
|
|
66
|
+
|
|
67
|
+
scale: 2,
|
|
68
|
+
variation: 0,
|
|
69
|
+
flat: 0,
|
|
70
|
+
|
|
71
|
+
color: new Color( 0 ),
|
|
72
|
+
background: new Color( 0xc0d0ff ),
|
|
73
|
+
|
|
74
|
+
seed: 0,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
export { voronoiCells };
|
package/src/wood.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Wood
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from 'three';
|
|
7
|
+
import { add, cos, exp, float, loop, mix, mul, positionLocal, radians, reciprocal, sin, sub, tslFn, vec3 } from 'three/nodes';
|
|
8
|
+
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var wood = tslFn( ( params ) => {
|
|
13
|
+
|
|
14
|
+
var angle = radians( params.angle ).toVar();
|
|
15
|
+
var posLocal = vec3(
|
|
16
|
+
sub( positionLocal.x.mul( cos( angle ) ), positionLocal.y.mul( sin( angle ) ) ),
|
|
17
|
+
add( positionLocal.x.mul( sin( angle ) ), positionLocal.y.mul( cos( angle ) ) ),
|
|
18
|
+
positionLocal.z,
|
|
19
|
+
).toVar();
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// main pattern with rings
|
|
23
|
+
var pos = posLocal.mul( exp( params.scale.sub( 3 ) ).mul( vec3( reciprocal( params.length ), 4, reciprocal( params.length ) ) ) ).add( params.seed ).toVar( );
|
|
24
|
+
var k = noise( pos ).add( 1 ).mul( 10 ).mul( params.rings );
|
|
25
|
+
k = k.add( k.cos() ).cos().add( 1 ).div( 2 );
|
|
26
|
+
|
|
27
|
+
var kk = float( 0 ).toVar(),
|
|
28
|
+
sum = float( 0 ).toVar(),
|
|
29
|
+
scale = exp( params.scale.sub( 2 ) ).mul( vec3( 1, params.fibersDensity, 1 ) ).toVar(),
|
|
30
|
+
power = float( 2 ).toVar();
|
|
31
|
+
|
|
32
|
+
loop( 10, ()=>{
|
|
33
|
+
|
|
34
|
+
kk.addAssign( mul( power, noise( posLocal.mul( scale ).add( params.seed ) ) ) );
|
|
35
|
+
sum.addAssign( power );
|
|
36
|
+
scale.mulAssign( 1.8 );
|
|
37
|
+
power.mulAssign( 0.6 );
|
|
38
|
+
|
|
39
|
+
} );
|
|
40
|
+
|
|
41
|
+
kk.assign( mul( kk, 5 ).div( sum ).mul( 10 ).sin().add( 1 ).div( 2 ) );
|
|
42
|
+
|
|
43
|
+
return mix( params.color, params.background, mix( k, kk, params.fibers ) );
|
|
44
|
+
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
wood.defaults = {
|
|
50
|
+
$name: 'Wood',
|
|
51
|
+
scale: 2.5,
|
|
52
|
+
rings: 4.5,
|
|
53
|
+
length: 1,
|
|
54
|
+
angle: 0,
|
|
55
|
+
fibers: 0.3,
|
|
56
|
+
fibersDensity: 10,
|
|
57
|
+
color: new Color( 0.8, 0.4, 0 ),
|
|
58
|
+
background: new Color( 0.4, 0.1, 0 ),
|
|
59
|
+
seed: 0,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
export { wood };
|
package/src/circles.js.bak
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
// TSL-Textures: Circles
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { Color } from "three";
|
|
7
|
-
import { acos, add, clamp, cond, cos, exp, float, hash, loop, mix, positionLocal, sin, smoothstep, sub, tslFn, vec3 } from 'three/nodes';
|
|
8
|
-
import { hsl, noise, spherical, toHsl } from 'tsl-textures/tsl-utils.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var circles = tslFn( ( params ) => {
|
|
13
|
-
|
|
14
|
-
var pos = positionLocal.normalize().toVar( );
|
|
15
|
-
|
|
16
|
-
var angle = acos( clamp( pos.y, -1, 1 ) ).mul( 20 );
|
|
17
|
-
|
|
18
|
-
var scale = exp( params.scale.sub( 1 ) ).toVar();
|
|
19
|
-
|
|
20
|
-
var x = angle.div( 3000 ).mul( scale );
|
|
21
|
-
|
|
22
|
-
var k = float( params.seed.sin().mul( 100 ) ).toVar();
|
|
23
|
-
for ( var n=0; n<=10; n++ )
|
|
24
|
-
k.addAssign( sin( x.mul( 2**n ).sub( Math.PI*n/2 ) ).mul( -n*( n+1 )/2 ) );
|
|
25
|
-
|
|
26
|
-
k.assign( k.div( 200 ).clamp( -2, 2 ) );
|
|
27
|
-
|
|
28
|
-
var HSL = toHsl( params.color );
|
|
29
|
-
|
|
30
|
-
var hue = HSL.x.add( k.mul( params.variety ) ).mod( 1 ).mul( 10 ).toVar();
|
|
31
|
-
|
|
32
|
-
var huei = hue.floor();
|
|
33
|
-
var huef = hue.sub( huei );
|
|
34
|
-
huef = cond( huef.lessThan( 0.5 ), huef.pow( 1.5 ), huef.pow( 1/1.5 ) );
|
|
35
|
-
hue.assign( huei.add( huef ) );
|
|
36
|
-
|
|
37
|
-
return hsl( hue.div( 10 ), HSL.y, HSL.z );
|
|
38
|
-
|
|
39
|
-
} );
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
circles.defaults = {
|
|
44
|
-
$name: 'Circles',
|
|
45
|
-
|
|
46
|
-
scale: 2,
|
|
47
|
-
variety: 1,
|
|
48
|
-
|
|
49
|
-
color: new Color( 0xF0E0D0 ),
|
|
50
|
-
|
|
51
|
-
seed: 0,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
export { circles };
|