pub fn procedural(shader: &str) -> bool {
shader.starts_with("Shapes/")
}
pub mod blend_mode {
pub const ZERO: u8 = 0;
pub const ONE: u8 = 1;
pub const DST_COLOR: u8 = 2;
pub const SRC_COLOR: u8 = 3;
pub const ONE_MINUS_DST_COLOR: u8 = 4;
pub const SRC_ALPHA: u8 = 5;
pub const ONE_MINUS_SRC_COLOR: u8 = 6;
pub const DST_ALPHA: u8 = 7;
pub const ONE_MINUS_DST_ALPHA: u8 = 8;
pub const SRC_ALPHA_SATURATE: u8 = 9;
pub const ONE_MINUS_SRC_ALPHA: u8 = 10;
pub const LAST: u8 = 10;
}
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
pub struct ShaderValue {
pub value: f32,
pub property: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub enum PassKind {
Normal,
Use(String),
Grab,
}
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
pub struct ShaderTargetBlend {
pub src: ShaderValue,
pub dst: ShaderValue,
pub src_alpha: ShaderValue,
pub dst_alpha: ShaderValue,
pub op: ShaderValue,
pub op_alpha: ShaderValue,
pub mask: ShaderValue,
}
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
pub struct ShaderStencilOp {
pub pass: ShaderValue,
pub fail: ShaderValue,
pub z_fail: ShaderValue,
pub comp: ShaderValue,
}
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
pub struct PassState {
pub targets: Vec<ShaderTargetBlend>,
pub separate_blend: bool,
pub z_test: ShaderValue,
pub offset_factor: ShaderValue,
pub offset_units: ShaderValue,
pub stencil_ref: ShaderValue,
pub stencil_read_mask: ShaderValue,
pub stencil_write_mask: ShaderValue,
pub stencil_op: ShaderStencilOp,
pub stencil_op_front: ShaderStencilOp,
pub stencil_op_back: ShaderStencilOp,
}
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
pub struct ShaderPass {
pub kind: PassKind,
pub light_mode: Option<String>,
pub src_blend: ShaderValue,
pub dst_blend: ShaderValue,
pub zwrite: ShaderValue,
pub cull: ShaderValue,
pub state: PassState,
}
#[derive(Clone, Debug, PartialEq, serde::Serialize)]
pub struct SubShader {
pub tags: Vec<(String, String)>,
pub passes: Vec<ShaderPass>,
}
#[cfg(test)]
mod tests {
use super::blend_mode::*;
#[test]
fn blend_modes_cover_unitys_eleven_values() {
let all = [
ZERO,
ONE,
DST_COLOR,
SRC_COLOR,
ONE_MINUS_DST_COLOR,
SRC_ALPHA,
ONE_MINUS_SRC_COLOR,
DST_ALPHA,
ONE_MINUS_DST_ALPHA,
SRC_ALPHA_SATURATE,
ONE_MINUS_SRC_ALPHA,
];
assert_eq!(all, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
assert_eq!(usize::from(LAST) + 1, all.len());
}
}