#[derive(Debug, Clone)]
pub struct ShaderMaterial {
pub fragment: String,
pub data: Vec<[f32; 4]>,
pub storage0: Vec<f32>,
pub storage1: Vec<f32>,
pub storage2: Vec<f32>,
pub opacity: f32,
pub transparent: bool,
pub side: u32,
}
impl Default for ShaderMaterial {
fn default() -> Self {
Self {
fragment: String::new(),
data: Vec::new(),
storage0: Vec::new(),
storage1: Vec::new(),
storage2: Vec::new(),
opacity: 1.0,
transparent: false,
side: 0,
}
}
}
impl ShaderMaterial {
pub fn new(fragment: impl Into<String>) -> Self {
Self {
fragment: fragment.into(),
..Default::default()
}
}
pub fn with_data(mut self, data: Vec<[f32; 4]>) -> Self {
self.data = data;
self
}
pub fn with_storage0(mut self, s: Vec<f32>) -> Self {
self.storage0 = s;
self
}
pub fn with_storage1(mut self, s: Vec<f32>) -> Self {
self.storage1 = s;
self
}
pub fn with_storage2(mut self, s: Vec<f32>) -> Self {
self.storage2 = s;
self
}
pub fn with_opacity(mut self, opacity: f32) -> Self {
self.opacity = opacity;
self
}
pub fn with_transparent(mut self, transparent: bool) -> Self {
self.transparent = transparent;
self
}
pub fn with_side(mut self, side: u32) -> Self {
self.side = side;
self
}
pub fn data_slots(&self) -> [[f32; 4]; 16] {
let mut out = [[0.0f32; 4]; 16];
for (i, v) in self.data.iter().take(16).enumerate() {
out[i] = *v;
}
out
}
}