mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added terrain pipeline
This commit is contained in:
parent
ae4f1ae2ea
commit
bd561dd1aa
@ -9,3 +9,4 @@ specs = "0.14"
|
||||
shred = "0.7"
|
||||
vek = "0.9"
|
||||
dot_vox = "1.0"
|
||||
threadpool = "1.7"
|
||||
|
@ -5,5 +5,6 @@ pub mod comp;
|
||||
pub mod figure;
|
||||
pub mod state;
|
||||
pub mod terrain;
|
||||
pub mod util;
|
||||
pub mod volumes;
|
||||
pub mod vol;
|
||||
|
1
common/src/util/mod.rs
Normal file
1
common/src/util/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod worker_pool;
|
10
common/src/util/worker_pool.rs
Normal file
10
common/src/util/worker_pool.rs
Normal file
@ -0,0 +1,10 @@
|
||||
// Library
|
||||
use threadpool::ThreadPool;
|
||||
|
||||
pub struct WorkerPool {
|
||||
thread_pool: ThreadPool,
|
||||
}
|
||||
|
||||
impl WorkerPool {
|
||||
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
in vec3 f_pos;
|
||||
in vec3 f_norm;
|
||||
in vec3 f_col;
|
||||
flat in uint f_bone_idx;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
@ -20,10 +21,23 @@ uniform u_globals {
|
||||
vec4 tick;
|
||||
};
|
||||
|
||||
struct BoneData {
|
||||
mat4 bone_mat;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_bones {
|
||||
BoneData bones[16];
|
||||
};
|
||||
|
||||
out vec4 tgt_color;
|
||||
|
||||
void main() {
|
||||
vec3 world_norm = (model_mat * vec4(f_norm, 0.0)).xyz;
|
||||
vec3 world_norm = (
|
||||
model_mat *
|
||||
bones[f_bone_idx].bone_mat *
|
||||
vec4(f_norm, 0.0)
|
||||
).xyz;
|
||||
|
||||
float ambient = 0.5;
|
||||
|
||||
|
@ -33,11 +33,13 @@ uniform u_bones {
|
||||
out vec3 f_pos;
|
||||
out vec3 f_norm;
|
||||
out vec3 f_col;
|
||||
flat out uint f_bone_idx;
|
||||
|
||||
void main() {
|
||||
f_pos = v_pos;
|
||||
f_norm = v_norm;
|
||||
f_col = v_col;
|
||||
f_bone_idx = v_bone_idx;
|
||||
|
||||
gl_Position =
|
||||
proj_mat *
|
||||
|
33
voxygen/shaders/terrain.frag
Normal file
33
voxygen/shaders/terrain.frag
Normal file
@ -0,0 +1,33 @@
|
||||
#version 330 core
|
||||
|
||||
in vec3 f_pos;
|
||||
in vec3 f_norm;
|
||||
in vec3 f_col;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec3 model_offs;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 tick;
|
||||
};
|
||||
|
||||
out vec4 tgt_color;
|
||||
|
||||
void main() {
|
||||
float ambient = 0.5;
|
||||
|
||||
vec3 sun_dir = normalize(vec3(1.3, 1.7, 1.1));
|
||||
|
||||
float sun_diffuse = dot(sun_dir, f_norm) * 0.5;
|
||||
|
||||
tgt_color = vec4(f_col * (ambient + sun_diffuse), 1.0);
|
||||
}
|
36
voxygen/shaders/terrain.vert
Normal file
36
voxygen/shaders/terrain.vert
Normal file
@ -0,0 +1,36 @@
|
||||
#version 330 core
|
||||
|
||||
in vec3 v_pos;
|
||||
in vec3 v_norm;
|
||||
in vec3 v_col;
|
||||
|
||||
layout (std140)
|
||||
uniform u_locals {
|
||||
vec3 model_offs;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 tick;
|
||||
};
|
||||
|
||||
out vec3 f_pos;
|
||||
out vec3 f_norm;
|
||||
out vec3 f_col;
|
||||
|
||||
void main() {
|
||||
f_pos = v_pos;
|
||||
f_norm = v_norm;
|
||||
f_col = v_col;
|
||||
|
||||
gl_Position =
|
||||
proj_mat *
|
||||
view_mat *
|
||||
vec4(v_pos + model_offs, 1);
|
||||
}
|
@ -17,8 +17,8 @@ impl Animation for RunAnimation {
|
||||
skeleton: &mut Self::Skeleton,
|
||||
time: f64,
|
||||
) {
|
||||
let wave = (time as f32 * 8.0).sin();
|
||||
let wave_fast = (time as f32 * 4.0).sin();
|
||||
let wave = (time as f32 * 12.0).sin();
|
||||
let wave_fast = (time as f32 * 6.0).sin();
|
||||
|
||||
skeleton.head.offset = Vec3::unit_z() * 13.0;
|
||||
skeleton.head.ori = Quaternion::rotation_z(wave * 0.3);
|
||||
@ -27,16 +27,18 @@ impl Animation for RunAnimation {
|
||||
skeleton.chest.ori = Quaternion::rotation_z(wave * 0.3);
|
||||
|
||||
skeleton.belt.offset = Vec3::unit_z() * 7.0;
|
||||
skeleton.belt.ori = Quaternion::rotation_z(wave * 0.3);
|
||||
skeleton.belt.ori = Quaternion::rotation_z(wave * 0.2);
|
||||
|
||||
skeleton.shorts.offset = Vec3::unit_z() * 4.0;
|
||||
skeleton.shorts.ori = Quaternion::rotation_z(wave * 0.3);
|
||||
skeleton.shorts.ori = Quaternion::rotation_z(wave * 0.1);
|
||||
|
||||
skeleton.l_hand.offset = Vec3::new(-8.0, wave * 5.0, 9.0);
|
||||
skeleton.r_hand.offset = Vec3::new(8.0, -wave * 5.0, 9.0);
|
||||
skeleton.l_hand.offset = Vec3::new(-7.5, wave * 5.0, 9.0);
|
||||
skeleton.r_hand.offset = Vec3::new(7.5, -wave * 5.0, 9.0);
|
||||
|
||||
skeleton.l_foot.offset = Vec3::new(-3.5, -wave * 4.0, -(wave_fast.abs() - 0.5).abs() * 4.0);
|
||||
skeleton.r_foot.offset = Vec3::new(3.5, wave * 4.0, -(wave_fast.abs() - 0.5).abs() * 4.0);
|
||||
skeleton.l_foot.offset = Vec3::new(-3.5, 2.0 - wave * 8.0, 3.5 - (wave_fast.abs() - 0.5).abs() * 4.0);
|
||||
skeleton.l_foot.ori = Quaternion::rotation_x(-wave + 1.0);
|
||||
skeleton.r_foot.offset = Vec3::new(3.5, 2.0 + wave * 8.0, 3.5 - (wave_fast.abs() - 0.5).abs() * 4.0);
|
||||
skeleton.r_foot.ori = Quaternion::rotation_x(wave + 1.0);
|
||||
|
||||
skeleton.back.offset = Vec3::new(-8.0, 5.0, 16.0);
|
||||
skeleton.back.ori = Quaternion::rotation_y(2.5);
|
||||
|
@ -23,6 +23,10 @@ pub use self::{
|
||||
SkyboxPipeline,
|
||||
Locals as SkyboxLocals,
|
||||
},
|
||||
terrain::{
|
||||
TerrainPipeline,
|
||||
Locals as TerrainLocals,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
pub mod figure;
|
||||
pub mod skybox;
|
||||
pub mod terrain;
|
||||
|
||||
// Library
|
||||
use gfx::{
|
||||
|
68
voxygen/src/render/pipelines/terrain.rs
Normal file
68
voxygen/src/render/pipelines/terrain.rs
Normal file
@ -0,0 +1,68 @@
|
||||
// Library
|
||||
use gfx::{
|
||||
self,
|
||||
// Macros
|
||||
gfx_defines,
|
||||
gfx_vertex_struct_meta,
|
||||
gfx_constant_struct_meta,
|
||||
gfx_impl_struct_meta,
|
||||
gfx_pipeline,
|
||||
gfx_pipeline_inner,
|
||||
};
|
||||
use vek::*;
|
||||
|
||||
// Local
|
||||
use super::{
|
||||
Globals,
|
||||
super::{
|
||||
Pipeline,
|
||||
TgtColorFmt,
|
||||
TgtDepthFmt,
|
||||
},
|
||||
};
|
||||
|
||||
gfx_defines! {
|
||||
vertex Vertex {
|
||||
pos: [f32; 3] = "v_pos",
|
||||
norm: [f32; 3] = "v_norm",
|
||||
col: [f32; 3] = "v_col",
|
||||
}
|
||||
|
||||
constant Locals {
|
||||
model_offs: [f32; 3] = "model_offs",
|
||||
}
|
||||
|
||||
pipeline pipe {
|
||||
vbuf: gfx::VertexBuffer<Vertex> = (),
|
||||
|
||||
locals: gfx::ConstantBuffer<Locals> = "u_locals",
|
||||
globals: gfx::ConstantBuffer<Globals> = "u_globals",
|
||||
|
||||
tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
|
||||
tgt_depth: gfx::DepthTarget<TgtDepthFmt> = gfx::preset::depth::LESS_EQUAL_WRITE,
|
||||
}
|
||||
}
|
||||
|
||||
impl Vertex {
|
||||
pub fn new(pos: Vec3<f32>, norm: Vec3<f32>, col: Rgb<f32>) -> Self {
|
||||
Self {
|
||||
pos: pos.into_array(),
|
||||
col: col.into_array(),
|
||||
norm: norm.into_array(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Locals {
|
||||
pub fn default() -> Self {
|
||||
Self {
|
||||
model_offs: [0.0; 3],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TerrainPipeline;
|
||||
|
||||
impl Pipeline for TerrainPipeline {
|
||||
type Vertex = Vertex;
|
||||
}
|
@ -17,6 +17,7 @@ use super::{
|
||||
Globals,
|
||||
figure,
|
||||
skybox,
|
||||
terrain,
|
||||
},
|
||||
};
|
||||
|
||||
@ -43,6 +44,7 @@ pub struct Renderer {
|
||||
|
||||
skybox_pipeline: GfxPipeline<skybox::pipe::Init<'static>>,
|
||||
figure_pipeline: GfxPipeline<figure::pipe::Init<'static>>,
|
||||
terrain_pipeline: GfxPipeline<terrain::pipe::Init<'static>>,
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
@ -70,6 +72,14 @@ impl Renderer {
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/figure.frag")),
|
||||
)?;
|
||||
|
||||
// Construct a pipeline for rendering terrain
|
||||
let terrain_pipeline = create_pipeline(
|
||||
&mut factory,
|
||||
terrain::pipe::new(),
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/terrain.vert")),
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/terrain.frag")),
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
device,
|
||||
encoder: factory.create_command_buffer().into(),
|
||||
@ -80,6 +90,7 @@ impl Renderer {
|
||||
|
||||
skybox_pipeline,
|
||||
figure_pipeline,
|
||||
terrain_pipeline,
|
||||
})
|
||||
}
|
||||
|
||||
@ -164,6 +175,26 @@ impl Renderer {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Queue the rendering of the provided terrain chunk model in the upcoming frame.
|
||||
pub fn render_terrain_chunk(
|
||||
&mut self,
|
||||
model: &Model<terrain::TerrainPipeline>,
|
||||
globals: &Consts<Globals>,
|
||||
locals: &Consts<terrain::Locals>,
|
||||
) {
|
||||
self.encoder.draw(
|
||||
&model.slice,
|
||||
&self.terrain_pipeline.pso,
|
||||
&terrain::pipe::Data {
|
||||
vbuf: model.vbuf.clone(),
|
||||
locals: locals.buf.clone(),
|
||||
globals: globals.buf.clone(),
|
||||
tgt_color: self.tgt_color_view.clone(),
|
||||
tgt_depth: self.tgt_depth_view.clone(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
struct GfxPipeline<P: gfx::pso::PipelineInit> {
|
||||
|
@ -82,8 +82,8 @@ impl Scene {
|
||||
Some(load_segment("pants.vox").generate_mesh_with_offset(Vec3::new(-5.0, -3.0, 0.0))),
|
||||
Some(load_segment("hand.vox").generate_mesh_with_offset(Vec3::new(-2.0, -2.0, -1.0))),
|
||||
Some(load_segment("hand.vox").generate_mesh_with_offset(Vec3::new(-2.0, -2.0, -1.0))),
|
||||
Some(load_segment("foot.vox").generate_mesh_with_offset(Vec3::new(-2.5, -3.0, 0.0))),
|
||||
Some(load_segment("foot.vox").generate_mesh_with_offset(Vec3::new(-2.5, -3.0, 0.0))),
|
||||
Some(load_segment("foot.vox").generate_mesh_with_offset(Vec3::new(-2.5, -3.0, -2.0))),
|
||||
Some(load_segment("foot.vox").generate_mesh_with_offset(Vec3::new(-2.5, -3.0, -2.0))),
|
||||
Some(load_segment("sword.vox").generate_mesh_with_offset(Vec3::new(-6.5, -1.0, 0.0))),
|
||||
None,
|
||||
None,
|
||||
|
BIN
voxygen/test_assets/elf/belt.vox
Normal file
BIN
voxygen/test_assets/elf/belt.vox
Normal file
Binary file not shown.
BIN
voxygen/test_assets/elf/chest.vox
Normal file
BIN
voxygen/test_assets/elf/chest.vox
Normal file
Binary file not shown.
BIN
voxygen/test_assets/elf/foot.vox
Normal file
BIN
voxygen/test_assets/elf/foot.vox
Normal file
Binary file not shown.
BIN
voxygen/test_assets/elf/hand.vox
Normal file
BIN
voxygen/test_assets/elf/hand.vox
Normal file
Binary file not shown.
BIN
voxygen/test_assets/elf/head.vox
Normal file
BIN
voxygen/test_assets/elf/head.vox
Normal file
Binary file not shown.
BIN
voxygen/test_assets/elf/pants.vox
Normal file
BIN
voxygen/test_assets/elf/pants.vox
Normal file
Binary file not shown.
BIN
voxygen/test_assets/elf/sword.vox
Normal file
BIN
voxygen/test_assets/elf/sword.vox
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user