Space Sim
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1#ifndef TYPES_H
2
3#define TYPES_H
4#include <stdbool.h>
5#include <stdint.h>
6#include <SDL2/SDL.h>
7#include <GL/glew.h>
8#include "nk_config.h"
9#include "nuklear/nuklear.h"
10#include <omp.h>
11#include "nuklear/nuklear_sdl_gl3.h"
12
13
14
19
24
29
34
35#define FOV 90
36#define VIEW_NEAR 0.01
37#define VIEW_FAR 100000.0
38
39#define BODY_COUNT 15000
40#define MAX_NODES 45000
41
42#define SHADOW_MAP_SIZE 2048
43#define QUERY_FRAMES 3
44
45typedef struct vec2 {float x, y;} vec2;
46typedef struct vec3 {float x, y, z;} vec3;
47typedef struct vec4 {float x, y, z, w;} vec4;
48typedef struct ivec3 {int x, y, z;} ivec3;
49typedef struct ivec4 {int x, y, z, w;} ivec4;
50typedef struct uvec4 {uint32_t x, y, z, w;} uvec4;
51typedef struct mat4 {float a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3;} mat4;
52
53typedef struct {
54 uint64_t start;
55 uint64_t freq;
56} Timer;
57
58static inline void start_timer(Timer* t) {
59 t->start = SDL_GetPerformanceCounter();
60 t->freq = SDL_GetPerformanceFrequency();
61}
62
63static inline double end_timer(Timer* t) {
64 Uint64 end = SDL_GetPerformanceCounter();
65 return (double)(end - t->start) * 1000.0 / (double)t->freq;
66}
67
68
91
92typedef struct Particle
93{
98
99} Particle;
100
101typedef struct ParticleVertex
102{
105
107
108typedef struct Node
109{
110
113 float mass;
118
119} Node;
120
121typedef struct MortonPair
122{
123 uint32_t pid;
124 uint32_t m;
125
126} MortonPair;
127
139typedef struct MortonData
140{
142
143} MortonData;
144
145typedef struct GPUNode {
146
148 // vec4 hs;
151 int next;
153} GPUNode;
154#define MAX_DEPTH 64
155
156typedef struct NodeData {
160 uint32_t pad0;
161 uint32_t pad1;
162 uint32_t pad2;
167
168 // GPUNode nodes[MAX_NODES];
169} NodeData;
170
171#define WORKGROUP_SIZE 128
172#define RADIX_BIN_SIZE 128
173
174typedef struct RadixData
175{
176 uint32_t local_prefix[5000 * WORKGROUP_SIZE];
181} RadixData;
182#define MAX_CHUNKS 1000
183
184#define MAX_CHUNK_LIST (MAX_CHUNKS * 20)
185
186
187
188typedef struct ChunkList
189{
190 int lod0;
191 int lod1;
194 int id0;
195 int id1;
199 bool free;
200
201}ChunkList;
202
203typedef struct NodeCounter
204{
205 uint32_t queue_out;
208 uint32_t star_pcnt;
209
211
212typedef struct BoundsData {
213 uint32_t minx;
214 uint32_t miny;
215 uint32_t minz;
216 uint32_t maxx;
217 uint32_t maxy;
218 uint32_t maxz;
219} BoundsData;
220
227typedef struct Render
228{
230} RenderData;
231typedef struct Camera
232{
234 float yaw, pitch, roll;
236
237 // float x, y, z;
238 // vec3 velocity;
239
241
242} Camera;
243typedef struct ChunkScore
244{
245 int index;
246 int lod;
247 float score;
248 bool active;
249
250} ChunkScore;
251
272
273
274// 52^3
275// LOD0 = 1
276//
277// 24^3
278// LOD1 = 27
279//
280// 12^3
281// LOD2 = VIEW FRUSTUM = 5-6
282//
283
284typedef enum LodLevels
285{
286
292
293} LodLevels;
294
295
296// max chunks per lod level
297#define MAX_DENSITY_RESOLUTION 64
298
299static const int LOD_RES[LODMAX] =
300{
301 16, 8, 4, 2
302};
303
304// lod0 has slots in lod1, lod1 has slots in lod2
305// each chunk gets both emitted always, higher lod parent points to child lower lod in the other array
306// this means that each lod level past 0 must contain enough to house the parent
307
308// 8 | 16 + 8 | 16 + 16 | 32 + 16
309static const int MAX_CHUNKS_LOD[LODMAX] =
310{
311 32, 64, 100, 600
312};
313
314extern int LOD_DENSITY_SIZES[LODMAX];
315extern int LOD_VERTEX_SIZES[LODMAX];
316
317
318#define CHUNK_WORLD_SIZE 20
336
337
338typedef struct MarchingCubesData
339{
340
342 int EDGE_TABLE[256];
343 int TRIANGLE_TABLE[256][16];
344
346
347typedef struct Vertex
348{
350 float pad0;
352 float pad1;
354 float pad2;
355
356} Vertex;
357
364
365typedef struct WaterVertex
366{
369
370
371typedef struct WarpLayer
372{
373
375 float freq0;
377 float freq1;
379 float freq2;
380 float amp;
381 float pad0;
382 float pad1;
383 float pad3;
384
385} WarpLayer;
386
387typedef struct PerlinLayer
388{
389
390 float freq;
391 float amp;
392 float pad0;
393 float pad1;
394
396
397typedef struct FBMLayer
398{
399
400 float freq;
401 float amp;
402 float pad0;
403 float pad1;
404
405} FBMLayer;
406
407#define MAX_LAYERS 24
422
423#define WATER_FFT_TEXTURE_SIZE 128
424#define WATER_FFT_L 1000
425
431
432
433typedef struct Uniform
434{
435 GLuint location;
436 char name[256];
437} Uniform;
438
440{
441 char path[256];
442 GLuint program;
443
445
446
448
449typedef struct ShaderProgram
450{
451
452 GLuint program;
453 char vert_path[256];
454 char frag_path[256];
455
457
459
460// 1 chunks max lod
461// 27 chunks half lod
462// 90 chunks quarter
463
464#define MAX_LOD_MAX 1
465#define HALF_LOD_MAX 27
466#define QUARTER_LOD_MAX 90
467#define HALF_DENSITY_RESOLUTION 32
468#define QUARTER_DENSITY_RESOLUTION 16
469
470
471#define WATER_RES 1024
472// #define WATER_RES 512
473
481
482
483#define VERTEX_COUNT_MAX (LODMAX * MAX_CHUNKS * 5)
484typedef struct VertexInfo
485{
486 int vcnt;
487 uint32_t uid;
488 uint32_t pad0;
489 uint32_t pad1;
490
491} VertexInfo;
498
499float noise(vec3 p);
500
501#define MESH_RES 64
502
503#define ATMOSPHERE_RES 64
504
505#define CHUNK_RADIUS 6
506#define CHUNK_DIAMETER (CHUNK_RADIUS * 2 + 1)
507#define CHUNK_LIMIT (CHUNK_DIAMETER * CHUNK_DIAMETER * CHUNK_DIAMETER)
508#define PERLIN_TEXTURE_SIZE 32
509#define WORLEY_TEXTURE_SIZE 32
510#define FBM_TEXTURE_SIZE 32
511
512
514extern uint32_t * ATMOSPHERE_INDICES;
515extern int ATMOSPHERE_VCNT;
516extern int ATMOSPHERE_ICNT;
517
518typedef struct {
519 uint32_t count; // number of vertices
520 uint32_t instanceCount; // usually 1
521 uint32_t first;
522 uint32_t baseInstance;
524
525
526extern Globals GLOBALS;
527
528
529extern GLsync fence;
530
531
532
533extern Camera cam;
534extern Camera space_cam;
535extern Camera LIGHT_CAM;
536extern Camera * current_cam;
537
538extern GLuint64 density_time;
539extern GLuint64 mc_time;
540extern GLuint d_q;
541extern GLuint mc_q;
542extern bool within_planet_atmosphere;
543float noise3d(vec3 p);
544void render_sky_cubemap();
545#endif
Camera cam
Definition main.c:222
#define LODMAX
int ATMOSPHERE_VCNT
Definition main.c:188
AtmosphereVertex * ATMOSPHERE_VERTS
Definition main.c:186
void render_sky_cubemap()
Renders the atmosphere and clouds from inside of the atmosphere.
Definition main.c:935
uint32_t * ATMOSPHERE_INDICES
Definition main.c:187
int ATMOSPHERE_ICNT
Definition main.c:189
int LOD_VERTEX_SIZES[LODMAX]
Definition main.c:65
int LOD_DENSITY_SIZES[LODMAX]
Definition main.c:64
uint32_t uid
Definition types.h:487
int vcnt
Definition types.h:486
uint32_t pad1
Definition types.h:489
uint32_t pad0
Definition types.h:488
float noise3d(vec3 p)
Definition init.c:508
GLuint64 mc_time
Definition main.c:1721
GLsync fence
Definition main.c:247
Camera * current_cam
Definition main.c:225
GLuint64 density_time
Definition main.c:1720
Globals GLOBALS
Definition main.c:39
Camera LIGHT_CAM
Definition main.c:224
bool within_planet_atmosphere
Definition main.c:1249
Camera space_cam
Definition main.c:223
vec3 center
Definition types.h:112
int first_child
Definition types.h:114
bool subdivided
Definition types.h:115
vec3 center_of_mass
Definition types.h:111
int body_index
Definition types.h:117
float mass
Definition types.h:113
float half_size
Definition types.h:116
Definition types.h:109
vec4 acc
Definition types.h:97
vec4 p_m
Definition types.h:94
vec4 mat
Definition types.h:95
vec3 vel
Definition main.h:10
Definition main.h:8
vec3 color
Definition types.h:353
float pad1
Definition types.h:352
float pad0
Definition types.h:350
vec3 pos
Definition types.h:349
float pad2
Definition types.h:354
vec3 normal
Definition types.h:351
int chunk_vertex_offset
Definition types.h:477
float density[(MAX_DENSITY_RESOLUTION+1) *(MAX_DENSITY_RESOLUTION+1) *(MAX_DENSITY_RESOLUTION+1)]
Definition types.h:478
int chunk_density_offset
Definition types.h:476
Vertex vertices[MAX_DENSITY_RESOLUTION *MAX_DENSITY_RESOLUTION *MAX_DENSITY_RESOLUTION *8]
Definition types.h:479
vec4 water_data[WATER_FFT_TEXTURE_SIZE *WATER_FFT_TEXTURE_SIZE]
Definition types.h:428
float x
Definition types.h:45
PerformanceQueryTypes
Definition types.h:70
@ PQUERY_MAIN
Definition types.h:72
@ PQUERY_TREECOUNT
Definition types.h:76
@ PQUERY_POSTPROCESS
Definition types.h:87
@ PQUERY_TREE
Definition types.h:77
@ PQUERY_RADIX
Definition types.h:75
@ PQUERY_BOUNDS
Definition types.h:73
@ PQUERY_PARTICLE
Definition types.h:84
@ PQUERY_MORTON
Definition types.h:74
@ PQUERY_MAX
Definition types.h:88
@ PQUERY_DRAW
Definition types.h:86
@ PQUERY_CLOUDS
Definition types.h:80
@ PQUERY_WATER
Definition types.h:82
@ PQUERY_MESH_GEN
Definition types.h:83
@ PQUERY_MESH
Definition types.h:85
@ PQUERY_ATMOSPHERE
Definition types.h:79
@ PQUERY_COM
Definition types.h:78
@ PQUERY_WATER_GEN
Definition types.h:81
bool active
Definition types.h:248
float a1
Definition types.h:51
float roll
Definition types.h:234
int EDGE_TO_VERTICES[12][2]
Definition types.h:341
bool on_ground
Definition types.h:240
float w
Definition types.h:47
uint32_t m
Definition types.h:124
vec3 dir
Definition types.h:233
int lod0
Definition types.h:190
PerlinLayer perlin_layers[MAX_LAYERS]
Definition types.h:418
char name[256]
Definition types.h:436
float z
Definition types.h:47
int nodes_visited[BODY_COUNT]
Definition types.h:135
const int LOD_RES[LODMAX]
Definition types.h:299
Uniform uniforms[32]
Definition types.h:444
bool particle_toggle
Definition types.h:266
uint32_t y
Definition types.h:50
vec4 sun_dir
Definition types.h:415
float d3
Definition types.h:51
float c2
Definition types.h:51
int x
Definition types.h:49
float score
Definition types.h:247
int id1
Definition types.h:195
int pad0
Definition types.h:414
VertexInfo vertex_counts[VERTEX_COUNT_MAX]
Definition types.h:496
#define VERTEX_COUNT_MAX
Definition types.h:483
float b0
Definition types.h:51
#define RADIX_BIN_SIZE
Definition types.h:172
WarpLayer warp_layers[MAX_LAYERS]
Definition types.h:417
uint32_t pad0
Definition types.h:160
float mass_pow
Definition types.h:261
int id0
Definition types.h:194
float c1
Definition types.h:51
float x
Definition types.h:47
uint32_t global_offsets[5000 *RADIX_BIN_SIZE]
Definition types.h:179
vec4 nmax[MAX_NODES]
Definition types.h:166
int replacement_lod
Definition types.h:331
vec4 sun_color
Definition types.h:416
MortonPair entry[BODY_COUNT]
Definition types.h:141
uint32_t x
Definition types.h:50
vec3 max
Definition types.h:150
float a2
Definition types.h:51
int w
Definition types.h:49
ivec3 min
Definition types.h:327
GLuint mc_q
double end_timer(Timer *t)
Definition types.h:63
#define WORKGROUP_SIZE
Definition types.h:171
int lod
Definition types.h:324
bool free
Definition types.h:199
float x
Definition main.h:5
uint32_t maxx
Definition types.h:216
bool lock_on
Definition types.h:257
ivec3 center
Definition types.h:329
int id0
Definition types.h:322
uint32_t uID
Definition types.h:326
GLuint program
Definition types.h:452
int y
Definition types.h:48
#define MAX_DEPTH
Definition types.h:154
float noise(vec3 p)
Definition density.comp:116
mat4 inv_proj
Definition types.h:225
vec4 lrsn[MAX_NODES]
Definition types.h:164
ivec3 max
Definition types.h:328
ivec4 resolution
Definition types.h:229
#define MAX_DENSITY_RESOLUTION
Definition types.h:297
#define BODY_COUNT
Definition types.h:39
int fbm_count
Definition types.h:413
int z
Definition types.h:49
float b3
Definition types.h:51
float y
Definition types.h:45
vec4 p_colors[BODY_COUNT]
Definition types.h:132
float y
Definition types.h:47
uint32_t ready_queue[MAX_NODES]
Definition types.h:157
uint32_t minx
Definition types.h:213
int warp_count
Definition types.h:411
GLuint d_q
int hovered_body
Definition types.h:255
int perlin_count
Definition types.h:412
int p_spawn_cnt
Definition types.h:207
uint32_t z
Definition types.h:50
int index
Definition types.h:245
mat4 inv_view
Definition types.h:225
uint32_t claimed[BODY_COUNT]
Definition types.h:134
float y
Definition main.h:5
int id1
Definition types.h:323
uint32_t maxy
Definition types.h:217
vec3 forward
Definition types.h:233
int p_dead_cnt
Definition types.h:206
void start_timer(Timer *t)
Definition types.h:58
char frag_path[256]
Definition types.h:454
const int MAX_CHUNKS_LOD[LODMAX]
Definition types.h:309
uint32_t pid
Definition types.h:123
uint32_t children_remaining[MAX_NODES]
Definition types.h:158
int offset0
Definition types.h:192
char vert_path[256]
Definition types.h:453
float d1
Definition types.h:51
float radius
Definition types.h:262
float a3
Definition types.h:51
vec3 min
Definition types.h:197
int z
Definition types.h:48
vec4 min
Definition types.h:149
float max_mass
Definition types.h:260
bool water_toggle
Definition types.h:265
LodLevels
Definition types.h:285
@ LOD2
Definition types.h:289
@ LOD0
Definition types.h:287
@ LOD3
Definition types.h:290
@ LOD1
Definition types.h:288
uint32_t pad1
Definition types.h:161
uint64_t start
Definition types.h:54
int next
Definition types.h:151
float c0
Definition types.h:51
float z
Definition main.h:5
uint32_t star_particles[BODY_COUNT]
Definition types.h:136
uint32_t star_pcnt
Definition types.h:208
uint32_t depth_offsets[MAX_DEPTH+1]
Definition types.h:159
int EDGE_TABLE[256]
Definition types.h:342
vec3 target
Definition types.h:233
vec4 com_m[MAX_NODES]
Definition types.h:163
uint32_t miny
Definition types.h:214
mat4 view
Definition types.h:225
vec3 max
Definition types.h:198
float pitch
Definition types.h:234
vec3 right
Definition types.h:233
bool force_space_cam
Definition types.h:263
vec4 nmin[MAX_NODES]
Definition types.h:165
bool planet_meshing_toggle
Definition types.h:264
float lod_dist[3]
Definition types.h:494
vec3 pos
Definition types.h:367
int x
Definition types.h:48
#define MAX_NODES
Definition types.h:40
bool paused
Definition types.h:258
float b2
Definition types.h:51
float d0
Definition types.h:51
char path[256]
Definition types.h:441
bool free
Definition types.h:333
bool is_child
Definition types.h:332
vec4 com_m
Definition types.h:147
vec3 center
Definition types.h:196
uint32_t local_bin_count[5000 *RADIX_BIN_SIZE]
Definition types.h:180
uint64_t freq
Definition types.h:55
bool profiling
Definition types.h:268
uint32_t w
Definition types.h:50
vec4 cam_vel
Definition types.h:224
bool within_frustum
Definition types.h:325
uint32_t queue_out
Definition types.h:205
FBMLayer fbm_layers[MAX_LAYERS]
Definition types.h:419
float yaw
Definition types.h:234
uint32_t emitted_chunks
Definition types.h:495
GLuint location
Definition types.h:435
mat4 proj
Definition types.h:225
#define MAX_LAYERS
Definition types.h:407
uint32_t minz
Definition types.h:215
float min_mass
Definition types.h:259
int selected_body
Definition types.h:256
Particle p_spawn[BODY_COUNT]
Definition types.h:131
CamData cam_data
Definition types.h:235
uint32_t local_offsets[BODY_COUNT]
Definition types.h:177
int offset1
Definition types.h:193
uint32_t pad2
Definition types.h:162
float a0
Definition types.h:51
uint32_t block_bin_count[5000 *RADIX_BIN_SIZE]
Definition types.h:178
uint32_t p_dead[BODY_COUNT]
Definition types.h:133
uint32_t maxz
Definition types.h:218
float c3
Definition types.h:51
int lod1
Definition types.h:191
uint32_t local_prefix[5000 *WORKGROUP_SIZE]
Definition types.h:176
int TRIANGLE_TABLE[256][16]
Definition types.h:343
int y
Definition types.h:49
Uniform uniforms[32]
Definition types.h:456
#define WATER_FFT_TEXTURE_SIZE
Definition types.h:423
bool sky_toggle
Definition types.h:267
vec4 cam_pos
Definition types.h:224
float b1
Definition types.h:51
float d2
Definition types.h:51
int replacement_index
Definition types.h:330
ivec4 lrpd
Definition types.h:152
Particle p[BODY_COUNT]
Definition types.h:137
int lod
Definition types.h:246
vec3 up
Definition types.h:233
Definition types.h:53
Definition types.h:48
Definition types.h:49
Definition types.h:51
Definition types.h:50
Definition types.h:45
Definition main.h:5
Definition types.h:47
uniform float t
Definition water.comp:23
vec3 offset2
Definition types.h:378
float pad1
Definition types.h:403
float amp
Definition types.h:401
float freq0
Definition types.h:375
vec3 offset1
Definition types.h:376
float freq
Definition types.h:400
float amp
Definition types.h:391
float pad3
Definition types.h:383
float freq1
Definition types.h:377
float pad1
Definition types.h:382
float pad0
Definition types.h:392
float freq2
Definition types.h:379
vec3 offset0
Definition types.h:374
float pad1
Definition types.h:393
float pad0
Definition types.h:381
float amp
Definition types.h:380
float freq
Definition types.h:390
float pad0
Definition types.h:402