use lactea_abi::{RunConfig, ShaderInterface};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
pub enum Compat {
#[default]
ProjectM,
MilkDrop2,
MilkDrop3,
}
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct CompatRules {
pub vol_is_comma_bug: bool,
pub mip_y_from_width: bool,
pub c1_is_zero: bool,
pub decay_8bit: bool,
pub quantize_vertex_colors: bool,
pub hue_tint_always: bool,
pub thick_needs_512: bool,
pub pm_waveforms: bool,
pub shape_thick_full_pixel: bool,
pub mv_skip_first_frame: bool,
pub mv_min_len_px: f32,
pub mv_mirrored_lookup: bool,
pub comp_reads_previous: bool,
pub ang_seam_fix: bool,
pub comp_uv_half_texel: bool,
pub shader_warp_diffuse_is_decay: bool,
pub rot_translation_dropped: bool,
pub shade_top_first: bool,
pub blur_halfpixel_bias: bool,
pub blur_src_flipped: bool,
pub warp_diag_flipped: bool,
pub echo_diag_flipped: bool,
pub echo_quad_aspect: bool,
pub gamma_pass_eps: f32,
pub gl_strokes: bool,
pub wave_dots_smoothed: bool,
pub point_size_honored: bool,
pub wave_thick_ndc_inc: bool,
pub wave_point_f64_aspect: bool,
pub no_mipmaps: bool,
pub warp_uv_on_gpu: bool,
pub main_alpha: bool,
pub shape_main_nearest: bool,
pub blur_alloc_drops_overlays: bool,
pub gl_fill_ties: bool,
pub gl_varying_fold: bool,
pub d3d9_float_rules: bool,
pub pm_border_mesh: bool,
pub custom_slots: usize,
pub max_rand_slot: u8,
pub rand_filter_raw_name: bool,
pub noisevol_row_stride: bool,
pub warp_main_sampler_from_wrap: bool,
pub md2_preset_blend: bool,
pub md2_code_join: bool,
pub frame_vars_drive_post: bool,
pub shared_shader_rand: bool,
pub warp_anim_projectm: bool,
pub custom_shape_image: bool,
pub noshader_comp_wrap: bool,
pub md3_wave_modes: bool,
pub md2_wave_modes_9_17: bool,
pub max_shape_sides: i32,
pub md3_warp_skip_tiny: bool,
pub md3_border_gate: bool,
pub md3_auto_hard_cut: bool,
pub md3_preset_time_rand: bool,
pub md3_audio_analysis: bool,
pub md3_shader_fft: bool,
pub md3_extended_vars: bool,
pub md3_shader_prelude: bool,
pub md3_shader_time: bool,
pub shader_time_wrap: bool,
pub md3_md2_comp_effects: bool,
pub md3_ns_eel2: bool,
pub drop_failed_code: bool,
pub md3_double_preset: bool,
pub md3_blend_patterns: bool,
pub md3_preset_sprites: bool,
pub md3_gif_textures: bool,
pub md3_sprite_burn_twice: bool,
pub md2_shader_inputs: bool,
pub md2_input_vars: bool,
}
const MILKDROP2_RULES: CompatRules = CompatRules {
vol_is_comma_bug: true,
mip_y_from_width: true,
c1_is_zero: false,
decay_8bit: true,
quantize_vertex_colors: true,
hue_tint_always: false,
thick_needs_512: true,
pm_waveforms: false,
shape_thick_full_pixel: true,
mv_skip_first_frame: false,
mv_min_len_px: 1.0,
mv_mirrored_lookup: true,
comp_reads_previous: true,
ang_seam_fix: true,
comp_uv_half_texel: false,
shader_warp_diffuse_is_decay: false,
rot_translation_dropped: false,
shade_top_first: false,
blur_halfpixel_bias: true,
blur_src_flipped: false,
warp_diag_flipped: false,
echo_diag_flipped: false,
echo_quad_aspect: false,
gamma_pass_eps: 0.001,
gl_strokes: false,
wave_dots_smoothed: false,
point_size_honored: true,
wave_thick_ndc_inc: false,
wave_point_f64_aspect: false,
no_mipmaps: false,
warp_uv_on_gpu: false,
main_alpha: false,
shape_main_nearest: false,
blur_alloc_drops_overlays: false,
gl_fill_ties: false,
gl_varying_fold: false,
d3d9_float_rules: true,
pm_border_mesh: false,
custom_slots: 16,
max_rand_slot: 99,
rand_filter_raw_name: false,
noisevol_row_stride: false,
warp_main_sampler_from_wrap: false,
md2_preset_blend: true,
md2_code_join: true,
frame_vars_drive_post: true,
shared_shader_rand: true,
warp_anim_projectm: false,
custom_shape_image: false,
noshader_comp_wrap: true,
shader_time_wrap: false,
md3_wave_modes: false,
md2_wave_modes_9_17: true,
max_shape_sides: 100,
md3_warp_skip_tiny: false,
md3_border_gate: false,
md3_auto_hard_cut: false,
md3_preset_time_rand: false,
md3_audio_analysis: false,
md3_shader_fft: false,
md3_extended_vars: false,
md3_shader_prelude: false,
md3_shader_time: false,
md3_md2_comp_effects: false,
md3_ns_eel2: false,
drop_failed_code: true,
md3_double_preset: false,
md3_blend_patterns: false,
md3_preset_sprites: false,
md3_gif_textures: false,
md3_sprite_burn_twice: false,
md2_shader_inputs: true,
md2_input_vars: true,
};
impl Compat {
pub fn rules(self) -> CompatRules {
match self {
Compat::ProjectM => CompatRules {
vol_is_comma_bug: false,
mip_y_from_width: false,
c1_is_zero: true,
decay_8bit: false,
quantize_vertex_colors: false,
hue_tint_always: true,
thick_needs_512: false,
pm_waveforms: true,
shape_thick_full_pixel: false,
mv_skip_first_frame: true,
mv_min_len_px: 1.25,
mv_mirrored_lookup: false,
comp_reads_previous: false,
ang_seam_fix: false,
comp_uv_half_texel: true,
shader_warp_diffuse_is_decay: true,
rot_translation_dropped: true,
shade_top_first: true,
blur_halfpixel_bias: false,
blur_src_flipped: true,
warp_diag_flipped: true,
echo_diag_flipped: true,
echo_quad_aspect: true,
gamma_pass_eps: 0.0001,
gl_strokes: true,
wave_dots_smoothed: true,
point_size_honored: false,
wave_thick_ndc_inc: true,
wave_point_f64_aspect: true,
no_mipmaps: true,
warp_uv_on_gpu: true,
main_alpha: true,
shape_main_nearest: true,
blur_alloc_drops_overlays: true,
gl_fill_ties: true,
gl_varying_fold: true,
d3d9_float_rules: false,
pm_border_mesh: true,
custom_slots: 4,
max_rand_slot: 15,
rand_filter_raw_name: true,
noisevol_row_stride: true,
warp_main_sampler_from_wrap: true,
md2_preset_blend: false,
md2_code_join: false,
frame_vars_drive_post: false,
shared_shader_rand: false,
warp_anim_projectm: true,
custom_shape_image: true,
noshader_comp_wrap: false,
shader_time_wrap: true,
md2_wave_modes_9_17: false,
md2_shader_inputs: false,
md2_input_vars: false,
..MILKDROP2_RULES
},
Compat::MilkDrop2 => MILKDROP2_RULES,
Compat::MilkDrop3 => CompatRules {
md3_wave_modes: true,
md2_wave_modes_9_17: false,
max_shape_sides: 500,
md3_warp_skip_tiny: true,
md3_border_gate: true,
md3_auto_hard_cut: true,
md3_preset_time_rand: true,
md3_audio_analysis: true,
md3_shader_fft: true,
md3_extended_vars: true,
md3_shader_prelude: true,
md3_shader_time: true,
shader_time_wrap: true,
md3_md2_comp_effects: true,
md3_ns_eel2: true,
drop_failed_code: true,
md3_double_preset: true,
md3_blend_patterns: true,
md3_preset_sprites: true,
md3_gif_textures: true,
md3_sprite_burn_twice: true,
md2_shader_inputs: false,
md2_input_vars: false,
..MILKDROP2_RULES
},
}
}
pub fn md2_family(self) -> bool {
matches!(self, Compat::MilkDrop2 | Compat::MilkDrop3)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum StrokeRaster {
Native,
#[default]
Emulated,
Quads,
}
#[derive(Clone, Debug)]
pub struct RenderConfig {
pub width: u32,
pub height: u32,
pub mesh: [u32; 2],
pub texel_offset: [f32; 2],
pub output_format: wgpu::TextureFormat,
pub seed: u64,
pub compat: Compat,
pub stroke: StrokeRaster,
}
impl Default for RenderConfig {
fn default() -> Self {
Self::from_run(&RunConfig::default(), wgpu::TextureFormat::Rgba8Unorm)
}
}
impl RenderConfig {
pub fn from_run(run: &RunConfig, output_format: wgpu::TextureFormat) -> Self {
Self {
width: run.width,
height: run.height,
mesh: run.mesh,
texel_offset: run.texel_offset,
output_format,
seed: run.seed,
compat: Compat::default(),
stroke: StrokeRaster::default(),
}
}
}
#[derive(Clone, Debug)]
pub struct CompiledShader {
pub wgsl: String,
pub interface: ShaderInterface,
pub folds: Vec<String>,
}
#[derive(Debug)]
#[non_exhaustive]
pub enum RenderError {
Shader(String),
Invalid(String),
Readback(String),
}
impl std::fmt::Display for RenderError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
RenderError::Shader(s) => write!(f, "shader error: {s}"),
RenderError::Invalid(s) => write!(f, "invalid argument: {s}"),
RenderError::Readback(s) => write!(f, "readback error: {s}"),
}
}
}
impl std::error::Error for RenderError {}