mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Reimplement #210
This commit is contained in:
parent
2710e6133d
commit
fd9cc76786
@ -27,7 +27,7 @@ void main() {
|
|||||||
// Increase array access by 3 to access positive values
|
// Increase array access by 3 to access positive values
|
||||||
uint norm_dir = ((f_pos_norm >> 29) & 0x1u) * 3u;
|
uint norm_dir = ((f_pos_norm >> 29) & 0x1u) * 3u;
|
||||||
// Use an array to avoid conditional branching
|
// Use an array to avoid conditional branching
|
||||||
vec3 f_norm = normals[norm_axis + norm_dir];
|
vec3 f_norm = normals[(f_pos_norm >> 29) & 0x7u];
|
||||||
|
|
||||||
vec3 light, diffuse_light, ambient_light;
|
vec3 light, diffuse_light, ambient_light;
|
||||||
get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||||
|
@ -236,7 +236,15 @@ impl<V: RectRasterableVol<Vox = Block> + ReadVol + Debug> Meshable<TerrainPipeli
|
|||||||
offs,
|
offs,
|
||||||
&colors, //&[[[colors[1][1][1]; 3]; 3]; 3],
|
&colors, //&[[[colors[1][1][1]; 3]; 3]; 3],
|
||||||
|pos, norm, col, ao, light| {
|
|pos, norm, col, ao, light| {
|
||||||
TerrainVertex::new(pos, norm, col, light.min(ao))
|
let light = (light.min(ao) * 255.0) as u32;
|
||||||
|
let norm = if norm.x != 0.0 {
|
||||||
|
if norm.x < 0.0 { 0 } else { 1 }
|
||||||
|
} else if norm.y != 0.0 {
|
||||||
|
if norm.y < 0.0 { 2 } else { 3 }
|
||||||
|
} else {
|
||||||
|
if norm.z < 0.0 { 4 } else { 5 }
|
||||||
|
};
|
||||||
|
TerrainVertex::new(norm, light, pos, col)
|
||||||
},
|
},
|
||||||
&lights,
|
&lights,
|
||||||
);
|
);
|
||||||
|
@ -42,26 +42,18 @@ gfx_defines! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Vertex {
|
impl Vertex {
|
||||||
pub fn new(pos: Vec3<f32>, norm: Vec3<f32>, col: Rgb<f32>, light: f32) -> Self {
|
pub fn new(norm_bits: u32, light: u32, pos: Vec3<f32>, col: Rgb<f32>) -> Self {
|
||||||
let (norm_axis, norm_dir) = norm
|
|
||||||
.as_slice()
|
|
||||||
.into_iter()
|
|
||||||
.enumerate()
|
|
||||||
.find(|(_i, e)| **e != 0.0)
|
|
||||||
.unwrap_or((0, &1.0));
|
|
||||||
let norm_bits = (norm_axis << 1) | if *norm_dir > 0.0 { 1 } else { 0 };
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
pos_norm: 0
|
pos_norm: 0
|
||||||
| ((pos.x as u32) & 0x00FF) << 0
|
| ((pos.x as u32) & 0x00FF) << 0
|
||||||
| ((pos.y as u32) & 0x00FF) << 8
|
| ((pos.y as u32) & 0x00FF) << 8
|
||||||
| ((pos.z.max(0.0).min((1 << 13) as f32) as u32) & 0x1FFF) << 16
|
| ((pos.z.max(0.0).min((1 << 13) as f32) as u32) & 0x1FFF) << 16
|
||||||
| ((norm_bits as u32) & 0x7) << 29,
|
| (norm_bits & 0x7) << 29,
|
||||||
col_light: 0
|
col_light: 0
|
||||||
| ((col.r.mul(255.0) as u32) & 0xFF) << 8
|
| ((col.r.mul(255.0) as u32) & 0xFF) << 8
|
||||||
| ((col.g.mul(255.0) as u32) & 0xFF) << 16
|
| ((col.g.mul(255.0) as u32) & 0xFF) << 16
|
||||||
| ((col.b.mul(255.0) as u32) & 0xFF) << 24
|
| ((col.b.mul(255.0) as u32) & 0xFF) << 24
|
||||||
| ((light.mul(255.0) as u32) & 0xFF) << 0,
|
| (light & 0xFF) << 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user