diff --git a/assets/voxygen/lod/house.obj b/assets/voxygen/lod/house.obj new file mode 100644 index 0000000000..08fa1d7126 --- /dev/null +++ b/assets/voxygen/lod/house.obj @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:09998d9d613ff3685914167bd09b93c7e6258d280f6f2b76bd0fdc548a416693 +size 1101 diff --git a/assets/voxygen/shaders/lod-object-vert.glsl b/assets/voxygen/shaders/lod-object-vert.glsl index d5880ecae7..fe5027f55d 100644 --- a/assets/voxygen/shaders/lod-object-vert.glsl +++ b/assets/voxygen/shaders/lod-object-vert.glsl @@ -21,7 +21,8 @@ layout(location = 0) in vec3 v_pos; layout(location = 1) in vec3 v_norm; layout(location = 2) in vec3 v_col; layout(location = 3) in vec3 inst_pos; -layout(location = 4) in uint inst_flags; +layout(location = 4) in uvec3 inst_col; +layout(location = 5) in uint inst_flags; const uint FLAG_SNOW_COVERED = 1; @@ -47,9 +48,8 @@ void main() { f_pos.z -= pow(distance(f_pos.xy + focus_off.xy, focus_pos.xy + focus_off.xy) * 0.05, 2); #endif - // Hacky, very bad, 50 is ~ tree height - f_norm = v_norm;//mix(v_norm, vec3(0, 0, 1), clamp(model_pos.z / 50, 0, 1)); - f_col = vec4(vec3(0.02, 0.1, 0.01) * (sin(inst_pos.xyy) * 0.33 + 0.66), 1.0);//vec4(v_col, 1.0); + f_norm = v_norm; + f_col = vec4(vec3(inst_col) * (1.0 / 255.0) * v_col * (sin(inst_pos.xyy) * 0.33 + 0.66), 1.0); if ((inst_flags & FLAG_SNOW_COVERED) > 0u) { snow_cover = 1.0; diff --git a/common/src/lod.rs b/common/src/lod.rs index 123ff87277..e778327351 100644 --- a/common/src/lod.rs +++ b/common/src/lod.rs @@ -18,12 +18,13 @@ bitflags::bitflags! { pub enum ObjectKind { Oak, Pine, + House, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Object { pub kind: ObjectKind, - pub pos: Vec3, + pub pos: Vec3, pub flags: Flags, } diff --git a/voxygen/src/render/pipelines/lod_object.rs b/voxygen/src/render/pipelines/lod_object.rs index fabcad7d18..8e86d9aef9 100644 --- a/voxygen/src/render/pipelines/lod_object.rs +++ b/voxygen/src/render/pipelines/lod_object.rs @@ -12,7 +12,7 @@ pub struct Vertex { } impl Vertex { - pub fn new(pos: Vec3, norm: Vec3, col: Vec3) -> Self { + pub fn new(pos: Vec3, norm: Vec3, col: Rgb) -> Self { Self { pos: pos.into_array(), norm: norm.into_array(), @@ -40,21 +40,24 @@ impl VertexTrait for Vertex { #[derive(Copy, Clone, Debug, Zeroable, Pod)] pub struct Instance { inst_pos: [f32; 3], + inst_col: [u8; 4], flags: u32, } impl Instance { - pub fn new(inst_pos: Vec3, flags: common::lod::Flags) -> Self { + pub fn new(inst_pos: Vec3, col: Rgb, flags: common::lod::Flags) -> Self { Self { inst_pos: inst_pos.into_array(), + inst_col: Rgba::new(col.r, col.g, col.b, 255).into_array(), flags: flags.bits() as u32, } } fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { - const ATTRIBUTES: [wgpu::VertexAttribute; 2] = wgpu::vertex_attr_array![ + const ATTRIBUTES: [wgpu::VertexAttribute; 3] = wgpu::vertex_attr_array![ 3 => Float32x3, - 4 => Uint32, + 4 => Uint8x4, + 5 => Uint32, ]; wgpu::VertexBufferLayout { array_stride: mem::size_of::() as wgpu::BufferAddress, diff --git a/voxygen/src/scene/lod.rs b/voxygen/src/scene/lod.rs index 34c5e89635..3da3ec4818 100644 --- a/voxygen/src/scene/lod.rs +++ b/voxygen/src/scene/lod.rs @@ -63,6 +63,7 @@ impl Lod { object_data: [ (lod::ObjectKind::Oak, make_lod_object("oak", renderer)), (lod::ObjectKind::Pine, make_lod_object("pine", renderer)), + (lod::ObjectKind::House, make_lod_object("house", renderer)), ] .into_iter() .collect(), @@ -113,10 +114,16 @@ impl Lod { z_range.start.min(pos.z as i32)..z_range.end.max(pos.z as i32) }, )); + // TODO: Put this somewhere more easily configurable, like a manifest + let color = match object.kind { + lod::ObjectKind::Pine => Rgb::new(0, 25, 12), + lod::ObjectKind::Oak => Rgb::new(13, 50, 5), + lod::ObjectKind::House => Rgb::new(20, 15, 0), + }; objects .entry(object.kind) .or_default() - .push(LodObjectInstance::new(pos, object.flags)); + .push(LodObjectInstance::new(pos, color, object.flags)); } objects .into_iter() @@ -226,7 +233,7 @@ fn make_lod_object(name: &str, renderer: &mut Renderer) -> Model= min && e < max) + .reduce_and() + }) + .filter_map(|(_, site)| match &site.kind { + SiteKind::Refactor(site) => { + Some(site.plots().filter_map(|plot| match &plot.kind { + site2::plot::PlotKind::House(_) => Some(site.tile_wpos(plot.root_tile)), + _ => None, + })) + }, + _ => None, + }) + .flatten() + .map(|wpos2d| lod::Object { + kind: lod::ObjectKind::House, + pos: (wpos2d - min_wpos) + .map(|e| e as i16) + .with_z(self.sim().get_alt_approx(wpos2d).unwrap_or(0.0) as i16), + flags: lod::Flags::empty(), + }), + ); + lod::Zone { objects } } }