22 __global float3* camera_up_axis,
const uint array_capacity,
23 __global uint* number_camera_positions, __global float4* camera_positions_at_time,
24 __global uint* number_camera_facing, __global float4* camera_facing_at_time,
25 __global
bool* do_camera_loop, __global
float* camera_speed,
26 __global float2* benchmark_start_stop_time)
36 * number_camera_positions = 1;
37 *number_camera_facing = 1;
48 camera_positions_at_time[i] = positions[i];
52 camera_facing_at_time[i] = facing[i];
68 float x =
DE(position + xOffset,
time) -
DE(position - xOffset,
time);
69 float y =
DE(position + yOffset,
time) -
DE(position - yOffset,
time);
70 float z =
DE(position + zOffset,
time) -
DE(position - zOffset,
time);
72 return normalize((float3)(x, y, z));
89 float3 distanceVector = lightPosition - pointOnGeometry;
90 float3 directionFromGeometryToLight = normalise(distanceVector);
91 float distanceFromGeometryToLight = magnitude(distanceVector);
95 float3 currentPosition = pointOnGeometry + directionFromGeometryToLight * totalDistance;
96 float distance =
DE(currentPosition,
time);
106 float y = distance * distance / (2.0f * ph);
107 float d = sqrt(distance * distance - y * y);
111 totalDistance += distance;
128 float3 distanceVector = lightPosition - pointOnGeometry;
129 float3 directionFromGeometryToLight = normalise(distanceVector);
130 float distanceFromGeometryToLight = magnitude(distanceVector);
134 float3 currentPosition = pointOnGeometry + directionFromGeometryToLight * totalDistance;
135 float distance =
DE(currentPosition,
time);
144 totalDistance += distance;
152 return incident - 2.0f * dot(normal, incident) * normal;
163 float totalDistance = 0.0f;
165 float3 currentPosition;
172#if USE_BOUNDING_VOLUME
175#if DISPLAY_BOUNDING_VOLUME
176 bool isBoundingVolume =
true;
183#if DISPLAY_BOUNDING_VOLUME
184 float actual =
DE(currentPosition,
time);
186 if (actual <= distance)
189 isBoundingVolume =
false;
193 distance =
DE(currentPosition,
time);
197 if (distance < closestDistanceToGeometry)
199 closestDistanceToGeometry = distance;
205 float distance =
DE(currentPosition,
time);
208 if (distance < closestDistanceToGeometry)
210 closestDistanceToGeometry = distance;
215 totalDistance += distance;
218#if INCREASE_INTERSECTION_EPSILON_LINEARLY
225#if DO_RENDER_MARCHING_ITERATIONS
232 float3 ambient = 0.0f;
233 float3 diffuse = 0.0f;
234 float3 specular = 0.0f;
238 const float3 lightDirection = normalise(light.
position - currentPosition);
241#if DO_AMBIENT_LIGHTING
246#if DO_DIFFUSE_LIGHTING
248 diffuse = material.
diffuse * light.
diffuse * max(dot(normal, lightDirection), 0.0f);
252#if DO_SPECULAR_HIGHLIGHTS
260 float3 viewDirection = normalise(ray.
position - currentPosition);
261 float3 halfwayVector = normalise(lightDirection + viewDirection);
265#if DO_RENDER_SURFACE_NORMALS
267 ambient = (normal + (float3)(1.0f)) * 0.5f;
271#if DISPLAY_BOUNDING_VOLUME
272 if (isBoundingVolume)
276 specular = (float3)(0);
293 return ambient + shadow * (diffuse + specular);
298#if DO_RENDER_MARCHING_ITERATIONS
327 const float h = tan(theta / 2);
328 const float viewport_height = 2.0f * h;
329 const float viewport_width = aspect_ratio * viewport_height;
333 float3 v = crossProduct(w, u);
339 float3 screenPosition = screenLowerLeftCorner + horizontal * screen_coordinate.x + vertical * screen_coordinate.y -
camera_position;
354 return (uchar3)((uchar)(clamp01(colour.x) * 255), (uchar)(clamp01(colour.y) * 255), (uchar)(clamp01(colour.z) * 255));
367__kernel
void calculatePixelColour(
371 const int ID = get_global_id(0);
380 const float2 screen_coordinate = (float2)((
float)(x) / (
float)(
width), (
float)(y) / (
float)(
height));
385#if DO_GAMMA_CORRECTION
392 const int output_ID = ID * 4;
393 colours[output_ID] = colour_8_bit.x;
394 colours[output_ID + 1] = colour_8_bit.y;
395 colours[output_ID + 2] = colour_8_bit.z;
396 colours[output_ID + 3] = 255;
#define CAMERA_VERTICAL_FOV_DEGREES
Camera vertical field of view in degrees
#define BENCHMARK_START_STOP_TIME_DONT_DO_TIMED
#define BOUNDING_VOLUME_INTERSECTION_EPSILON
Epsilon value used for determining ray collisions with the a bounding volume
#define SURFACE_SHADOW_EPSILON
Epsilon value used when calculating shadows on geometry. Represents the distance at which shadow chec...
#define SURFACE_INTERSECTION_EPSILON
Epsilon value used to define the maximum distance which is considered a ray collision
#define SCENE_MAX_GLOW_DISTANCE
Maximum distance of the glow effect. DO_GEOMETRY_GLOW must be enabled
#define SURFACE_SHADOW_FALLOFF
Falloff value used when calculating soft shadows
#define CAMERA_FOCUS_DISTANCE
Camera focus distance in world units
#define SCENE_GLOW_COLOUR
Colour of the glow effect in the scene. DO_GEOMETRY_GLOW must be enabled
#define LINEAR_INTERSECTION_EPSILON_MULTIPLIER
Multiplier used to determine how quickly SURFACE_INTERSECTION_EPSILON should increase as each ray get...
#define BOUNDING_VOLUME_COLOUR
Colour to display the bounding volume when DISPLAY_BOUNDING_VOLUME is enabled
#define SURFACE_NORMAL_EPSILON
Epsilon value used to calculate surface the normal of geometry
#define CAMERA_UP_AXIS
Camera up axis. Must be a normalised float3
#define FLOAT_MAX_VALUE
Approximate value for a float
#define GAMMA_CORRECTION_STRENGTH
Strength of gamma correction. DO_GAMMA_CORRECTION must be enabled
Light getLight(float time)
Material getMaterial(float3 position, float time)
#define MAXIMUM_MARCH_STEPS
float DE(float3 position, float time)
#define MAXIMUM_MARCH_DISTANCE
#define SCENE_BACKGROUND_COLOUR
float3 estimateSurfaceNormal(const float3 position, const float time)
Calculates the surface normal for a any point in the scene.
const uint const uint const float const float3 camera_position
const uint const uint height
uchar3 convertColourTo8Bit(const float3 colour)
Converts a colour range 0-1 to an integer colour with range 0-255.
float calculateHardShadow(const float3 pointOnGeometry, const float time, const float3 lightPosition)
Calculates hard shadows for a point on geometry in the scene.
Ray getCameraRay(const float2 screen_coordinate, const float3 camera_position, const float3 camera_facing, const float aspect_ratio)
Creates a ray for the specified position on the camera screen.
__attribute__((vec_type_hint(float3))) __kernel void calculatePixelColour(__global uchar *colours
Main kernel function. Calculates the colour for a pixel with the specified coordinate position range ...
float3 reflect(float3 incident, float3 normal)
const uint const uint const float const float3 const float3 camera_facing
float3 trace(const Ray ray, const float time)
Traces the path of a ray.
const uint const uint const float time
__kernel void getSceneInformation(__global float3 *camera_up_axis, const uint array_capacity, __global uint *number_camera_positions, __global float4 *camera_positions_at_time, __global uint *number_camera_facing, __global float4 *camera_facing_at_time, __global bool *do_camera_loop, __global float *camera_speed, __global float2 *benchmark_start_stop_time)
Kernel function used to pass scene information to the C++ interface.
float calculateSoftShadow(const float3 pointOnGeometry, const float time, const float3 lightPosition)
Calculates soft shadows for a point on geometry in the scene.
float boundingVolumeDE(float3 position, float time)
#define BENCHMARK_START_STOP_TIME
#define CAMERA_FACING_DIRECTIONS_LENGTH
#define CAMERA_POSITIONS_ARRAY
#define CAMERA_FACING_DIRECTIONS_ARRAY
#define CAMERA_POSITIONS_LENGTH
A struct representing a light, for use with the phong illumination model.
A struct representing a geometry material, for use with the Phong reflection model.
A struct representing a line in 3D space.