Space Sim
Loading...
Searching...
No Matches
Planet Surfaces

The system for planet surface generation and rendering. More...

Files

file  src/mesh/density.comp
 Creates a density field from a chunk.
file  src/mesh/indirect.comp
 Emits a draw command for the generated mesh.
file  src/mesh/marching_cubes.comp
 Meshes a chunk using marching cubes.
file  src/mesh/marching_cubes.h
 Marching cubes static header with constants.
file  src/render/mesh.frag
 Renders the mesh planet surface and calculates light.
file  src/render/mesh.vert
 Renders the mesh planet surface, pushing out by planet radius.

Functions

void render_mesh_planet ()
 Renders a planet's meshed surface.
float sample_density (vec3 p)
 Samples a precomputed perlin volume.
float sample_fbm_density (vec3 p)
 Samples a precomputed fbm volume.
float calc_density (vec3 p)
 Copies the exact density function from the GPU to the CPU.
void create_new_planet_mesh (int lod, ivec3 chunk_center, int chunk_id, bool is_parent)
 Creates a mesh for a certain chunk.
int find_current_lod (ivec3 center, ChunkHash **h)
 Finds the highest LOD that we have cached from the current chunk.
bool free_current_parent (int lod, int i)
 Frees the given LOD (as a parent).
bool free_parent (int lod, int i)
 Frees the parent of given LOD.
bool free_child (int lod, int i)
 Frees the child of given LOD.
void init_chunk_data ()
 Initializes and frees old ChunkData and hash tables.
void load_chunks (vec3 planet_origin, float planet_radius)
 Checks all chunks based on new Camera position, building a job list and then executing them based on ChunkScore.
int CURRENT_LOD_BOUND = -1
int LOD_DENSITY_SIZES [LODMAX]
int LOD_VERTEX_SIZES [LODMAX]
ChunkData CHUNK_DATA [LODMAX][MAX_CHUNKS]
int * CHUNK_DATA_PTR [3]
int CHUNK_DATA_FLAG = 0

Detailed Description

The system for planet surface generation and rendering.

Function Documentation

◆ render_mesh_planet()

void render_mesh_planet ( )

◆ sample_density()

float sample_density ( vec3 p)

Samples a precomputed perlin volume.

Parameters
pThe position to sample.

Definition at line 217 of file mesh.c.

References c0, c1, lerp(), perlin_tex, PERLIN_TEXTURE_SIZE, sample_density(), ivec3::x, vec3::x, ivec3::y, vec3::y, ivec3::z, and vec3::z.

◆ sample_fbm_density()

float sample_fbm_density ( vec3 p)

Samples a precomputed fbm volume.

Parameters
pThe position to sample.

Definition at line 269 of file mesh.c.

References c0, c1, fbm_tex, FBM_TEXTURE_SIZE, lerp(), sample_fbm_density(), ivec3::x, vec3::x, ivec3::y, vec3::y, ivec3::z, and vec3::z.

Referenced by calc_density(), and sample_fbm_density().

◆ calc_density()

◆ create_new_planet_mesh()

void create_new_planet_mesh ( int lod,
ivec3 chunk_center,
int chunk_id,
bool is_parent )

Creates a mesh for a certain chunk.

Parameters
lodThe LOD level to generate.
chunk_centerThe chunk center in world space.
chunk_idThe ID of the chunk in CHUNK_DATA.
is_parentIf the chunk is that of higher LOD than child. This makes it so that the parent always reports the vertex count.

Definition at line 433 of file mesh.c.

References CHUNK_DATA, chunk_id, create_new_planet_mesh(), DENSITY_COMPUTE_SHADER, DENSITY_SSBO, DENSITY_VERTEX_SSBO, FBM_TEXTURE, INDIRECT_BUFFER, INDIRECT_COMPUTE_SHADER, is_parent, Uniform::location, lod, LOD_RES, MARCHING_CUBES_COMPUTE_SHADER, PERLIN_TEXTURE, ComputeShaderProgram::program, size, ChunkData::uID, ComputeShaderProgram::uniforms, ivec3::x, ivec3::y, and ivec3::z.

Referenced by create_new_planet_mesh(), and load_chunks().

◆ find_current_lod()

int find_current_lod ( ivec3 center,
ChunkHash ** h )

Finds the highest LOD that we have cached from the current chunk.

Definition at line 630 of file mesh.c.

References find_chunk_hash(), find_current_lod(), and LODMAX.

Referenced by find_current_lod().

◆ free_current_parent()

bool free_current_parent ( int lod,
int i )

Frees the given LOD (as a parent).

Definition at line 661 of file mesh.c.

References CHUNK_DATA, delete_chunk_hash(), ChunkData::free, free_current_parent(), ChunkData::is_child, lod, and LODMAX.

Referenced by display_main_menu(), free_current_parent(), and load_chunks().

◆ free_parent()

bool free_parent ( int lod,
int i )

Frees the parent of given LOD.

Definition at line 690 of file mesh.c.

References already_emitted, CHUNK_DATA, delete_chunk_hash(), ChunkData::free, free_parent(), ChunkData::id1, ChunkData::is_child, lod, and LODMAX.

Referenced by display_main_menu(), free_parent(), and load_chunks().

◆ free_child()

bool free_child ( int lod,
int i )

Frees the child of given LOD.

Definition at line 724 of file mesh.c.

References already_emitted, CHUNK_DATA, delete_chunk_hash(), ChunkData::free, free_child(), ChunkData::id0, ChunkData::is_child, lod, and LODMAX.

Referenced by display_main_menu(), free_child(), and load_chunks().

◆ init_chunk_data()

◆ load_chunks()

void load_chunks ( vec3 planet_origin,
float planet_radius )

Checks all chunks based on new Camera position, building a job list and then executing them based on ChunkScore.

Parameters
planet_originThe origin to determine the relative noise value.
planet_radiusThe radius to determine the height offset needed to find the planet surface from the planet center.

Definition at line 893 of file mesh.c.

References aabb_in_frustum(), ChunkScore::active, already_emitted, assign_new_uID(), Camera::cam_data, CamData::cam_pos, CamData::cam_vel, ChunkData::center, CHUNK_DATA, CHUNK_DATA_FLAG, CHUNK_DATA_SSBO, CHUNK_RADIUS, chunk_uID, CHUNK_WORLD_SIZE, CHUNK_ZERO_COMPUTE_SHADER, compareFrees(), compareJobs(), create_new_planet_mesh(), current_cam, emitted_chunk_ids, emitted_chunk_lods, emitted_chunks, end_timer(), find_chunk_hash(), ChunkData::free, free_child(), free_current_parent(), free_parent(), frees, generation_id, get_current_lod(), get_view_planes(), ChunkHash::id, ChunkData::id0, ChunkData::id1, ChunkScore::index, ChunkData::is_child, is_parent, ivec3_add(), ivec3_dist(), ivec3_scale(), job_data, jobs, ZeroEntry::key, LIGHT_CAM, load_chunks(), ChunkData::lod, ChunkScore::lod, lod, lod_level, LODMAX, MAX, ChunkData::max, MAX_CHUNKS, MAX_CHUNKS_LOD, MAX_ZERO_LIST, MIN, ChunkData::min, planet_origin, planet_radius, replace_chunk_hash(), ChunkData::replacement_index, ChunkData::replacement_lod, replacement_mask, res, s, ChunkScore::score, set_current_lod(), start_timer(), ChunkData::uID, uID, vec3_scale(), VERTEX_COUNT_MAX, ChunkData::within_frustum, ivec3::x, vec3::x, vec4::x, ivec3::y, vec3::y, vec4::y, ivec3::z, vec3::z, vec4::z, zero_fence, zero_hash_table, and zero_list_count.

Referenced by load_chunks(), and main().

Variable Documentation

◆ CURRENT_LOD_BOUND

int CURRENT_LOD_BOUND = -1

Definition at line 63 of file main.c.

Referenced by render_mesh_planet().

◆ LOD_DENSITY_SIZES

int LOD_DENSITY_SIZES[LODMAX]

Definition at line 64 of file main.c.

Referenced by init().

◆ LOD_VERTEX_SIZES

int LOD_VERTEX_SIZES[LODMAX]

Definition at line 65 of file main.c.

Referenced by init().

◆ CHUNK_DATA

◆ CHUNK_DATA_PTR

int* CHUNK_DATA_PTR[3]

Definition at line 68 of file main.c.

◆ CHUNK_DATA_FLAG

int CHUNK_DATA_FLAG = 0

Definition at line 69 of file main.c.

Referenced by init(), and load_chunks().