Kohi Game Engine
terrain.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <assets/kasset_types.h>
4 #include <defines.h>
6 #include <math/math_types.h>
7 #include <strings/kname.h>
8 
10 /*
11 Need to modify the geometry structure/functions to allow for multiple materials.
12 Write shader to handle 8 material weights/blending
13 Multi-materials (combine maps using uv offsets)?
14 Load terrain configuration from file
15 Load heightmaps
16 calculate normals/tangents (copy-pasta of existing, but using terrain_vertex
17 structure) New material type? (terrain/multi material)
18 */
19 
20 typedef struct terrain_vertex {
31 
35 
36 typedef struct terrain_vertex_data {
39 
40 typedef struct terrain_chunk_lod {
43 
51 
52 typedef struct terrain_chunk {
59 
61 
66 
69 
72 
73 typedef enum terrain_state {
80 
81 typedef struct terrain {
90  // How large each tile is on the x axis.
92  // How large each tile is on the z axis.
94  // The max height of the generated terrain.
96 
98 
101 
104 
106  // row by row, then column
107  // 0, 1, 2, 3
108  // 4, 5, 6, 7
109  // 8, 9, ...
111 
113 
117 
120 
126 
128 
129 KAPI void terrain_geometry_generate_normals(u32 vertex_count, struct terrain_vertex* vertices, u32 index_count, u32* indices);
130 
131 KAPI void terrain_geometry_generate_tangents(u32 vertex_count, struct terrain_vertex* vertices, u32 index_count, u32* indices);
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:205
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:25
_Bool b8
8-bit boolean type
Definition: defines.h:58
float f32
32-bit floating point number
Definition: defines.h:47
unsigned short u16
Unsigned 16-bit integer.
Definition: defines.h:22
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:28
unsigned char u8
Unsigned 8-bit integer.
Definition: defines.h:19
Contains a system for creating numeric identifiers.
This files contains an implementation of knames.
u64 kname
A kname is a string hash made for quick comparisons versus traditional string comparisons.
Definition: kname.h:36
Contains various math types required for the engine.
This file contains the types for common resources the engine uses.
#define TERRAIN_MAX_MATERIAL_COUNT
Definition: resource_types.h:20
Represents the extents of a 3d object.
Definition: math_types.h:213
Definition: identifier.h:20
Definition: kasset_types.h:188
A material instance, which contains handles to both the base material as well as the instance itself....
Definition: core_render_types.h:395
Definition: terrain.h:40
u32 * indices
The index data.
Definition: terrain.h:47
u32 total_index_count
The total index count, including those for side skirts.
Definition: terrain.h:45
u32 surface_index_count
The index count for the chunk surface.
Definition: terrain.h:42
u64 index_buffer_offset
The offset from the beginning of the index buffer.
Definition: terrain.h:49
Definition: terrain.h:52
vec3 center
The center of the geometry in local coordinates.
Definition: terrain.h:63
u32 total_vertex_count
Definition: terrain.h:56
u8 current_lod
Definition: terrain.h:70
material_instance material
The material instance associated with this geometry.
Definition: terrain.h:68
terrain_vertex * vertices
Definition: terrain.h:57
terrain_chunk_lod * lods
Definition: terrain.h:60
u64 vertex_buffer_offset
Definition: terrain.h:58
u32 surface_vertex_count
Definition: terrain.h:55
extents_3d extents
The extents of the geometry in local coordinates.
Definition: terrain.h:65
u16 generation
The chunk generation. Incremented every time the geometry changes.
Definition: terrain.h:54
Definition: terrain.h:36
f32 height
Definition: terrain.h:37
Definition: terrain.h:20
vec3 position
The position of the vertex.
Definition: terrain.h:22
vec3 normal
The normal of the vertex.
Definition: terrain.h:24
vec2 texcoord
The texture coordinate of the vertex.
Definition: terrain.h:26
vec4 tangent
The tangent of the vertex.
Definition: terrain.h:30
f32 material_weights[TERRAIN_MAX_MATERIAL_COUNT]
A collection of material weights for this vertex.
Definition: terrain.h:33
vec4 colour
The colour of the vertex.
Definition: terrain.h:28
Definition: terrain.h:81
u32 material_count
Definition: terrain.h:114
kname material_name
Definition: terrain.h:87
u8 lod_count
Definition: terrain.h:112
kname name
Definition: terrain.h:85
kname * material_names
Definition: terrain.h:115
vec3 origin
Definition: terrain.h:103
u32 vertex_data_length
Definition: terrain.h:99
f32 scale_y
Definition: terrain.h:95
identifier id
Definition: terrain.h:82
u32 generation
Definition: terrain.h:83
f32 tile_scale_x
Definition: terrain.h:91
u32 chunk_size
Definition: terrain.h:97
f32 tile_scale_z
Definition: terrain.h:93
u32 tile_count_z
Definition: terrain.h:89
u32 chunk_count
Definition: terrain.h:105
terrain_chunk * chunks
Definition: terrain.h:110
terrain_state state
Definition: terrain.h:84
u32 tile_count_x
Definition: terrain.h:88
extents_3d extents
Definition: terrain.h:102
terrain_vertex_data * vertex_datas
Definition: terrain.h:100
kasset_heightmap_terrain * asset
Definition: terrain.h:86
KAPI b8 terrain_update(terrain *t)
KAPI void terrain_geometry_generate_tangents(u32 vertex_count, struct terrain_vertex *vertices, u32 index_count, u32 *indices)
KAPI void terrain_destroy(terrain *t)
KAPI b8 terrain_create(kasset_heightmap_terrain *asset, terrain *out_terrain)
struct terrain_chunk terrain_chunk
KAPI void terrain_geometry_generate_normals(u32 vertex_count, struct terrain_vertex *vertices, u32 index_count, u32 *indices)
struct terrain_vertex terrain_vertex
KAPI b8 terrain_unload(terrain *t)
KAPI b8 terrain_chunk_unload(terrain *t, terrain_chunk *chunk)
KAPI b8 terrain_load(terrain *t)
struct terrain terrain
terrain_state
Definition: terrain.h:73
@ TERRAIN_STATE_INITIALIZED
Definition: terrain.h:76
@ TERRAIN_STATE_UNDEFINED
Definition: terrain.h:74
@ TERRAIN_STATE_LOADING
Definition: terrain.h:77
@ TERRAIN_STATE_LOADED
Definition: terrain.h:78
@ TERRAIN_STATE_CREATED
Definition: terrain.h:75
struct terrain_vertex_data terrain_vertex_data
KAPI b8 terrain_initialize(terrain *t)
struct terrain_chunk_lod terrain_chunk_lod
KAPI b8 terrain_chunk_load(terrain *t, terrain_chunk *chunk)
A 2-element vector.
Definition: math_types.h:19
A 3-element vector.
Definition: math_types.h:49
A 4-element vector.
Definition: math_types.h:89