Realtime Fractal Renderer Documentation
mandelbulb_cross_section.cl
Go to the documentation of this file.
1#define OVERRIDE true
2
3#ifndef ITERATIONS
4#define ITERATIONS 10
5#endif
6
7
8#include "utils.cl"
9#include "types.cl"
10#include "sdf.cl"
11
13{
14 float t = fmod(time * 0.5f, 2.0f * PI);
15
16 Light light;
17 light.ambient = (float3)(0.1f, 0.1f, 0.1f);
18 light.diffuse = (float3)(0.6f, 0.6f, 0.6f);
19 light.specular = (float3)(1.0f, 1.0f, 1.0f);
20 light.position = (float3)(5, -5, 5);
21
22 return light;
23}
24
25Material mandelbulbSDF(const float3 position, const float time, float* distance)
26{
27 // Material
28 Material material;
29
30 const float power = 7.75f + time * 0.01f;
31
32 float3 w = position;
33 float m = dot(w, w);
34 float4 colorParams = (float4) (absolute(w), m);
35 float dz = 1.0f;
36
37 for (int i = 0; i < ITERATIONS; i++)
38 {
39 dz = 8.0f * pow(sqrt(m), 7.0f) * dz + 1.0f;
40
41 // Calculate power
42 float r = length(w);
43 float b = power * acos(w.y / r);
44 float a = power * atan2(w.x, w.z);
45 w = pow(r, power) * (float3) (sin(b) * sin(a), cos(b), sin(b) * cos(a)) + position;
46
47 colorParams = min(colorParams, (float4) (absolute(w), m));
48 m = dot(w, w);
49
50 if (m > 256.0f) break;
51 }
52
53 material.ambient = (float3)(colorParams.x, colorParams.y, colorParams.z);
54 material.diffuse = material.ambient;
55 material.specular = (float3)(0.5f, 0.5f, 0.5f);
56 material.shininess = 50.0f;
57
58 // Distance estimation
59 *distance = opSubtraction(0.5f - position.x - time * 0.01f, 0.25f * log(m) * sqrt(m) / dz);
60
61 return material;
62}
63
64float boundingVolumeDE(float3 position, float time)
65{
66 return opSubtraction(0.5f - position.x - time * 0.01f, sphereSDF(position, (float3)(0, 0, 0), 1.25f));
67}
68
69#include "mandelbulb.cl"
70
const uint const uint const float time
Definition: main.cl:368
Light getLight(float time)
float boundingVolumeDE(float3 position, float time)
Material mandelbulbSDF(const float3 position, const float time, float *distance)
#define ITERATIONS
A struct representing a light, for use with the phong illumination model.
Definition: types.cl:32
float3 ambient
Definition: types.cl:34
float3 position
Definition: types.cl:33
float3 diffuse
Definition: types.cl:35
float3 specular
Definition: types.cl:36
A struct representing a geometry material, for use with the Phong reflection model.
Definition: types.cl:20
float3 ambient
Definition: types.cl:21
float3 diffuse
Definition: types.cl:22
float shininess
Definition: types.cl:24
float3 specular
Definition: types.cl:23