Realtime Fractal Renderer Documentation
trivial.cl
Go to the documentation of this file.
1#include "utils.cl"
2#include "types.cl"
3#include "sdf.cl"
4
5#ifndef BENCHMARK
6
7#define CAMERA_POSITIONS_LENGTH 1
8#define CAMERA_POSITIONS_ARRAY { (float4)(15, -5, 0, 0) }
9#define CAMERA_FACING_DIRECTIONS_LENGTH 1
10#define CAMERA_FACING_DIRECTIONS_ARRAY { (float4)(normalise((float3)(1, 0, 0)), 0.0f) }
11
12#define DO_SOFT_SHADOWS true
13
14#endif
15
16// Debug
17#define DO_RENDER_SURFACE_NORMALS true
18#define DO_RENDER_MARCHING_ITERATIONS false
19#define DISPLAY_BOUNDING_VOLUME false
20
21#define SCENE_BACKGROUND_COLOUR (float3)(0.1f, 0.1f, 0.1f)
22
23#define SURFACE_INTERSECTION_EPSILON 0.00001f
24#define MAXIMUM_MARCH_STEPS 300
25#define MAXIMUM_MARCH_DISTANCE 100
26#define SURFACE_SHADOW_FALLOFF 5.0f
27
29{
30 float t = fmod(time * 0.75f, 2.0f * PI);
31
32 Light light;
33 light.ambient = (float3)(0.1f, 0.1f, 0.1f);
34 light.diffuse = (float3)(0.6f, 0.6f, 0.6f);
35 light.specular = (float3)(1.0f, 1.0f, 1.0f);
36 light.position = (float3)(25 * cos(t), -25, 25 * sin(t));
37
38 return light;
39}
40
41Material SDF(float3 position, float time, float * distance)
42{
43 float offset = -sin(time * 0.5f) * 1.5f;
44 float dist_sphere = sphereSDF(position, (float3)(0.0f, offset - 5.0f, 0.0f), 1.0f);
45 float dist_plane = f_abs(position.y);
46
47 Material material;
48
49 if (dist_sphere < dist_plane)
50 {
51 *distance = dist_sphere;
52
53 material.ambient = (float3)(0.9f, 0.9f, 0.9f);
54 material.diffuse = material.ambient;
55 material.specular = (float3)(0.5f, 0.5f, 0.5f);
56 material.shininess = 25.0f;
57 }
58 else
59 {
60 *distance = dist_plane;
61
62 material.ambient = (float3)(0.92f, 0.30f, 0.16f);
63 material.diffuse = material.ambient;
64 material.specular = (float3)(0.0f, 0.0f, 0.0f);
65 material.shininess = 100.0f;
66 }
67
68 return material;
69}
70
71Material getMaterial(float3 position, float time)
72{
73 float distance;
74 return SDF(position, time, &distance);
75}
76
77float DE(float3 position, float time)
78{
79 float distance;
80 SDF(position, time, &distance);
81 return distance;
82}
83
84#include "main.cl"
const uint const uint const float time
Definition: main.cl:368
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
Light getLight(float time)
Definition: trivial.cl:28
Material getMaterial(float3 position, float time)
Definition: trivial.cl:71
Material SDF(float3 position, float time, float *distance)
Definition: trivial.cl:41
float DE(float3 position, float time)
Definition: trivial.cl:77