mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Made meshing considerably faster
This commit is contained in:
parent
b57031804e
commit
09197049cb
@ -25,14 +25,12 @@ impl Meshable<FigurePipeline, FigurePipeline> for Segment {
|
||||
|
||||
for (pos, vox) in self.full_vol_iter() {
|
||||
if let Some(col) = vox.get_color() {
|
||||
let col = col.map(|e| e as f32 / 255.0);
|
||||
|
||||
vol::push_vox_verts(
|
||||
&mut mesh,
|
||||
self,
|
||||
pos,
|
||||
offs + pos.map(|e| e as f32),
|
||||
&[[[Some(col); 3]; 3]; 3],
|
||||
&[[[Rgba::from_opaque(col); 3]; 3]; 3],
|
||||
|origin, norm, col, ao, light| {
|
||||
FigureVertex::new(
|
||||
origin,
|
||||
@ -84,14 +82,12 @@ impl Meshable<SpritePipeline, SpritePipeline> for Segment {
|
||||
|
||||
for (pos, vox) in self.full_vol_iter() {
|
||||
if let Some(col) = vox.get_color() {
|
||||
let col = col.map(|e| e as f32 / 255.0);
|
||||
|
||||
vol::push_vox_verts(
|
||||
&mut mesh,
|
||||
self,
|
||||
pos,
|
||||
offs + pos.map(|e| e as f32),
|
||||
&[[[Some(col); 3]; 3]; 3],
|
||||
&[[[Rgba::from_opaque(col); 3]; 3]; 3],
|
||||
|origin, norm, col, ao, light| {
|
||||
SpriteVertex::new(
|
||||
origin,
|
||||
|
@ -160,10 +160,11 @@ impl<V: RectRasterableVol<Vox = Block> + ReadVol + Debug> Meshable<TerrainPipeli
|
||||
.ok()
|
||||
.filter(|vox| vox.is_opaque())
|
||||
.and_then(|vox| vox.get_color())
|
||||
.map(|col| col.map(|e| e as f32 / 255.0))
|
||||
.map(|col| Rgba::from_opaque(col))
|
||||
.unwrap_or(Rgba::zero())
|
||||
};
|
||||
|
||||
let mut colors = [[[None; 3]; 3]; 3];
|
||||
let mut colors = [[[Rgba::zero(); 3]; 3]; 3];
|
||||
for i in 0..3 {
|
||||
for j in 0..3 {
|
||||
for k in 0..3 {
|
||||
|
@ -10,8 +10,9 @@ use crate::render::{
|
||||
/// Given volume, position, and cardinal directions, compute each vertex's AO value.
|
||||
/// `dirs` should be a slice of length 5 so that the sliding window of size 2 over the slice
|
||||
/// yields each vertex' adjacent positions.
|
||||
#[allow(unsafe_code)]
|
||||
fn get_ao_quad<V: ReadVol>(
|
||||
vol: &V,
|
||||
_vol: &V,
|
||||
pos: Vec3<i32>,
|
||||
shift: Vec3<i32>,
|
||||
dirs: &[Vec3<i32>],
|
||||
@ -20,22 +21,40 @@ fn get_ao_quad<V: ReadVol>(
|
||||
) -> Vec4<(f32, f32)> {
|
||||
dirs.windows(2)
|
||||
.map(|offs| {
|
||||
let vox_opaque = |pos: Vec3<i32>| {
|
||||
let pos = (pos + 1).map(|e| e as usize);
|
||||
unsafe {
|
||||
darknesses
|
||||
.get_unchecked(pos.z)
|
||||
.get_unchecked(pos.y)
|
||||
.get_unchecked(pos.x)
|
||||
<= &0.0
|
||||
}
|
||||
};
|
||||
|
||||
let (s1, s2) = (
|
||||
vox_opaque(shift + offs[0]),
|
||||
vox_opaque(shift + offs[1]),
|
||||
/*
|
||||
vol.get(pos + shift + offs[0])
|
||||
.map(&is_opaque)
|
||||
.unwrap_or(false),
|
||||
vol.get(pos + shift + offs[1])
|
||||
.map(&is_opaque)
|
||||
.unwrap_or(false),
|
||||
*/
|
||||
);
|
||||
|
||||
let mut darkness = 0.0;
|
||||
for x in 0..2 {
|
||||
for y in 0..2 {
|
||||
let dark_pos = shift + offs[0] * x + offs[1] * y + 1;
|
||||
darkness += darknesses[dark_pos.z as usize][dark_pos.y as usize]
|
||||
[dark_pos.x as usize]
|
||||
/ 4.0;
|
||||
darkness += unsafe {
|
||||
darknesses
|
||||
.get_unchecked(dark_pos.z as usize)
|
||||
.get_unchecked(dark_pos.y as usize)
|
||||
.get_unchecked(dark_pos.x as usize)
|
||||
} / 4.0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,27 +85,29 @@ fn get_col_quad<V: ReadVol>(
|
||||
_pos: Vec3<i32>,
|
||||
_shift: Vec3<i32>,
|
||||
dirs: &[Vec3<i32>],
|
||||
cols: &[[[Option<Rgb<f32>>; 3]; 3]; 3],
|
||||
cols: &[[[Rgba<u8>; 3]; 3]; 3],
|
||||
_is_opaque: impl Fn(&V::Vox) -> bool,
|
||||
) -> Vec4<Rgb<f32>> {
|
||||
dirs.windows(2)
|
||||
.map(|offs| {
|
||||
let primary_col = cols[1][1][1].unwrap_or(Rgb::zero());
|
||||
let primary_col = Rgb::from(cols[1][1][1]).map(|e: u8| e as f32);
|
||||
let mut color = Rgb::zero();
|
||||
let mut total = 0.0;
|
||||
for x in 0..2 {
|
||||
for y in 0..2 {
|
||||
let col_pos = offs[0] * x + offs[1] * y + 1;
|
||||
if let Some(col) = unsafe {
|
||||
let col = unsafe {
|
||||
cols.get_unchecked(col_pos.z as usize)
|
||||
.get_unchecked(col_pos.y as usize)
|
||||
.get_unchecked(col_pos.x as usize)
|
||||
} {
|
||||
if Vec3::<f32>::from(primary_col).distance_squared(Vec3::from(*col))
|
||||
< 0.25 * 0.25
|
||||
};
|
||||
if col.a > 0 {
|
||||
let col = Rgb::new(col.r, col.g, col.b).map(|e| e as f32);
|
||||
if Vec3::<f32>::from(primary_col).distance_squared(Vec3::from(col))
|
||||
< (0.25f32 * 256.0).powf(2.0)
|
||||
{
|
||||
color += *col;
|
||||
total += 1.0;
|
||||
color += col;
|
||||
total += 256.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -148,7 +169,7 @@ pub fn push_vox_verts<V: ReadVol, P: Pipeline>(
|
||||
vol: &V,
|
||||
pos: Vec3<i32>,
|
||||
offs: Vec3<f32>,
|
||||
cols: &[[[Option<Rgb<f32>>; 3]; 3]; 3],
|
||||
cols: &[[[Rgba<u8>; 3]; 3]; 3],
|
||||
vcons: impl Fn(Vec3<f32>, Vec3<f32>, Rgb<f32>, f32, f32) -> P::Vertex,
|
||||
error_makes_face: bool,
|
||||
darknesses: &[[[f32; 3]; 3]; 3],
|
||||
|
Loading…
Reference in New Issue
Block a user