-
Notifications
You must be signed in to change notification settings - Fork 8
/
mandelbulb.osl
82 lines (65 loc) · 2.32 KB
/
mandelbulb.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
/*
* Copyright 2015, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* mandelbulb OSL Shader - by Sylvio Sell - maitag.de - Rostock Germany 2015
* More information: https://github.com/maitag/blender-osl-shader
*/
float mandelbulb_intensity (
point p,
float max_iter, // max number of iterations
float max_pow, // max power
float n // power
)
{
// -----------------------------
int iter = 0;
float r, theta, phi;
float tmp_pow_r_n, tmp_sin_theta_n;
float x = p[0];
float y = p[1];
float z = p[2];
float tmp_xyz = x*x + y*y + z*z;
while ( tmp_xyz < max_pow && iter < max_iter)
{
r = sqrt(tmp_xyz);
theta = atan2(sqrt(x*x + y*y) , z);
phi = atan2(y,x);
tmp_pow_r_n = pow(r,n);
tmp_sin_theta_n = sin(theta*n);
x = tmp_pow_r_n * tmp_sin_theta_n * cos(phi*n) + p[0];
y = tmp_pow_r_n * tmp_sin_theta_n * sin(phi*n) + p[1];
z = tmp_pow_r_n * cos(theta*n) + p[2];
tmp_xyz = x*x + y*y + z*z;
iter++;
}
return( iter / max_iter );
}
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
shader node_mandelbulb (
float iterations = 12.0, // number of iterations
float power = 2.0, // max power
float symmetry = 3.0, // power
float scale = 1.0,
point position = P,
output float intensity = 0.0 )
{
// -----------------------------
intensity = mandelbulb_intensity( position*scale, iterations, power, symmetry );
}