tsl-textures 0.6.0 → 0.8.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/concrete.js +59 -0
- package/src/concrete.js.bak +59 -0
- package/src/polka-dots.js +62 -0
- package/src/--concrete.js +0 -37
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/concrete.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Concrete
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { abs, cos, cross, exp, normalLocal, positionLocal, pow, remap, sin, sub, tangentLocal, tslFn, vec3 } from 'three/nodes';
|
|
7
|
+
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var surfacePos = tslFn( ([ pos, normal, bump, density, seed ]) => {
|
|
12
|
+
|
|
13
|
+
var k = noise( pos.add( seed ) ).mul( 0.5 ).add( 0.5 );
|
|
14
|
+
k = bump.mul( pow( abs( k ), density ) );
|
|
15
|
+
|
|
16
|
+
return pos.add( k.mul( normal ) );
|
|
17
|
+
|
|
18
|
+
} );
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var concrete = tslFn( ( params ) => {
|
|
22
|
+
|
|
23
|
+
var eps = 0.001;
|
|
24
|
+
|
|
25
|
+
var position = positionLocal.mul( exp( params.scale.div( 2 ).add( 2 ) ) ).toVar( ),
|
|
26
|
+
normal = normalLocal.normalize().toVar(),
|
|
27
|
+
tangent = tangentLocal.normalize().mul( eps ).toVar(),
|
|
28
|
+
bitangent = cross( normal, tangent ).normalize().mul( eps ).toVar();
|
|
29
|
+
|
|
30
|
+
var density = remap( params.density, 0, 1, 10, 0.5 ).toVar();
|
|
31
|
+
var seed = vec3( sin( params.seed ).mul( 100 ), cos( params.seed.div( 2 ) ).mul( 100 ), sin( params.seed.div( 3 ) ).mul( 100 ) ).toVar();
|
|
32
|
+
|
|
33
|
+
var pos = surfacePos( position, normal, params.bump, density, seed );
|
|
34
|
+
var posU = surfacePos( position.add( tangent ), normal, params.bump, density, seed );
|
|
35
|
+
var posV = surfacePos( position.add( bitangent ), normal, params.bump, density, seed );
|
|
36
|
+
|
|
37
|
+
var dU = sub( posU, pos ),
|
|
38
|
+
dV = sub( posV, pos );
|
|
39
|
+
|
|
40
|
+
return cross( dU, dV ).normalize();
|
|
41
|
+
|
|
42
|
+
} );
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
concrete.defaults = {
|
|
47
|
+
$name: 'Concrete',
|
|
48
|
+
$normalNode: true,
|
|
49
|
+
|
|
50
|
+
scale: 2,
|
|
51
|
+
density: 0.5,
|
|
52
|
+
bump: 0.5,
|
|
53
|
+
|
|
54
|
+
seed: 0,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export { concrete };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Concrete
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { abs, cos, cross, exp, mul, normalLocal, positionLocal, pow, remap, sin, sub, tangentLocal, tslFn, vec3 } from 'three/nodes';
|
|
7
|
+
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var surfacePos = tslFn( ([ pos, normal, bump, density, seed ]) => {
|
|
12
|
+
|
|
13
|
+
var k = noise( pos.add( seed ) ).mul( 0.5 ).add( 0.5 );
|
|
14
|
+
k = bump.mul( pow( abs( k ), density ) );
|
|
15
|
+
|
|
16
|
+
return pos.add( k.mul( normal ) );
|
|
17
|
+
|
|
18
|
+
} );
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var concrete = tslFn( ( params ) => {
|
|
22
|
+
|
|
23
|
+
var eps = 0.001;
|
|
24
|
+
|
|
25
|
+
var position = positionLocal.mul( exp( params.scale.div( 2 ).add( 2 ) ) ).toVar( ),
|
|
26
|
+
normal = normalLocal.normalize().toVar(),
|
|
27
|
+
tangent = tangentLocal.normalize().mul( eps ).toVar(),
|
|
28
|
+
bitangent = cross( normal, tangent ).normalize().mul( eps ).toVar();
|
|
29
|
+
|
|
30
|
+
var density = remap( params.density, 0, 1, 10, 0.5 ).toVar();
|
|
31
|
+
var seed = vec3( sin( params.seed ).mul( 100 ), cos( params.seed.div( 2 ) ).mul( 100 ), sin( params.seed.div( 3 ) ).mul( 100 ) ).toVar();
|
|
32
|
+
|
|
33
|
+
var pos = surfacePos( position, normal, params.bump, density, seed );
|
|
34
|
+
var posU = surfacePos( position.add( tangent ), normal, params.bump, density, seed );
|
|
35
|
+
var posV = surfacePos( position.add( bitangent ), normal, params.bump, density, seed );
|
|
36
|
+
|
|
37
|
+
var dU = sub( posU, pos ),
|
|
38
|
+
dV = sub( posV, pos );
|
|
39
|
+
|
|
40
|
+
return cross( dU, dV ).normalize();
|
|
41
|
+
|
|
42
|
+
} );
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
concrete.defaults = {
|
|
47
|
+
$name: 'Concrete',
|
|
48
|
+
$normalNode: true,
|
|
49
|
+
|
|
50
|
+
scale: 2,
|
|
51
|
+
density: 0.5,
|
|
52
|
+
bump: 0.5,
|
|
53
|
+
|
|
54
|
+
seed: 0,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export { concrete };
|
|
@@ -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 };
|
package/src/--concrete.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
// TSL-Textures: Concrete
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//import { Color } from "three";
|
|
7
|
-
import { abs, /*add, div,*/ exp, /*If, MeshLambertNodeMaterial, mix,*/ mul, /*oneMinus,*/ positionLocal, pow, remap, tslFn } from 'three/nodes';
|
|
8
|
-
import { /*hsl,*/ noise } from 'tsl-textures/tsl-utils.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var concrete = tslFn( ( params ) => {
|
|
13
|
-
|
|
14
|
-
var pos = positionLocal.mul( exp( params.scale ) ).add( params.seed ).toVar( );
|
|
15
|
-
|
|
16
|
-
var k = noise( pos );
|
|
17
|
-
|
|
18
|
-
//return hsl( 0, 0, mul(params.bump,pow(abs(k.div(2).add(0.5)),remap(params.density,0,1,10,0.5))) );
|
|
19
|
-
return mul( params.bump, pow( abs( k.div( 2 ).add( 0.5 ) ), remap( params.density, 0, 1, 10, 0.5 ) ) );
|
|
20
|
-
|
|
21
|
-
} );
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
concrete.defaults = {
|
|
26
|
-
$name: 'Concrete',
|
|
27
|
-
|
|
28
|
-
scale: 2,
|
|
29
|
-
density: 1,
|
|
30
|
-
bump: 1,
|
|
31
|
-
|
|
32
|
-
seed: 0,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export { concrete };
|