Realtime Fractal Renderer Documentation
mandelbulb.cl
Go to the documentation of this file.
1#ifndef BENCHMARK
2
3// Config
4#define CAMERA_POSITIONS_LENGTH 1
5#define CAMERA_POSITIONS_ARRAY { (float4)(2, 0, 0, 0) }
6#define CAMERA_FACING_DIRECTIONS_LENGTH 1
7#define CAMERA_FACING_DIRECTIONS_ARRAY { (float4)(normalise((float3)(1, 1, 1)), 0) }
8#define FORCE_FREE_CAMERA true
9
10// Features
11#define DO_GEOMETRY_GLOW true
12#define DO_SOFT_SHADOWS true
13#define DO_HARD_SHADOWS false
14
15#ifndef USE_BOUNDING_VOLUME
16#define USE_BOUNDING_VOLUME true
17#endif
18
19// Debug
20#define DO_RENDER_SURFACE_NORMALS false
21#define DO_RENDER_MARCHING_ITERATIONS false
22#define DISPLAY_BOUNDING_VOLUME false
23
24#endif
25
26#ifndef OVERRIDE
27#define OVERRIDE false
28#endif
29
30// Scene
31#define MAXIMUM_MARCH_STEPS 150
32#define MAXIMUM_MARCH_DISTANCE 50.0f
33#define SURFACE_INTERSECTION_EPSILON 0.001f
34#define SCENE_GLOW_COLOUR (float3)(0.8f, 0.8f, 0.8f)
35#define SCENE_MAX_GLOW_DISTANCE 0.05f
36#define SCENE_BACKGROUND_COLOUR (float3)(0.1f, 0.1f, 0.1f)
37#define CAMERA_SPEED 0.5f
38#define SURFACE_SHADOW_EPSILON 0.01f
39#define SURFACE_SHADOW_FALLOFF 10.0f
40
41#ifndef ITERATIONS
42#define ITERATIONS 10
43#endif
44
45#include "utils.cl"
46#include "types.cl"
47#include "sdf.cl"
48
49#if ! OVERRIDE
50
52{
53 float t = fmod(time * 0.5f, 2.0f * PI);
54
55 Light light;
56 light.ambient = (float3)(0.1f, 0.1f, 0.1f);
57 light.diffuse = (float3)(0.6f, 0.6f, 0.6f);
58 light.specular = (float3)(1.0f, 1.0f, 1.0f);
59 light.position = (float3)(5 * cos(t), -5, 5 * sin(t));
60
61 return light;
62}
63
64Material mandelbulbSDF(const float3 position, const float time, float* distance)
65{
66 // Material
67 Material material;
68
69 const float power = 7.75f + time * 0.01f;
70
71 float3 w = position;
72 float m = dot(w, w);
73 float4 colorParams = (float4) (absolute(w), m);
74 float dz = 1.0f;
75
76 for (int i = 0; i < ITERATIONS; i++)
77 {
78 dz = 8.0f * pow(sqrt(m), 7.0f) * dz + 1.0f;
79
80 // Calculate power
81 float r = length(w);
82 float b = power * acos(w.y / r);
83 float a = power * atan2(w.x, w.z);
84 w = pow(r, power) * (float3) (sin(b) * sin(a), cos(b), sin(b) * cos(a)) + position;
85
86 colorParams = min(colorParams, (float4) (absolute(w), m));
87 m = dot(w, w);
88
89 if (m > 256.0f) break;
90 }
91
92 material.ambient = (float3)(colorParams.x, colorParams.y, colorParams.z);
93 material.diffuse = material.ambient;
94 material.specular = (float3)(0.5f, 0.5f, 0.5f);
95 material.shininess = 50.0f;
96
97 // Distance estimation
98 *distance = 0.25f * log(m) * sqrt(m) / dz;
99
100 return material;
101}
102
103float boundingVolumeDE(float3 position, float time)
104{
105 return sphereSDF(position, (float3)(0, 0, 0), 1.25f);
106}
107
108#endif
109
110Material getMaterial(float3 position, float time)
111{
112 float distance;
113 return mandelbulbSDF(position, time, &distance);
114}
115
116
117
118float DE(float3 position, float time)
119{
120 float distance;
121 mandelbulbSDF(position, time, &distance);
122 return distance;
123}
124
125#include "main.cl"
const uint const uint const float time
Definition: main.cl:368
Light getLight(float time)
Definition: mandelbulb.cl:51
Material getMaterial(float3 position, float time)
Definition: mandelbulb.cl:110
float boundingVolumeDE(float3 position, float time)
Definition: mandelbulb.cl:103
float DE(float3 position, float time)
Definition: mandelbulb.cl:118
Material mandelbulbSDF(const float3 position, const float time, float *distance)
Definition: mandelbulb.cl:64
#define ITERATIONS
Definition: mandelbulb.cl:42
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