-
Notifications
You must be signed in to change notification settings - Fork 0
/
rt_skybox_simple.c
45 lines (37 loc) · 1015 Bytes
/
rt_skybox_simple.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Copyright (c) 2020, Evgeniy Morozov
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <assert.h>
#include "rt_skybox_simple.h"
struct rt_skybox_s
{
colour_t from;
colour_t to;
};
rt_skybox_t *rt_skybox_new_gradient(colour_t from, colour_t to)
{
rt_skybox_t *result = calloc(1, sizeof(rt_skybox_t));
assert(NULL != result);
result->from = from;
result->to = to;
return result;
}
rt_skybox_t *rt_skybox_new_background(colour_t background)
{
return rt_skybox_new_gradient(background, background);
}
colour_t rt_skybox_value(const rt_skybox_t *skybox, const ray_t *ray)
{
assert(NULL != skybox);
assert(NULL != ray);
point3_t unit_direction = vec3_normalized(ray->direction);
double t = 0.5 * (unit_direction.y + 1.0);
return vec3_lerp(skybox->from, skybox->to, t);
}
void rt_skybox_delete(rt_skybox_t *skybox)
{
free(skybox);
}