-
Notifications
You must be signed in to change notification settings - Fork 1
/
water-drops.js
74 lines (41 loc) · 1.31 KB
/
water-drops.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Procedural Equirectangular Textures
// Water Drops Pattern
//
// defaults = {...} - default parameters
// pattern( ... ) - calculate color of pixel
// texture( params ) - generate a texture
// material( ... ) - material shader fix
import { Color } from "three";
import { noise, retexture, map, mapExp } from "pet/texture-generator.js";
var defaults = {
$name: 'Water Drops',
width: 512,
height: 256,
scale: 50,
density: 40,
color: 0xFFFFFF,
background: 0x000000,
};
function pattern( x, y, z, color, options, /*u, v, px, py*/ ) {
var k = noise( x, y, z, options.scale ) + options.density;
k = Math.min( 1, k );
k = Math.max( 0, k )**0.5;
k = -( Math.cos( Math.PI*k )-1 )/2;
color.lerpColors( options.background, options.color, k );
}
function options( params ) {
return {
color: new Color( params.color ?? defaults.color ),
background: new Color( params.background ?? defaults.background ),
scale: mapExp( params.scale ?? defaults.scale, 90, 1.5 ),
density: map( params.density??defaults.density, -0.6, 0.6 ),
width: params.width ?? defaults.width,
height: params.height ?? defaults.height,
};
}
function texture( ...opt ) {
return retexture( opt, defaults, options, pattern );
}
export { pattern, defaults, texture };
export { material } from "pet/texture-generator.js";