Skip to main content

Crate lactea_render

Crate lactea_render 

Source
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):

  1. motion vectors are drawn onto the previous image (MD2 order),
  2. warp pass prev -> next (user warp shader, or WarpedBlit_NoShaders),
  3. blur chain from the previous image, only up to the highest level a shader uses,
  4. custom shapes, custom waves, main wave, darken-center, borders on next,
  5. composite next -> final (user comp shader on the 32x24 comp mesh, or ShowToUser_NoShaders: video echo, gamma, brighten/darken/solarize/invert),
  6. blit final to 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 MilkUniforms exactly like CPlugin::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.cpp AllocateMilkDropDX9).
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§

BeatDropTexture
BeatDrop’s two shader textures, both R32F with two rows (plugin.cpp, m_lpFFTTexture / m_lpWaveTexture, refilled every frame by DoCustomSoundAnalysis): sampler_fft is BEATDROP_FFT_BINS x 2 (row 0 the smoothed spectrum, row 1 the peak hold) and sampler_wave BEATDROP_WAVE_SAMPLES x 2 (row 0 left, row 1 right, the waveform divided by 128). The renderer keeps them as two textures of their own.
BlurParams
Blur-chain parameters (var_pf_blur*).
Borders
Outer/inner border: var_pf_ob_* / var_pf_ib_*.
CompatRules
The individual behaviours selected by a Compat value (see the table there for the projectM / MilkDrop 2 values of each).
CompiledShader
A warp or composite shader: WGSL module source (starting with lactea_abi::WGSL_COMMON, entry fs_main) plus the resource interface the renderer binds in group 1.
CustomWave
One evaluated custom wave (CWave). points.len() is the samples actually produced (<= 512). Spectrum / sep / smoothing / scaling are the engine’s job (see crate::wavegen::custom_wave_values_into).
FrameInput
Per-frame values after per-frame equations.
MainWave
Main waveform (DrawWave inputs).
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 blended m_pState->var_pf_*).
Md2OldPass
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_*).
MotionVectors
Motion vector field: var_pf_mv_x/y/dx/dy/l/r/g/b/a.
PassRandom
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. Any None falls back to the renderer’s own state.
PostParams
Decay, composite-pass controls.
RenderConfig
Renderer construction parameters.
Renderer
The MilkDrop 2 frame renderer. See the crate docs for the pass order.
Rng
The renderer’s deterministic generator (SplitMix64).
ShaderExt
See the module docs. One per shader pass owner: crate::FrameInput::ext for the state the frame is built for, crate::Md2OldPass::ext for the outgoing state of a MilkDrop 2 / 3 blend.
ShapeImage
The texture of a shape’s image= key, already split like projectM’s ExtractTextureSettings (fw_ / fc_ / pw_ / pc_ prefixes pick filter and wrapping; no prefix = linear + repeat).
ShapeInstance
One evaluated custom-shape instance (CShape after per-frame code for that instance).
SpriteDraw
One sprite draw handed to the renderer in FrameInput::sprites.
SpriteVertex
One corner of a sprite quad.
TransitionBlender
The six transition pipelines and the bilinear / clamp sampler (m_presetSampler).
TransitionParams
Per-frame inputs of a transition draw (PresetTransition::Draw).
WarpGpu
See FrameInput::warp_gpu.
WavePoint
One evaluated custom-wave point (var_pp_x/y/r/g/b/a after per-point code). x / y are the VM’s f64: projectM turns them into clip space as static_cast<float>((x * 2.0 - 1.0) * invAspectX), i.e. the product is also taken in double (MD2: (float)(x * 2 - 1) * invAspectX, see CompatRules::wave_point_f64_aspect).

Enums§

Compat
Which reference behaviour the renderer follows where MilkDrop 2 (third_party/md2) and projectM differ. Default: projectM.
RenderError
Errors reported by the renderer.
StrokeRaster
How 1-pixel lines and points (custom/main waves, shape outlines, motion vectors) are rasterised.
TransitionKind
The six built-in transition shaders, in projectM’s TransitionShaderManager order.

Constants§

BEATDROP_FFT_BINS
Texels per row of BeatDrop’s sampler_fft (MY_FFT_SHADER_SAMPLES); equals lactea_audio::SHADER_FFT_BINS.
BEATDROP_WAVE_SAMPLES
Texels per row of BeatDrop’s sampler_wave (NUM_WAVEFORM_SAMPLES); equals lactea_audio::SHADER_WAVE_SAMPLES.
SPRITE_MODES
Number of blend modes (0..=10).

Functions§

cosine_interp
CosineInterp (vis_milk2 utility.h, not part of third_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 than t, else the last. One frame, no delays or a non-positive total always give frame 0. delays are in seconds and already follow the “<= 0 means 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) w x h texture 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. Always an error on the web ([SYNC_READBACK]).
sprite_blend_reference
CPU model of the table: result of drawing a texel texel (straight alpha) over the destination colour dst with a sprite of colour rgba in mode, in 0..=255 units (not rounded). It follows the table, not the shader: stage colour C / alpha A, then out = C * SRC + D * DEST with the mode’s factors.
sprite_mode
The mode a blend value selects (0 for anything outside 0..=10).
sprite_vertex_color
The vertex colour (r, g, b, a) of a sprite in mode, after the byte quantisation of D3DCOLOR.