-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathlight.h
More file actions
136 lines (114 loc) · 3.53 KB
/
light.h
File metadata and controls
136 lines (114 loc) · 3.53 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* This file is part of the gk project (https://github.com/recp/gk)
* Copyright (c) Recep Aslantas.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef gk_light_h
#define gk_light_h
#include "common.h"
#include "color.h"
#include <cglm/cglm.h>
struct GkScene;
struct GkNode;
struct GkPipeline;
struct GkColorOrTex;
struct GkCamera;
struct GkTransform;
typedef enum GkLightType {
GK_LIGHT_TYPE_AMBIENT = 1,
GK_LIGHT_TYPE_DIRECTIONAL = 2,
GK_LIGHT_TYPE_POINT = 3,
GK_LIGHT_TYPE_SPOT = 4,
GK_LIGHT_TYPE_CUSTOM = 5
} GkLightType;
typedef enum GkLightFlags {
GK_LIGHTF_NONE = 0,
GK_LIGHTF_TRANSFORMED = 1 << 1,
GK_LIGHTF_DISABLED = 1 << 2
} GkLightFlags;
/* for scene, because node can have multiple light instancs */
typedef struct GkLightRef {
struct GkLightRef *prev;
struct GkLightRef *next;
} GkLightRef;
typedef struct GkLight {
GkLightRef ref;
struct GkLight *next;
struct GkNode *node;
struct GkCamera *camera;
const char *name;
vec4 *ambient;
vec3 dir;
vec3 defdir;
GkLightType type;
GkColor color;
int32_t index;
uint8_t isvalid;
GkLightFlags flags;
} GkLight;
typedef GkLight GkAmbientLight;
typedef struct GkDirectionalLight {
GkLight base;
} GkDirectionalLight;
typedef struct GkPointLight {
GkLight base;
float constAttn;
float linearAttn;
float quadAttn;
} GkPointLight;
typedef struct GkSpotLight {
GkLight base;
float constAttn;
float linearAttn;
float quadAttn;
float falloffAngle;
float cutoffCosine;
float cutoffExp;
} GkSpotLight;
void
gkUniformLights(struct GkScene * __restrict scene,
struct GkPipeline * __restrict prog);
void
gkUniformLight(struct GkScene * __restrict scene,
GkLight * __restrict light,
struct GkPipeline * __restrict prog,
mat4 transView);
void
gkUniformSingleLight(struct GkScene * __restrict scene,
GkLight * __restrict light,
struct GkPipeline * __restrict prog);
void
gkApplyTransformToLight(struct GkScene * __restrict scene,
GkLight * __restrict light,
struct GkPipeline * __restrict prog);
void
gkShadowMatrix(struct GkScene *scene,
GkLight *light,
mat4 viewProj);
struct GkTransform*
gkLightTransform(GkLight *light);
void
gkLightPos(struct GkScene *scene, GkLight *light, vec3 position);
void
gkLightDir(struct GkScene *scene, GkLight *light, vec3 dir);
void
gkLightDirWorld(struct GkScene *scene, GkLight *light, vec3 dir);
void
gkLightRotation(struct GkScene *scene,
GkLight *light,
vec3 right,
vec3 up,
vec3 fwd);
#endif /* gk_light_h */