Animated chunk loading

This commit is contained in:
Joshua Barretto 2019-09-24 16:43:51 +01:00
parent 82dbfefa16
commit 8085e37f82
6 changed files with 17 additions and 0 deletions

View File

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

View File

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

View File

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

View File

@ -9,6 +9,7 @@ in uint v_col_light;
layout (std140) layout (std140)
uniform u_locals { uniform u_locals {
vec3 model_offs; vec3 model_offs;
float load_time;
}; };
out vec3 f_pos; out vec3 f_pos;
@ -26,6 +27,8 @@ void main() {
float((v_pos_norm >> 16) & 0x1FFFu) float((v_pos_norm >> 16) & 0x1FFFu)
) + model_offs; ) + 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. // 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; uint norm_axis = (v_pos_norm >> 30) & 0x3u;

View File

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

View File

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