Realtime Fractal Renderer Documentation
planet.cl
Go to the documentation of this file.
1#ifndef BENCHMARK
2
3#define CAMERA_POSITIONS_LENGTH 1
4#define CAMERA_POSITIONS_ARRAY { (float4)(40, 0, 0, 0) }
5#define CAMERA_FACING_DIRECTIONS_LENGTH 1
6#define CAMERA_FACING_DIRECTIONS_ARRAY { (float4)(normalise((float3)(1, 1, 1)), 0) }
7#define FORCE_FREE_CAMERA true
8#define CAMERA_SPEED 5.0f
9
10#define USE_BOUNDING_VOLUME true
11//#define DISPLAY_BOUNDING_VOLUME true
12
13#endif
14
15#define SCENE_BACKGROUND_COLOUR (float3)(0.5f, 0.8f, 0.9f)
16#define MAXIMUM_MARCH_STEPS 200
17#define MAXIMUM_MARCH_DISTANCE 100.0f
18#define SURFACE_INTERSECTION_EPSILON 0.00001f
19#define CAMERA_FOCUS_DISTANCE 0.01f
20
21#define DO_GEOMETRY_GLOW true
22#define SCENE_GLOW_COLOUR (float3)(0.6f, 0.6f, 0.8f)
23#define SCENE_MAX_GLOW_DISTANCE 1.0f
24
25#include "simplexnoise1234.cl"
26#include "types.cl"
27#include "sdf.cl"
28
29#define SCALE 0.25f
30#define AMPLITUDE 10.0f
31#define ITERATIONS 2
32
33#define FREQUENCY_MULTIPLIER 2.5f
34#define AMPLITUDE_MULTIPLIER 0.4f
35
36float getHeightAt(const float x, const float y, const float z)
37{
38 float frequency = SCALE;
39 float amplitude = AMPLITUDE;
40 float height = 0.0f;
41
42 for (int j = 0; j < ITERATIONS; j++)
43 {
44 height += amplitude * snoise3(x * frequency, y * frequency, z * frequency);
45 frequency *= FREQUENCY_MULTIPLIER;
46 amplitude *= AMPLITUDE_MULTIPLIER;
47 }
48
49 return height;
50}
51
53{
54 float t = fmod(time * 0.5f, 2.0f * PI);
55
56 Light light;
57 light.ambient = (float3)(0.1f, 0.1f, 0.1f);
58 light.diffuse = (float3)(0.6f, 0.6f, 0.6f);
59 light.specular = (float3)(1.0f, 1.0f, 1.0f);
60 light.position = (float3)(50 * cos(t), -25, 50 * sin(t));
61
62 return light;
63}
64
65Material SDF(const float3 position, const float time, float* distance)
66{
67 float height = getHeightAt(position.x, position.y, position.z) - 1.0f;
68
69 // Distance estimation
70 *distance = sphereSDF(position, (float3)(0), 10.0f) - max(height, 0.0f) / 20.0f;
71
72 float3 colour;
73
74 // Water
75 if (height <= 0.0f)
76 {
77 colour = (float3)(0, 0.05, 0.8);
78 }
79 // Land
80 else
81 {
82 // Snow
83 if (height >= 8.0f)
84 {
85 colour = (float3)(0.9, 0.9, 1);
86 }
87 // Grass
88 else
89 {
90 colour = (float3)(0.1, 0.5, 0.2);
91 }
92 }
93
94 // Material
95 Material material;
96 material.ambient = colour;
97 material.diffuse = material.ambient;
98 material.specular = (float3)(0.5f, 0.5f, 0.5f);
99 material.shininess = 25.0f;
100
101 return material;
102}
103
104Material getMaterial(float3 position, float time)
105{
106 float distance;
107 return SDF(position, time, &distance);
108}
109
110float boundingVolumeDE(float3 position, float time)
111{
112 return sphereSDF(position, (float3)(0), 11.0f);
113}
114
115float DE(float3 position, float time)
116{
117 float distance;
118 SDF(position, time, &distance);
119 return distance;
120}
121
122#include "main.cl"
const uint const uint height
Definition: main.cl:368
const uint const uint const float time
Definition: main.cl:368
#define SCALE
Definition: planet.cl:29
Light getLight(float time)
Definition: planet.cl:52
#define FREQUENCY_MULTIPLIER
Definition: planet.cl:33
float getHeightAt(const float x, const float y, const float z)
Definition: planet.cl:36
Material SDF(const float3 position, const float time, float *distance)
Definition: planet.cl:65
Material getMaterial(float3 position, float time)
Definition: planet.cl:104
float boundingVolumeDE(float3 position, float time)
Definition: planet.cl:110
float DE(float3 position, float time)
Definition: planet.cl:115
#define ITERATIONS
Definition: planet.cl:31
#define AMPLITUDE_MULTIPLIER
Definition: planet.cl:34
#define AMPLITUDE
Definition: planet.cl:30
float snoise3(float x, float y, float z)
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