mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
add multisampling option to voxel graphics
Former-commit-id: d5ca47cd029226d1268c6d860516bfea6f9c5cf6
This commit is contained in:
parent
b99a8dea39
commit
aed6750885
@ -1,4 +1,4 @@
|
||||
use crate::ui::{BlankGraphic, ImageGraphic, VoxelGraphic};
|
||||
use crate::ui::img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic, VoxelMs9Graphic};
|
||||
|
||||
image_ids! {
|
||||
pub struct Imgs {
|
||||
@ -8,6 +8,8 @@ image_ids! {
|
||||
inv_grid: "/voxygen/element/frames/inv_grid.vox",
|
||||
inv_slot: "/voxygen/element/buttons/inv_slot.vox",
|
||||
|
||||
<VoxelMs9Graphic>
|
||||
|
||||
// Buttons
|
||||
mmap_closed: "/voxygen/element/buttons/button_mmap_closed.vox",
|
||||
mmap_closed_hover: "/voxygen/element/buttons/button_mmap_closed_hover.vox",
|
||||
@ -52,6 +54,8 @@ image_ids! {
|
||||
button_hover: "/voxygen/element/buttons/button_hover.vox",
|
||||
button_press: "/voxygen/element/buttons/button_press.vox",
|
||||
|
||||
<VoxelGraphic>
|
||||
|
||||
// MiniMap
|
||||
mmap_frame: "/voxygen/element/frames/mmap.vox",
|
||||
mmap_frame_closed: "/voxygen/element/frames/mmap_closed.vox",
|
||||
|
@ -7,7 +7,7 @@ use vek::*;
|
||||
|
||||
pub enum Graphic {
|
||||
Image(Arc<DynamicImage>),
|
||||
Voxel(Arc<DotVoxData>),
|
||||
Voxel(Arc<DotVoxData>, Option<u8>),
|
||||
Blank,
|
||||
}
|
||||
|
||||
@ -94,9 +94,8 @@ impl GraphicCache {
|
||||
.pixels()
|
||||
.map(|p| p.data)
|
||||
.collect::<Vec<[u8; 4]>>(),
|
||||
Graphic::Voxel(ref vox) => {
|
||||
super::renderer::draw_vox(&vox.as_ref().into(), aabr.size().into())
|
||||
}
|
||||
Graphic::Voxel(ref vox, min_samples) =>
|
||||
super::renderer::draw_vox(&vox.as_ref().into(), aabr.size().into(), *min_samples),
|
||||
Graphic::Blank => return None,
|
||||
};
|
||||
|
||||
|
@ -4,6 +4,7 @@ use common::{
|
||||
vol::{ReadVol, SizedVol, Vox},
|
||||
};
|
||||
use euc::{buffer::Buffer2d, rasterizer, Pipeline};
|
||||
use image::{DynamicImage, RgbaImage};
|
||||
use vek::*;
|
||||
|
||||
struct Voxel {
|
||||
@ -56,8 +57,13 @@ impl<'a> Pipeline for Voxel {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_vox(segment: &Segment, output_size: Vec2<u16>) -> Vec<[u8; 4]> {
|
||||
let dims = output_size.map(|e| e as usize).into_array();
|
||||
pub fn draw_vox(
|
||||
segment: &Segment,
|
||||
output_size: Vec2<u16>,
|
||||
min_samples: Option<u8>,
|
||||
) -> Vec<[u8; 4]> {
|
||||
let scale = min_samples.map_or(1.0, |s| s as f32).sqrt().ceil() as usize;
|
||||
let dims = output_size.map(|e| e as usize * scale).into_array();
|
||||
let mut color = Buffer2d::new(dims, [0; 4]);
|
||||
let mut depth = Buffer2d::new(dims, 1.0);
|
||||
|
||||
@ -79,8 +85,33 @@ pub fn draw_vox(segment: &Segment, output_size: Vec2<u16>) -> Vec<[u8; 4]> {
|
||||
&mut depth,
|
||||
);
|
||||
|
||||
// TODO: remove this clone
|
||||
color.as_ref().to_vec()
|
||||
if scale > 1 {
|
||||
DynamicImage::ImageRgba8(
|
||||
RgbaImage::from_vec(
|
||||
dims[0] as u32,
|
||||
dims[1] as u32,
|
||||
color
|
||||
.as_ref()
|
||||
.iter()
|
||||
.flatten()
|
||||
.cloned()
|
||||
.collect::<Vec<u8>>(),
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.resize_exact(
|
||||
output_size.x as u32,
|
||||
output_size.y as u32,
|
||||
image::FilterType::Triangle,
|
||||
)
|
||||
.to_rgba()
|
||||
.pixels()
|
||||
.map(|p| p.data)
|
||||
.collect::<Vec<[u8; 4]>>()
|
||||
} else {
|
||||
// TODO: remove clone
|
||||
color.as_ref().to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
fn ao_level(side1: bool, corner: bool, side2: bool) -> u8 {
|
||||
|
@ -3,9 +3,8 @@ use common::assets::{load, Error};
|
||||
use dot_vox::DotVoxData;
|
||||
use image::DynamicImage;
|
||||
|
||||
pub struct BlankGraphic;
|
||||
pub struct ImageGraphic;
|
||||
pub struct VoxelGraphic;
|
||||
pub enum BlankGraphic {}
|
||||
pub enum ImageGraphic {}
|
||||
|
||||
pub trait GraphicCreator<'a> {
|
||||
type Specifier;
|
||||
@ -23,10 +22,37 @@ impl<'a> GraphicCreator<'a> for ImageGraphic {
|
||||
Ok(Graphic::Image(load::<DynamicImage>(specifier)?))
|
||||
}
|
||||
}
|
||||
|
||||
pub enum VoxelGraphic {}
|
||||
pub enum VoxelMsGraphic {}
|
||||
pub enum VoxelMs4Graphic {}
|
||||
pub enum VoxelMs9Graphic {}
|
||||
|
||||
impl<'a> GraphicCreator<'a> for VoxelGraphic {
|
||||
type Specifier = &'a str;
|
||||
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
||||
Ok(Graphic::Voxel(load::<DotVoxData>(specifier)?))
|
||||
Ok(Graphic::Voxel(load::<DotVoxData>(specifier)?, None))
|
||||
}
|
||||
}
|
||||
impl<'a> GraphicCreator<'a> for VoxelMsGraphic {
|
||||
type Specifier = (&'a str, u8);
|
||||
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
||||
Ok(Graphic::Voxel(
|
||||
load::<DotVoxData>(specifier.0)?,
|
||||
Some(specifier.1),
|
||||
))
|
||||
}
|
||||
}
|
||||
impl<'a> GraphicCreator<'a> for VoxelMs4Graphic {
|
||||
type Specifier = &'a str;
|
||||
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
||||
Ok(Graphic::Voxel(load::<DotVoxData>(specifier)?, Some(4)))
|
||||
}
|
||||
}
|
||||
impl<'a> GraphicCreator<'a> for VoxelMs9Graphic {
|
||||
type Specifier = &'a str;
|
||||
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
||||
Ok(Graphic::Voxel(load::<DotVoxData>(specifier)?, Some(9)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +85,7 @@ macro_rules! image_ids {
|
||||
|
||||
impl $Ids {
|
||||
pub fn load(ui: &mut crate::ui::Ui) -> Result<Self, common::assets::Error> {
|
||||
use crate::ui::GraphicCreator;
|
||||
use crate::ui::img_ids::GraphicCreator;
|
||||
Ok(Self {
|
||||
$($( $name: ui.add_graphic(<$T>::new_graphic($specifier)?), )*)*
|
||||
})
|
||||
|
@ -5,13 +5,12 @@ mod scale;
|
||||
mod util;
|
||||
mod widgets;
|
||||
#[macro_use]
|
||||
mod img_ids;
|
||||
pub mod img_ids;
|
||||
#[macro_use]
|
||||
mod font_ids;
|
||||
|
||||
pub use event::Event;
|
||||
pub use graphic::Graphic;
|
||||
pub use img_ids::{BlankGraphic, GraphicCreator, ImageGraphic, VoxelGraphic};
|
||||
pub use scale::ScaleMode;
|
||||
pub use widgets::toggle_button::ToggleButton;
|
||||
|
||||
@ -315,8 +314,8 @@ impl Ui {
|
||||
srgb_to_linear(color.unwrap_or(conrod_core::color::WHITE).to_fsa().into());
|
||||
|
||||
let resolution = Vec2::new(
|
||||
(rect.w() * p_scale_factor) as u16,
|
||||
(rect.h() * p_scale_factor) as u16,
|
||||
(rect.w() * p_scale_factor).round() as u16,
|
||||
(rect.h() * p_scale_factor).round() as u16,
|
||||
);
|
||||
// Transform the source rectangle into uv coordinate
|
||||
// TODO: make sure this is right
|
||||
|
Loading…
Reference in New Issue
Block a user