Expand description
wgpu backend reproducing the MilkDrop 2 frame pipeline; host-provided device, renders into any texture.
This crate is a port of MilkDrop 2’s CPlugin::RenderFrame (milkdropfs.cpp) and the texture /
noise setup of plugin.cpp. It knows nothing about presets, expressions, HLSL or audio: the
engine evaluates a preset’s equations, builds a FrameInput and calls
Renderer::render_frame.
Frame pipeline (all internal images Rgba8Unorm, never sRGB):
- motion vectors are drawn onto the previous image (MD2 order),
- warp pass
prev -> next(user warp shader, orWarpedBlit_NoShaders), - blur chain from the previous image, only up to the highest level a shader uses,
- custom shapes, custom waves, main wave, darken-center, borders on
next, - composite
next -> final(user comp shader on the 32x24 comp mesh, orShowToUser_NoShaders: video echo, gamma, brighten/darken/solarize/invert), - blit
finalto the host target (sRGB-compensated if needed).
With Compat::MilkDrop2 / Compat::MilkDrop3 the engine may hand over Md2Blend data (FrameInput::md2_blend): MilkDrop 2’s own
preset blend, where steps 2, 4 and 5 run once or twice (old and new shader, alpha-tiled) on a blended warp mesh.
Where MilkDrop 2 and projectM differ, Compat picks the behaviour (default projectM).
§Features
diagnostics(off by default): reference-comparison hooks (image injection, extra read-backs).
Re-exports§
pub use warp_mesh::MeshGeometry;pub use lactea_abi as abi;
Modules§
- noise
- Port of MD2’s procedural noise textures (plugin.cpp
AddNoiseTex/AddNoiseVol,fCubicInterpolate,dwCubicInterpolate). - uniforms
- Filling of
MilkUniformsexactly likeCPlugin::ApplyShaderParams(milkdropfs.cpp), including its quirks, plus the preset-level random state (CState::RandomizePresetVars). - warp_
mesh - Warp-mesh geometry and MD2’s per-vertex UV formula (milkdropfs.cpp
CPlugin::ComputeGridAlphaValues, vertex setup in plugin.cppAllocateMilkDropDX9). - wavegen
- Geometry generation for the main waveform (
CPlugin::DrawWave) and custom-wave helpers (DrawCustomWaves,SmoothWave). Pure functions: no GPU. - wavegen_
md3 - Main waveform of MilkDrop 3 (3.37): the 17 modes
0..=16(docs/md3.md, “Main waveform”).
Structs§
- Beat
Drop Texture - BeatDrop’s two shader textures, both
R32Fwith two rows (plugin.cpp,m_lpFFTTexture/m_lpWaveTexture, refilled every frame byDoCustomSoundAnalysis):sampler_fftisBEATDROP_FFT_BINSx 2 (row 0 the smoothed spectrum, row 1 the peak hold) andsampler_waveBEATDROP_WAVE_SAMPLESx 2 (row 0 left, row 1 right, the waveform divided by 128). The renderer keeps them as two textures of their own. - Blur
Params - Blur-chain parameters (
var_pf_blur*). - Borders
- Outer/inner border:
var_pf_ob_*/var_pf_ib_*. - Compat
Rules - The individual behaviours selected by a
Compatvalue (see the table there for the projectM / MilkDrop 2 values of each). - Compiled
Shader - A warp or composite shader: WGSL module source (starting with
lactea_abi::WGSL_COMMON, entryfs_main) plus the resource interface the renderer binds in group 1. - Custom
Wave - One evaluated custom wave (
CWave).points.len()is thesamplesactually produced (<= 512). Spectrum /sep/ smoothing / scaling are the engine’s job (seecrate::wavegen::custom_wave_values_into). - Frame
Input - Per-frame values after per-frame equations.
- Main
Wave - Main waveform (
DrawWaveinputs). - Md2Blend
- Everything the renderer needs to draw a blend frame, on top of the new state’s
crate::FrameInput(whose per-frame values are already the blendedm_pState->var_pf_*). - Md2Old
Pass - What the old state contributes to the shader passes of a blend frame (its
ApplyShaderParams(.., m_pOldState)inputs that differ from the new state’s:q1..q32, blur range,rand_preset/rot_*). - Motion
Vectors - Motion vector field:
var_pf_mv_x/y/dx/dy/l/r/g/b/a. - Pass
Random - Per-shader-pass random state. projectM gives the warp and the composite shader independent
rand_preset/rand_frame/rot_*streams (MD2 shares one set per preset); the engine supplies them here. AnyNonefalls back to the renderer’s own state. - Post
Params - Decay, composite-pass controls.
- Render
Config - Renderer construction parameters.
- Renderer
- The MilkDrop 2 frame renderer. See the crate docs for the pass order.
- Rng
- The renderer’s deterministic generator (SplitMix64).
- Shader
Ext - See the module docs. One per shader pass owner:
crate::FrameInput::extfor the state the frame is built for,crate::Md2OldPass::extfor the outgoing state of a MilkDrop 2 / 3 blend. - Shape
Image - The texture of a shape’s
image=key, already split like projectM’sExtractTextureSettings(fw_/fc_/pw_/pc_prefixes pick filter and wrapping; no prefix = linear + repeat). - Shape
Instance - One evaluated custom-shape instance (
CShapeafter per-frame code for that instance). - Sprite
Draw - One sprite draw handed to the renderer in
FrameInput::sprites. - Sprite
Vertex - One corner of a sprite quad.
- Transition
Blender - The six transition pipelines and the bilinear / clamp sampler (
m_presetSampler). - Transition
Params - Per-frame inputs of a transition draw (
PresetTransition::Draw). - WarpGpu
- See
FrameInput::warp_gpu. - Wave
Point - One evaluated custom-wave point (
var_pp_x/y/r/g/b/aafter per-point code).x/yare the VM’sf64: projectM turns them into clip space asstatic_cast<float>((x * 2.0 - 1.0) * invAspectX), i.e. the product is also taken in double (MD2:(float)(x * 2 - 1) * invAspectX, seeCompatRules::wave_point_f64_aspect).
Enums§
- Compat
- Which reference behaviour the renderer follows where MilkDrop 2 (
third_party/md2) and projectM differ. Default: projectM. - Render
Error - Errors reported by the renderer.
- Stroke
Raster - How 1-pixel lines and points (custom/main waves, shape outlines, motion vectors) are rasterised.
- Transition
Kind - The six built-in transition shaders, in projectM’s
TransitionShaderManagerorder.
Constants§
- BEATDROP_
FFT_ BINS - Texels per row of BeatDrop’s
sampler_fft(MY_FFT_SHADER_SAMPLES); equalslactea_audio::SHADER_FFT_BINS. - BEATDROP_
WAVE_ SAMPLES - Texels per row of BeatDrop’s
sampler_wave(NUM_WAVEFORM_SAMPLES); equalslactea_audio::SHADER_WAVE_SAMPLES. - SPRITE_
MODES - Number of blend modes (
0..=10).
Functions§
- cosine_
interp CosineInterp(vis_milk2utility.h, not part ofthird_party/md2):0.5 - 0.5 cos(pi x). Used for the blend of the per-frame variables, the wave blend and the video-echo flip.- gif_
frame_ index - GIF frame choice (MD3 3.37):
t = fmod(time, sum(delays)), the first frame whose cumulative delay is strictly greater thant, else the last. One frame, no delays or a non-positive total always give frame 0.delaysare in seconds and already follow the “<= 0means 0.1 s” rule. - mix64
- The SplitMix64 output mixer: a bijective scramble of
z, usable on its own to hash a value into 64 random bits. - readback_
rgba8 - Read an
Rgba8Unorm-sized (4 bytes per texel)wxhtexture back as tightly packed RGBA8 (row 0 = top). Submits its own copy and waits for it, so the frame’s command buffers must have been submitted. - sprite_
blend_ reference - CPU model of the table: result of drawing a texel
texel(straight alpha) over the destination colourdstwith a sprite of colourrgbainmode, in0..=255units (not rounded). It follows the table, not the shader: stage colourC/ alphaA, thenout = C * SRC + D * DESTwith the mode’s factors. - sprite_
mode - The mode a
blendvalue selects (0for anything outside0..=10). - sprite_
vertex_ color - The vertex colour
(r, g, b, a)of a sprite inmode, after the byte quantisation ofD3DCOLOR.