Animated chunk loading

This commit is contained in:
Joshua Barretto 2019-09-24 16:43:51 +01:00
parent 2165e79971
commit 46fdc87014
6 changed files with 17 additions and 0 deletions

View File

@ -11,6 +11,7 @@ in float f_light;
layout (std140)
uniform u_locals {
vec3 model_offs;
float load_time;
};
out vec4 tgt_color;

View File

@ -8,6 +8,7 @@ in uint v_col_light;
layout (std140)
uniform u_locals {
vec3 model_offs;
float load_time;
};
out vec3 f_pos;

View File

@ -10,6 +10,7 @@ in float f_light;
layout (std140)
uniform u_locals {
vec3 model_offs;
float load_time;
};
out vec4 tgt_color;

View File

@ -9,6 +9,7 @@ in uint v_col_light;
layout (std140)
uniform u_locals {
vec3 model_offs;
float load_time;
};
out vec3 f_pos;
@ -26,6 +27,8 @@ void main() {
float((v_pos_norm >> 16) & 0x1FFFu)
) + model_offs;
f_pos.z *= min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0);
// TODO: last 3 bits in v_pos_norm should be a number between 0 and 5, rather than 0-2 and a direction.
uint norm_axis = (v_pos_norm >> 30) & 0x3u;

View File

@ -23,6 +23,7 @@ gfx_defines! {
constant Locals {
model_offs: [f32; 3] = "model_offs",
load_time: f32 = "load_time",
}
pipeline pipe {
@ -66,6 +67,7 @@ impl Locals {
pub fn default() -> Self {
Self {
model_offs: [0.0; 3],
load_time: 0.0,
}
}
}

View File

@ -23,6 +23,7 @@ use vek::*;
struct TerrainChunk {
// GPU data
load_time: f32,
opaque_model: Model<TerrainPipeline>,
fluid_model: Model<FluidPipeline>,
sprite_instances: HashMap<(BlockKind, usize), Instances<SpriteInstance>>,
@ -613,6 +614,7 @@ impl<V: RectRasterableVol> Terrain<V> {
proj_mat: Mat4<f32>,
) {
let current_tick = client.get_tick();
let current_time = client.state().get_time();
// Add any recently created or changed chunks to the list of chunks to be meshed.
for (modified, pos) in client
@ -796,9 +798,15 @@ impl<V: RectRasterableVol> Terrain<V> {
// It's the mesh we want, insert the newly finished model into the terrain model
// data structure (convert the mesh to a model first of course).
Some(todo) if response.started_tick <= todo.started_tick => {
let load_time = self
.chunks
.get(&response.pos)
.map(|chunk| chunk.load_time)
.unwrap_or(current_time as f32);
self.chunks.insert(
response.pos,
TerrainChunk {
load_time,
opaque_model: renderer
.create_model(&response.opaque_mesh)
.expect("Failed to upload chunk mesh to the GPU!"),
@ -825,6 +833,7 @@ impl<V: RectRasterableVol> Terrain<V> {
}),
)
.into_array(),
load_time,
}])
.expect("Failed to upload chunk locals to the GPU!"),
visible: false,