@dailies-studio/tsl-textures 3.0.4
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/LICENSE +21 -0
- package/README.md +142 -0
- package/dist/cjs/tsl-textures.cjs +4749 -0
- package/dist/cjs/tsl-textures.min.cjs +2 -0
- package/dist/tsl-textures.js +4659 -0
- package/dist/tsl-textures.min.js +2 -0
- package/package.json +36 -0
- package/src/brain.js +116 -0
- package/src/bricks.js +116 -0
- package/src/camouflage.js +85 -0
- package/src/caustics.js +75 -0
- package/src/cave-art.js +83 -0
- package/src/circle-decor.js +76 -0
- package/src/circles.js +83 -0
- package/src/clouds.js +114 -0
- package/src/concrete.js +95 -0
- package/src/cork.js +104 -0
- package/src/crumpled-fabric.js +81 -0
- package/src/dalmatian-spots.js +80 -0
- package/src/darth-maul.js +84 -0
- package/src/dyson-sphere.js +144 -0
- package/src/entangled.js +75 -0
- package/src/fordite.js +69 -0
- package/src/gas-giant.js +94 -0
- package/src/grid.js +84 -0
- package/src/halftone.js +252 -0
- package/src/isolayers.js +79 -0
- package/src/isolines.js +72 -0
- package/src/karst-rock.js +67 -0
- package/src/marble.js +96 -0
- package/src/melter.js +76 -0
- package/src/neon-lights.js +107 -0
- package/src/perlin-noise.js +66 -0
- package/src/photosphere.js +73 -0
- package/src/planet.js +168 -0
- package/src/polka-dots.js +106 -0
- package/src/processed-wood.js +80 -0
- package/src/protozoa.js +110 -0
- package/src/reticular-veins.js +72 -0
- package/src/roman-paving.js +58 -0
- package/src/rotator.js +120 -0
- package/src/rough-clay.js +90 -0
- package/src/runny-eggs.js +180 -0
- package/src/rust.js +144 -0
- package/src/satin.js +69 -0
- package/src/scaler.js +111 -0
- package/src/scepter-head.js +94 -0
- package/src/scream.js +72 -0
- package/src/stars.js +72 -0
- package/src/static-noise.js +73 -0
- package/src/supersphere.js +108 -0
- package/src/tiger-fur.js +77 -0
- package/src/translator.js +116 -0
- package/src/tsl-textures.js +63 -0
- package/src/tsl-utils.js +344 -0
- package/src/turbulent-smoke.js +73 -0
- package/src/voronoi-cells.js +99 -0
- package/src/water-drops.js +96 -0
- package/src/watermelon.js +87 -0
- package/src/waves.js +150 -0
- package/src/wood.js +99 -0
- package/src/zebra-lines.js +77 -0
package/src/halftone.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Halftone
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Discard, float, Fn, If, min, positionView, screenCoordinate, Switch, vec2, vec3, vertexColor } from 'three/tsl';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var defaults = {
|
|
11
|
+
$name: 'Halftone',
|
|
12
|
+
|
|
13
|
+
position: screenCoordinate,
|
|
14
|
+
scale: 2,
|
|
15
|
+
radius: 0.5,
|
|
16
|
+
pattern: 1,
|
|
17
|
+
|
|
18
|
+
attenuation: 0,
|
|
19
|
+
near: 6,
|
|
20
|
+
far: 14,
|
|
21
|
+
|
|
22
|
+
color: vertexColor(),
|
|
23
|
+
|
|
24
|
+
positionView: positionView,
|
|
25
|
+
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// square grid of circles
|
|
31
|
+
var halftoneGridRaw = Fn( ([ position, scale, radius, attenuation, far, near, color, positionView ]) => {
|
|
32
|
+
|
|
33
|
+
var xscale = float( 5 ).sub( scale ).exp().toVar(),
|
|
34
|
+
pos = position.toVar(),
|
|
35
|
+
xradius = radius.div( Math.sqrt( 2 ) ).toVar();
|
|
36
|
+
|
|
37
|
+
var center = pos.div( xscale ).round().mul( xscale );
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
If( attenuation.notEqual( 0 ), ()=>{
|
|
41
|
+
|
|
42
|
+
xradius.mulAssign( positionView.z.mul( -1 ).smoothstep( far, near ).pow( 1/2 ) );
|
|
43
|
+
|
|
44
|
+
} );
|
|
45
|
+
|
|
46
|
+
If( pos.distance( center ).greaterThan( xscale.mul( xradius ) ), ()=>Discard() );
|
|
47
|
+
|
|
48
|
+
return color;
|
|
49
|
+
|
|
50
|
+
} ).setLayout( {
|
|
51
|
+
name: 'halftoneGridRaw',
|
|
52
|
+
type: 'vec3',
|
|
53
|
+
inputs: [
|
|
54
|
+
{ name: 'position', type: 'vec3' },
|
|
55
|
+
{ name: 'scale', type: 'float' },
|
|
56
|
+
{ name: 'radius', type: 'float' },
|
|
57
|
+
{ name: 'attenuation', type: 'int' },
|
|
58
|
+
{ name: 'far', type: 'float' },
|
|
59
|
+
{ name: 'near', type: 'float' },
|
|
60
|
+
{ name: 'color', type: 'vec3' },
|
|
61
|
+
{ name: 'positionView', type: 'vec3' },
|
|
62
|
+
] }
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// diagonal geid of circles
|
|
68
|
+
var halftoneDiagRaw = Fn( ([ position, scale, radius, attenuation, far, near, color, positionView ]) => {
|
|
69
|
+
|
|
70
|
+
var xscale = float( 5 ).sub( scale ).exp().toVar(),
|
|
71
|
+
pos = position.toVar(),
|
|
72
|
+
xradius = radius.div( Math.sqrt( 2 ) ).toVar();
|
|
73
|
+
|
|
74
|
+
var shift = pos.y.div( xscale ).round().mod( 2 );
|
|
75
|
+
|
|
76
|
+
var centerA = pos.div( xscale ).round().mulAssign( xscale ).toVar();
|
|
77
|
+
|
|
78
|
+
If( shift.equal( 0 ), ()=>{
|
|
79
|
+
|
|
80
|
+
centerA.x.addAssign( xscale.mul( 0.5 ) );
|
|
81
|
+
|
|
82
|
+
} );
|
|
83
|
+
var centerB = vec2( centerA.x.sub( xscale ), centerA.y ).toVar();
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
If( attenuation.notEqual( 0 ), ()=>{
|
|
87
|
+
|
|
88
|
+
xradius.mulAssign( positionView.z.mul( -1 ).smoothstep( far, near ).pow( 1/2 ) );
|
|
89
|
+
|
|
90
|
+
} );
|
|
91
|
+
|
|
92
|
+
If( min( pos.distance( centerA ), pos.distance( centerB ) ).greaterThan( xscale.mul( xradius ) ), ()=>Discard() );
|
|
93
|
+
|
|
94
|
+
return color;
|
|
95
|
+
|
|
96
|
+
} ).setLayout( {
|
|
97
|
+
name: 'halftoneDiagRaw',
|
|
98
|
+
type: 'vec3',
|
|
99
|
+
inputs: [
|
|
100
|
+
{ name: 'position', type: 'vec3' },
|
|
101
|
+
{ name: 'scale', type: 'float' },
|
|
102
|
+
{ name: 'radius', type: 'float' },
|
|
103
|
+
{ name: 'attenuation', type: 'int' },
|
|
104
|
+
{ name: 'far', type: 'float' },
|
|
105
|
+
{ name: 'near', type: 'float' },
|
|
106
|
+
{ name: 'color', type: 'vec3' },
|
|
107
|
+
{ name: 'positionView', type: 'vec3' },
|
|
108
|
+
] }
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
// trigonetric pattern
|
|
114
|
+
var halftoneTrigRaw = Fn( ([ position, scale, radius, pattern, attenuation, far, near, color, positionView ]) => {
|
|
115
|
+
|
|
116
|
+
var pos = position.mul( scale.sub( 3.5 ).exp() ).sin().add( 1 ).div( 2 ).toVar(),
|
|
117
|
+
x = pos.x,
|
|
118
|
+
y = pos.y,
|
|
119
|
+
xradius = radius.div( Math.sqrt( 2 ) ).toVar();
|
|
120
|
+
|
|
121
|
+
var dist = float( 0 );
|
|
122
|
+
|
|
123
|
+
Switch( pattern )
|
|
124
|
+
.Case( 2, ()=>{
|
|
125
|
+
|
|
126
|
+
dist.assign( x.add( y ).div( 2 ) );
|
|
127
|
+
|
|
128
|
+
} )
|
|
129
|
+
.Case( 3, ()=>{
|
|
130
|
+
|
|
131
|
+
dist.assign( x.sub( y ).abs().oneMinus() );
|
|
132
|
+
|
|
133
|
+
} )
|
|
134
|
+
.Case( 10, ()=>{
|
|
135
|
+
|
|
136
|
+
dist.assign( x.sub( y ).abs() );
|
|
137
|
+
|
|
138
|
+
} )
|
|
139
|
+
.Case( 4, ()=>{
|
|
140
|
+
|
|
141
|
+
dist.assign( x.mul( y ).oneMinus() );
|
|
142
|
+
|
|
143
|
+
} )
|
|
144
|
+
.Case( 9, ()=>{
|
|
145
|
+
|
|
146
|
+
dist.assign( x.mul( y ) );
|
|
147
|
+
|
|
148
|
+
} )
|
|
149
|
+
.Case( 5, ()=>{
|
|
150
|
+
|
|
151
|
+
dist.assign( x.max( y ) );
|
|
152
|
+
|
|
153
|
+
} )
|
|
154
|
+
.Case( 6, ()=>{
|
|
155
|
+
|
|
156
|
+
dist.assign( x.min( y ) );
|
|
157
|
+
|
|
158
|
+
} )
|
|
159
|
+
.Case( 7, ()=>{
|
|
160
|
+
|
|
161
|
+
dist.assign( x );
|
|
162
|
+
|
|
163
|
+
} )
|
|
164
|
+
.Case( 8, ()=>{
|
|
165
|
+
|
|
166
|
+
dist.assign( y );
|
|
167
|
+
|
|
168
|
+
} );
|
|
169
|
+
|
|
170
|
+
If( attenuation.notEqual( 0 ), ()=>{
|
|
171
|
+
|
|
172
|
+
xradius.mulAssign( positionView.z.mul( -1 ).smoothstep( far, near ).pow( 1/2 ) );
|
|
173
|
+
|
|
174
|
+
} );
|
|
175
|
+
|
|
176
|
+
If( dist.greaterThan( xradius ), ()=>Discard() );
|
|
177
|
+
|
|
178
|
+
return color;
|
|
179
|
+
|
|
180
|
+
} ).setLayout( {
|
|
181
|
+
name: 'halftoneTrigRaw',
|
|
182
|
+
type: 'vec3',
|
|
183
|
+
inputs: [
|
|
184
|
+
{ name: 'position', type: 'vec3' },
|
|
185
|
+
{ name: 'scale', type: 'float' },
|
|
186
|
+
{ name: 'radius', type: 'float' },
|
|
187
|
+
{ name: 'pattern', type: 'int' },
|
|
188
|
+
{ name: 'attenuation', type: 'int' },
|
|
189
|
+
{ name: 'far', type: 'float' },
|
|
190
|
+
{ name: 'near', type: 'float' },
|
|
191
|
+
{ name: 'color', type: 'vec3' },
|
|
192
|
+
{ name: 'positionView', type: 'vec3' },
|
|
193
|
+
] }
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
var halftoneRaw = Fn( ([ position, scale, radius, pattern, attenuation, far, near, color, positionView ]) => {
|
|
199
|
+
|
|
200
|
+
var result = vec3( 0 ).toVar();
|
|
201
|
+
|
|
202
|
+
Switch( pattern )
|
|
203
|
+
.Case( 0, ()=>{
|
|
204
|
+
|
|
205
|
+
result.assign( halftoneGridRaw( position, scale, radius, attenuation, far, near, color, positionView ) );
|
|
206
|
+
|
|
207
|
+
} )
|
|
208
|
+
.Case( 1, ()=>{
|
|
209
|
+
|
|
210
|
+
result.assign( halftoneDiagRaw( position, scale, radius, attenuation, far, near, color, positionView ) );
|
|
211
|
+
|
|
212
|
+
} )
|
|
213
|
+
.Default( ()=>{
|
|
214
|
+
|
|
215
|
+
result.assign( halftoneTrigRaw( position, scale, radius, pattern, attenuation, far, near, color, positionView ) );
|
|
216
|
+
|
|
217
|
+
} );
|
|
218
|
+
|
|
219
|
+
return result;
|
|
220
|
+
|
|
221
|
+
} ).setLayout( {
|
|
222
|
+
name: 'halftoneRaw',
|
|
223
|
+
type: 'vec3',
|
|
224
|
+
inputs: [
|
|
225
|
+
{ name: 'position', type: 'vec3' },
|
|
226
|
+
{ name: 'scale', type: 'float' },
|
|
227
|
+
{ name: 'radius', type: 'float' },
|
|
228
|
+
{ name: 'pattern', type: 'int' },
|
|
229
|
+
{ name: 'attenuation', type: 'int' },
|
|
230
|
+
{ name: 'far', type: 'float' },
|
|
231
|
+
{ name: 'near', type: 'float' },
|
|
232
|
+
{ name: 'color', type: 'vec3' },
|
|
233
|
+
{ name: 'positionView', type: 'vec3' },
|
|
234
|
+
] }
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
function halftone( params={} ) {
|
|
239
|
+
|
|
240
|
+
var { position, scale, radius, pattern, attenuation, far, near, color, positionView } = { ...defaults, ...params };
|
|
241
|
+
|
|
242
|
+
return halftoneRaw( position, scale, radius, pattern, attenuation, far, near, color, positionView );
|
|
243
|
+
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
halftone.defaults = defaults;
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
export { halftone };
|
package/src/isolayers.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Isolayers
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from 'three';
|
|
7
|
+
import { exp, float, Fn, mix, positionGeometry } from 'three/tsl';
|
|
8
|
+
import { hsl, noise, toHsl } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var defaults = {
|
|
13
|
+
$name: 'Isolayers',
|
|
14
|
+
|
|
15
|
+
position: positionGeometry,
|
|
16
|
+
scale: 2,
|
|
17
|
+
layers: 10,
|
|
18
|
+
edge: 0.5,
|
|
19
|
+
darkness: 0,
|
|
20
|
+
|
|
21
|
+
color: new Color( 0xFFFFF0 ),
|
|
22
|
+
background: new Color( 0xFF4040 ),
|
|
23
|
+
|
|
24
|
+
seed: 0,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
var isolayersRaw = Fn( ([ position, scale, layers, edge, darkness, color, background, seed ])=>{
|
|
30
|
+
|
|
31
|
+
var pos = position.mul( exp( scale.sub( 1 ) ) ).add( seed ).toVar( );
|
|
32
|
+
|
|
33
|
+
var depth = edge.remap( 0, 1, 40, 10 );
|
|
34
|
+
|
|
35
|
+
var k = noise( pos, 1.2, 1 ).div( 2 );
|
|
36
|
+
|
|
37
|
+
var i = k.mul( layers ).round().div( layers ).clamp( 0, 1 );
|
|
38
|
+
var f = k.sub( float( 0.5+0.03 ).div( layers ) )
|
|
39
|
+
.mul( layers ).fract()
|
|
40
|
+
.mul( float( 2 ).pow( depth.reciprocal() ) )
|
|
41
|
+
.pow( depth ).sub( 1 ).abs().oneMinus();
|
|
42
|
+
|
|
43
|
+
var hslColor = mix( toHsl( background ), toHsl( color ), i ).toVar();
|
|
44
|
+
hslColor.z.mulAssign( mix( 1, i.mul( 1.5 ), darkness ).clamp( 0, 1 ) );
|
|
45
|
+
|
|
46
|
+
return hsl( hslColor ).sub( f );
|
|
47
|
+
|
|
48
|
+
} ).setLayout( {
|
|
49
|
+
name: 'isolayersRaw',
|
|
50
|
+
type: 'vec3',
|
|
51
|
+
inputs: [
|
|
52
|
+
{ name: 'position', type: 'vec3' },
|
|
53
|
+
{ name: 'scale', type: 'float' },
|
|
54
|
+
{ name: 'layers', type: 'int' },
|
|
55
|
+
{ name: 'edge', type: 'float' },
|
|
56
|
+
{ name: 'darkness', type: 'float' },
|
|
57
|
+
{ name: 'color', type: 'vec3' },
|
|
58
|
+
{ name: 'background', type: 'vec3' },
|
|
59
|
+
{ name: 'seed', type: 'float' },
|
|
60
|
+
] }
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
function isolayers( params={} ) {
|
|
66
|
+
|
|
67
|
+
var { position, scale, layers, edge, darkness, color, background, seed } = { ...defaults, ...params };
|
|
68
|
+
|
|
69
|
+
return isolayersRaw( position, scale, layers, edge, darkness, color, background, seed );
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
isolayers.defaults = defaults;
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
export { isolayers };
|
package/src/isolines.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Isolines
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from "three";
|
|
7
|
+
import { add, exp, Fn, mix, oneMinus, positionGeometry, sin, smoothstep, sub } from 'three/tsl';
|
|
8
|
+
import { noise } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var defaults = {
|
|
13
|
+
$name: 'Isolines',
|
|
14
|
+
|
|
15
|
+
position: positionGeometry,
|
|
16
|
+
scale: 2,
|
|
17
|
+
density: 40,
|
|
18
|
+
blur: 0.3,
|
|
19
|
+
thinness: 0.6,
|
|
20
|
+
|
|
21
|
+
color: new Color( 0xFFFFFF ),
|
|
22
|
+
background: new Color( 0x000000 ),
|
|
23
|
+
|
|
24
|
+
seed: 0,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
var isolinesRaw = Fn( ([ position, scale, density, blur, thinness, color, background, seed ])=>{
|
|
30
|
+
|
|
31
|
+
var pos = position.mul( exp( scale ) ).add( seed ).toVar( );
|
|
32
|
+
|
|
33
|
+
var k = noise( pos, density );
|
|
34
|
+
|
|
35
|
+
k = oneMinus( sin( k ) ).div( 2 );
|
|
36
|
+
|
|
37
|
+
k = smoothstep( sub( thinness, blur ), add( thinness, blur ), k );
|
|
38
|
+
|
|
39
|
+
return mix( color, background, k );
|
|
40
|
+
|
|
41
|
+
} ).setLayout( {
|
|
42
|
+
name: 'isolinesRaw',
|
|
43
|
+
type: 'vec3',
|
|
44
|
+
inputs: [
|
|
45
|
+
{ name: 'position', type: 'vec3' },
|
|
46
|
+
{ name: 'scale', type: 'float' },
|
|
47
|
+
{ name: 'density', type: 'float' },
|
|
48
|
+
{ name: 'blur', type: 'float' },
|
|
49
|
+
{ name: 'thinness', type: 'float' },
|
|
50
|
+
{ name: 'color', type: 'vec3' },
|
|
51
|
+
{ name: 'background', type: 'vec3' },
|
|
52
|
+
{ name: 'seed', type: 'float' },
|
|
53
|
+
] }
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
function isolines( params={} ) {
|
|
59
|
+
|
|
60
|
+
var { position, scale, density, blur, thinness, color, background, seed } = { ...defaults, ...params };
|
|
61
|
+
|
|
62
|
+
return isolinesRaw( position, scale, density, blur, thinness, color, background, seed );
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
isolines.defaults = defaults;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
export { isolines };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Karst rock
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from "three";
|
|
7
|
+
import { exp, Fn, mix, positionGeometry } from 'three/tsl';
|
|
8
|
+
import { noise } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var defaults = {
|
|
13
|
+
$name: 'Karst rock',
|
|
14
|
+
|
|
15
|
+
position: positionGeometry,
|
|
16
|
+
scale: 2,
|
|
17
|
+
|
|
18
|
+
color: new Color( 0xFFF4F0 ),
|
|
19
|
+
background: new Color( 0xD0D0D0 ),
|
|
20
|
+
|
|
21
|
+
seed: 0,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var karstRockRaw = Fn( ([ position, scale, color, background, seed ])=>{
|
|
27
|
+
|
|
28
|
+
var pos = position.mul( exp( scale ) ).add( seed.sin().mul( 5 ) ).toVar( );
|
|
29
|
+
|
|
30
|
+
var pos2 = pos.add( noise( pos.mul( 2 ) ) ).toVar();
|
|
31
|
+
|
|
32
|
+
var k = noise( pos2 ).div( noise( pos2.mul( 1.01 ) ) ).clamp( 0, 2 ).toVar();
|
|
33
|
+
|
|
34
|
+
k.addAssign( noise( pos.mul( 100 ) ).div( 3 ) );
|
|
35
|
+
k.addAssign( noise( pos.mul( 2 ) ).div( 2 ) );
|
|
36
|
+
|
|
37
|
+
return mix( background, color, k ).mul( k.pow( 0.1 ) );
|
|
38
|
+
|
|
39
|
+
} ).setLayout( {
|
|
40
|
+
name: 'karstRockRaw',
|
|
41
|
+
type: 'vec3',
|
|
42
|
+
inputs: [
|
|
43
|
+
{ name: 'position', type: 'vec3' },
|
|
44
|
+
{ name: 'scale', type: 'float' },
|
|
45
|
+
{ name: 'color', type: 'vec3' },
|
|
46
|
+
{ name: 'background', type: 'vec3' },
|
|
47
|
+
{ name: 'seed', type: 'float' },
|
|
48
|
+
] }
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
function karstRock( params={} ) {
|
|
54
|
+
|
|
55
|
+
var { position, scale, color, background, seed } = { ...defaults, ...params };
|
|
56
|
+
|
|
57
|
+
return karstRockRaw( position, scale, color, background, seed );
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
karstRock.defaults = defaults;
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
export { karstRock };
|
package/src/marble.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Marble
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Color } from "three";
|
|
7
|
+
import { add, div, exp, Fn, If, mix, mul, oneMinus, positionGeometry, pow } from 'three/tsl';
|
|
8
|
+
import { noise } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var defaults = {
|
|
13
|
+
$name: 'Marble',
|
|
14
|
+
|
|
15
|
+
position: positionGeometry,
|
|
16
|
+
scale: 1.2,
|
|
17
|
+
thinness: 5,
|
|
18
|
+
noise: 0.3,
|
|
19
|
+
|
|
20
|
+
color: new Color( 0x4545D3 ),
|
|
21
|
+
background: new Color( 0xF0F8FF ),
|
|
22
|
+
|
|
23
|
+
seed: 0,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var marbleRaw = Fn( ([ position, scale, thinness, xnoise, color, background, seed ]) => {
|
|
29
|
+
|
|
30
|
+
var pos = position.mul( exp( scale ) ).add( seed ).toVar( );
|
|
31
|
+
|
|
32
|
+
var k = add(
|
|
33
|
+
noise( pos ),
|
|
34
|
+
noise( pos.mul( 2 ) ).mul( 0.5 ),
|
|
35
|
+
noise( pos.mul( 6 ) ).mul( 0.1 )
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
var k = oneMinus( k.abs().pow( 2.5 ) ).toVar();
|
|
39
|
+
|
|
40
|
+
var maxSmooth = oneMinus( pow( 0.5, thinness.add( 7 ) ) ).toVar(),
|
|
41
|
+
minSmooth = oneMinus( pow( 0.5, thinness.add( 7 ).mul( 0.5 ) ) ).toVar();
|
|
42
|
+
|
|
43
|
+
If( k.greaterThan( maxSmooth ), ()=>{
|
|
44
|
+
|
|
45
|
+
k.assign( 1 );
|
|
46
|
+
|
|
47
|
+
} )
|
|
48
|
+
.ElseIf( k.lessThan( minSmooth ), ()=>{
|
|
49
|
+
|
|
50
|
+
k.assign( 0 );
|
|
51
|
+
|
|
52
|
+
} )
|
|
53
|
+
.Else( ()=> {
|
|
54
|
+
|
|
55
|
+
var a = k.sub( minSmooth );
|
|
56
|
+
var b = maxSmooth.sub( minSmooth );
|
|
57
|
+
k.assign( pow( div( a, b ), 5 ).mul( 0.75 ) );
|
|
58
|
+
k.assign( k.mul( add( 0.5, noise( pos.mul( 2 ) ).mul( 1.5 ) ) ) );
|
|
59
|
+
|
|
60
|
+
} );
|
|
61
|
+
|
|
62
|
+
k.assign( k.add( mul( xnoise, noise( pos.mul( 150 ) ).abs().pow3() ) ) );
|
|
63
|
+
|
|
64
|
+
return mix( background, color, k );
|
|
65
|
+
|
|
66
|
+
} ).setLayout( {
|
|
67
|
+
name: 'marbleRaw',
|
|
68
|
+
type: 'vec3',
|
|
69
|
+
inputs: [
|
|
70
|
+
{ name: 'position', type: 'vec3' },
|
|
71
|
+
{ name: 'scale', type: 'float' },
|
|
72
|
+
{ name: 'thinness', type: 'float' },
|
|
73
|
+
{ name: 'xnoise', type: 'float' },
|
|
74
|
+
{ name: 'color', type: 'vec3' },
|
|
75
|
+
{ name: 'background', type: 'vec3' },
|
|
76
|
+
{ name: 'seed', type: 'float' },
|
|
77
|
+
] }
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
function marble( params={} ) {
|
|
83
|
+
|
|
84
|
+
var { position, scale, thinness, noise, color, background, seed } = { ...defaults, ...params };
|
|
85
|
+
|
|
86
|
+
return marbleRaw( position, scale, thinness, noise, color, background, seed );
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
marble.defaults = defaults;
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
export { marble };
|
package/src/melter.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
// TSL-Textures: Melter
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { Vector2, Vector3 } from "three";
|
|
7
|
+
import { cross, float, Fn, normalLocal, positionGeometry, sub, tangentLocal, transformNormalToView, vec4 } from 'three/tsl';
|
|
8
|
+
import { matTrans, noise, prepare } from './tsl-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var surfacePos = Fn( ([ pos, params ])=>{
|
|
13
|
+
|
|
14
|
+
var zone = float( 1 ).toVar();
|
|
15
|
+
var n = noise( pos.mul( 2 ) ).add( 1 ).div( 2 ); // noise factor
|
|
16
|
+
var k = params.distance.normalize().dot( normalLocal.normalize() ).max( 0 ).pow( 10 );
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
var T = matTrans( params.distance.mul( zone ).mul( n ).mul( k ).pow( 0.1 ) );
|
|
20
|
+
|
|
21
|
+
return T.mul( vec4( pos, 1 ) ).xyz;
|
|
22
|
+
|
|
23
|
+
} );
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
var melter = Fn( ( params )=>{
|
|
28
|
+
|
|
29
|
+
params = prepare( { ...melter.defaults, ...params } );
|
|
30
|
+
|
|
31
|
+
return surfacePos( positionGeometry, params );
|
|
32
|
+
|
|
33
|
+
} );
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
melter.normal = Fn( ( params ) => {
|
|
38
|
+
|
|
39
|
+
params = prepare( { ...melter.defaults, ...params } );
|
|
40
|
+
|
|
41
|
+
var eps = 0.01;
|
|
42
|
+
|
|
43
|
+
var position = positionGeometry,
|
|
44
|
+
normal = normalLocal.normalize().toVar(),
|
|
45
|
+
tangent = tangentLocal.normalize().mul( eps ).toVar(),
|
|
46
|
+
bitangent = cross( normal, tangent ).normalize().mul( eps ).toVar();
|
|
47
|
+
|
|
48
|
+
var pos = surfacePos( position, params );
|
|
49
|
+
var posU = surfacePos( position.add( tangent ), params );
|
|
50
|
+
var posV = surfacePos( position.add( bitangent ), params );
|
|
51
|
+
|
|
52
|
+
var dU = sub( posU, pos ),
|
|
53
|
+
dV = sub( posV, pos );
|
|
54
|
+
|
|
55
|
+
return transformNormalToView( cross( dU, dV ).normalize() );
|
|
56
|
+
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
melter.defaults = {
|
|
62
|
+
$name: 'Melter',
|
|
63
|
+
$positionNode: true,
|
|
64
|
+
$selectorPlanar: true,
|
|
65
|
+
|
|
66
|
+
distance: new Vector3( 0, -0.5, 0 ),
|
|
67
|
+
|
|
68
|
+
selectorCenter: new Vector3( 0, 0, 0 ),
|
|
69
|
+
selectorAngles: new Vector2( 0, 0 ),
|
|
70
|
+
selectorWidth: 1.7,
|
|
71
|
+
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
export { melter };
|