mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added LoD houses
This commit is contained in:
parent
7382aab13a
commit
d4fd9d2d0e
BIN
assets/voxygen/lod/house.obj
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/lod/house.obj
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -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;
|
||||
|
@ -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<u16>,
|
||||
pub pos: Vec3<i16>,
|
||||
pub flags: Flags,
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ pub struct Vertex {
|
||||
}
|
||||
|
||||
impl Vertex {
|
||||
pub fn new(pos: Vec3<f32>, norm: Vec3<f32>, col: Vec3<f32>) -> Self {
|
||||
pub fn new(pos: Vec3<f32>, norm: Vec3<f32>, col: Rgb<f32>) -> 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<f32>, flags: common::lod::Flags) -> Self {
|
||||
pub fn new(inst_pos: Vec3<f32>, col: Rgb<u8>, 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::<Self>() as wgpu::BufferAddress,
|
||||
|
@ -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<LodObjectVertex
|
||||
LodObjectVertex::new(
|
||||
v.position().into(),
|
||||
v.normal().unwrap_or([0.0, 0.0, 1.0]).into(),
|
||||
Vec3::broadcast(1.0),
|
||||
Rgb::broadcast(1.0),
|
||||
//v.color().unwrap_or([1.0; 3]).into(),
|
||||
)
|
||||
});
|
||||
|
@ -473,6 +473,7 @@ impl World {
|
||||
|
||||
let mut objects = Vec::new();
|
||||
|
||||
// Add trees
|
||||
objects.append(
|
||||
&mut self
|
||||
.sim()
|
||||
@ -497,8 +498,8 @@ impl World {
|
||||
if rpos.is_any_negative() {
|
||||
return None;
|
||||
} else {
|
||||
rpos.map(|e| e as u16).with_z(
|
||||
self.sim().get_alt_approx(tree.pos).unwrap_or(0.0) as u16,
|
||||
rpos.map(|e| e as i16).with_z(
|
||||
self.sim().get_alt_approx(tree.pos).unwrap_or(0.0) as i16,
|
||||
)
|
||||
}
|
||||
},
|
||||
@ -513,6 +514,35 @@ impl World {
|
||||
.collect(),
|
||||
);
|
||||
|
||||
// Add buildings
|
||||
objects.extend(
|
||||
index
|
||||
.sites
|
||||
.iter()
|
||||
.filter(|(_, site)| {
|
||||
site.get_origin()
|
||||
.map2(min_wpos.zip(max_wpos), |e, (min, max)| e >= 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 }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user