tsl-textures 0.8.0 → 0.9.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/README.md +9 -0
- package/package.json +1 -1
- package/src/concrete.js +2 -2
- package/src/polka-dots.js +2 -2
- package/src/scepter-head.js +2 -2
- package/src/tsl-utils.js +1 -10
- package/src/{concrete.js.bak → water-drops.js} +16 -15
package/README.md
CHANGED
|
@@ -12,3 +12,12 @@ for both the planet and its moon; and [stars.js](https://boytchev.github.io/tsl-
|
|
|
12
12
|
for the stars. Click on the image for a live demo.
|
|
13
13
|
|
|
14
14
|
[<img src="https://boytchev.github.io/tsl-textures/examples/example-planet.jpg">](https://boytchev.github.io/tsl-textures/examples/example-planet.html)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
#### Example "Normal map"
|
|
18
|
+
|
|
19
|
+
Uses tsl-utils.js to generate two normal maps and the transition between them.
|
|
20
|
+
The normal are created directly without using any of the TSL texture generators.
|
|
21
|
+
Click on the image for a live demo.
|
|
22
|
+
|
|
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)
|
package/package.json
CHANGED
package/src/concrete.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import { abs, cos, cross, exp, normalLocal, positionLocal, pow, remap, sin, sub, tangentLocal, tslFn, vec3 } from 'three/nodes';
|
|
6
|
+
import { abs, cos, cross, exp, modelNormalMatrix, normalLocal, positionLocal, pow, remap, sin, sub, tangentLocal, tslFn, vec3 } from 'three/nodes';
|
|
7
7
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
8
8
|
|
|
9
9
|
|
|
@@ -37,7 +37,7 @@ var concrete = tslFn( ( params ) => {
|
|
|
37
37
|
var dU = sub( posU, pos ),
|
|
38
38
|
dV = sub( posV, pos );
|
|
39
39
|
|
|
40
|
-
return cross( dU, dV ).normalize();
|
|
40
|
+
return modelNormalMatrix.mul( cross( dU, dV ).normalize() );
|
|
41
41
|
|
|
42
42
|
} );
|
|
43
43
|
|
package/src/polka-dots.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
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 {
|
|
7
|
+
import { acos, add, distance, exp, float, loop, max, min, mix, mod, mul, oneMinus, positionLocal, pow, smoothstep, tslFn, } from 'three/nodes';
|
|
8
|
+
import { spherical } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
package/src/scepter-head.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { Color } from "three";
|
|
7
|
-
import { abs, add, cos, floor, max, mix, mul, positionLocal, remapClamp, sign, tan, tslFn, vec3 } from 'three/nodes';
|
|
8
|
-
import { hsl,
|
|
7
|
+
import { abs, add, cos, floor, max, mix, mod, mul, positionLocal, remapClamp, sign, tan, tslFn, vec3 } from 'three/nodes';
|
|
8
|
+
import { hsl, noise, remapExp, toHsl } from 'tsl-textures/tsl-utils.js';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
package/src/tsl-utils.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
import { add, cond, cos, cross,
|
|
11
|
+
import { add, cond, cos, cross, float, If, log2, max, min, mul, pow, remap, sin, sub, tslFn, uniform, vec3, vec4 } from 'three/nodes';
|
|
12
12
|
import { mx_perlin_noise_float as noise } from 'three/addons/nodes/materialx/lib/mx_noise.js';
|
|
13
13
|
|
|
14
14
|
|
|
@@ -187,14 +187,6 @@ const applyQuaternion = tslFn( ([ vec, quat ]) => {
|
|
|
187
187
|
} );
|
|
188
188
|
|
|
189
189
|
|
|
190
|
-
// calculate modulo (missing in TSL?)
|
|
191
|
-
const mod = tslFn( ([ x, y ]) => {
|
|
192
|
-
|
|
193
|
-
return sub( x, floor( div( x, y ) ).mul( y ) );
|
|
194
|
-
|
|
195
|
-
} );
|
|
196
|
-
|
|
197
|
-
|
|
198
190
|
|
|
199
191
|
// exponential version of remap
|
|
200
192
|
const remapExp = tslFn( ([ x, fromMin, fromMax, toMin, toMax ]) => {
|
|
@@ -227,6 +219,5 @@ export
|
|
|
227
219
|
dynamic,
|
|
228
220
|
spherical,
|
|
229
221
|
applyEuler,
|
|
230
|
-
mod,
|
|
231
222
|
remapExp
|
|
232
223
|
};
|
|
@@ -1,59 +1,60 @@
|
|
|
1
1
|
|
|
2
|
-
// TSL-Textures:
|
|
2
|
+
// TSL-Textures: Water Drops
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { cos, cross, exp, modelNormalMatrix, normalLocal, positionLocal, remap, sin, sub, tangentLocal, tslFn, vec3 } from 'three/nodes';
|
|
7
7
|
import { noise } from 'tsl-textures/tsl-utils.js';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
var surfacePos = tslFn( ([ pos, normal, bump, density, seed ]) => {
|
|
12
12
|
|
|
13
|
-
var k = noise( pos.add( seed ) ).
|
|
14
|
-
k =
|
|
13
|
+
var k = noise( pos.add( seed ) ).add( density ).clamp( 0, 1 );
|
|
14
|
+
k = cos( k.mul( Math.PI ) ).add( 1 ).pow( 0.5 ).toVar();
|
|
15
|
+
|
|
16
|
+
return pos.add( k.mul( normal, bump ) );
|
|
15
17
|
|
|
16
|
-
return pos.add( k.mul( normal ) );
|
|
17
|
-
|
|
18
18
|
} );
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var waterDrops = tslFn( ( params ) => {
|
|
22
22
|
|
|
23
23
|
var eps = 0.001;
|
|
24
24
|
|
|
25
|
-
var position = positionLocal.mul( exp( params.scale.div(
|
|
25
|
+
var position = positionLocal.mul( exp( params.scale.div( 1 ).add( 1 ) ) ).toVar( ),
|
|
26
26
|
normal = normalLocal.normalize().toVar(),
|
|
27
27
|
tangent = tangentLocal.normalize().mul( eps ).toVar(),
|
|
28
28
|
bitangent = cross( normal, tangent ).normalize().mul( eps ).toVar();
|
|
29
29
|
|
|
30
|
-
var density = remap( params.density, 0, 1,
|
|
30
|
+
var density = remap( params.density, 0, 1, 1.5, 0.7 ).toVar();
|
|
31
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
32
|
|
|
33
33
|
var pos = surfacePos( position, normal, params.bump, density, seed );
|
|
34
|
+
|
|
34
35
|
var posU = surfacePos( position.add( tangent ), normal, params.bump, density, seed );
|
|
35
36
|
var posV = surfacePos( position.add( bitangent ), normal, params.bump, density, seed );
|
|
36
37
|
|
|
37
38
|
var dU = sub( posU, pos ),
|
|
38
39
|
dV = sub( posV, pos );
|
|
39
40
|
|
|
40
|
-
return cross( dU, dV ).normalize();
|
|
41
|
+
return modelNormalMatrix.mul( cross( dU, dV ).normalize() );
|
|
41
42
|
|
|
42
43
|
} );
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
$name: '
|
|
47
|
+
waterDrops.defaults = {
|
|
48
|
+
$name: 'Water Drops',
|
|
48
49
|
$normalNode: true,
|
|
49
50
|
|
|
50
|
-
scale:
|
|
51
|
+
scale: 1.4,
|
|
51
52
|
density: 0.5,
|
|
52
|
-
bump: 0.
|
|
53
|
+
bump: 0.6,
|
|
53
54
|
|
|
54
55
|
seed: 0,
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
|
|
58
59
|
|
|
59
|
-
export {
|
|
60
|
+
export { waterDrops };
|