-
Notifications
You must be signed in to change notification settings - Fork 43
/
HagelslagNoise.osl
93 lines (80 loc) · 2.23 KB
/
HagelslagNoise.osl
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Hagelslag.osl by Michel J. Anders (c)2012
* from https://github.com/sambler/osl-shaders
*
* license: cc-by-sa
*
* original script from -
* http://blenderthings.blogspot.com.au/2012/12/a-hagelslag-sprinkles-osl-shader-for.html
*
*
* In blender's homeland hagelslag is the name used for sprinkles.
* Enjoy sprinkling blender's hagelslag on all your materials
* to make them as delicious as can be ;)
* Modified 1/4/2020 by Saul Espinosa for Redshift 3D
*/
// replacement for the missing distance(a, b, q) function
float minimum_distance(point v, point w, point p) {
vector s = w - v;
float l2 = dot(s,s);
if (l2 == 0.0) return distance(p, v);
float t = dot(p - v, s) / l2;
if (t < 0.0) return distance(p, v);
else if (t > 1.0) return distance(p, w);
vector projection = v + t * (s);
return distance(p, projection);
}
shader MAHagelslag
[[ string help = "Hagelslag Noise Pattern",
string label = "Hagelslag Noise" ]]
(
vector Vector = P,
float Scale = 1.0
[[
float min = 0, float max = 25
]],
int Density = 1
[[
float min = 0, float max = 25
]],
int Seed = 0
[[
int min = 0, int max = 100
]],
float Radius = 0.05
[[
float min = 0, float max = 1
]],
float Size = 1.0
[[
float min = 0, float max = 25
]],
output float Fac = 0 )
{
point p = Vector * Scale;
point f = floor(p);
int xx,yy,np;
vector one = 1;
for( xx=-1; xx<=1; xx++){
for( yy=-1; yy<=1; yy++){
point ff = f + vector(xx,yy,0);
vector dp = vector(5,7,11);
for( np=0; np < Density; np++){
vector pd1 = 2*cellnoise(ff+dp)-one;
vector pd2 = 2*cellnoise(ff+dp+Seed)-one;
dp *= 17;
point p1 = ff + pd1;
point p2 = ff + pd2;
p2 = (p2 - p1)*Size+p1;
// reduce to 2D
p1[2]=0;
p2[2]=0;
p [2]=0;
float r = minimum_distance(p1,p2,p);
if ( r < Radius ) {
Fac = 1 - r/Radius;
}
}
}
}
}