Expand description
Derive macros for the RDPE particle simulation engine.
This crate provides three derive macros:
Particle- Generates GPU-compatible structs and WGSL codeParticleType- Creates type-safe enums for particle categoriesMultiParticle- Combines multiple Particle types into one simulation
§Usage
These macros are re-exported from the main rdpe crate. You don’t need
to add this crate directly:
ⓘ
use rdpe::prelude::*;
#[derive(Particle, Clone)]
struct Ball {
position: Vec3,
velocity: Vec3,
}
#[derive(ParticleType, Clone, Copy, PartialEq)]
enum Species {
Prey,
Predator,
}§The Particle Macro
#[derive(Particle)] transforms your Rust struct into a GPU-compatible
format. It generates:
- A companion
{Name}Gpustruct with proper alignment and padding - A
WGSL_STRUCTconstant containing the WGSL struct definition to_gpu()method for converting Rust → GPU format
§Required Fields
Every particle must have:
position: Vec3- Particle position in 3D spacevelocity: Vec3- Particle velocity
§Optional Fields
particle_type: u32- For typed interactions (auto-added if missing)#[color] color: Vec3- Custom particle color- Any
f32,u32,i32,Vec2,Vec3,Vec4fields
§GPU Memory Layout
The macro handles WGSL’s strict alignment requirements:
Vec3requires 16-byte alignment (even though it’s only 12 bytes)- Struct total size must be a multiple of 16 bytes
- Padding fields are automatically inserted
§The ParticleType Macro
#[derive(ParticleType)] enables type-safe particle categories for use
with typed rules like Chase, Evade, and Convert.
It generates:
From<EnumName> for u32- Convert enum to GPU-compatible integerFrom<u32> for EnumName- Convert back (defaults to first variant)EnumName::count() -> u32- Number of variants
Derive Macros§
- Multi
Particle - Derive macro for multi-particle enums with inline struct definitions.
- Particle
- Derive macro for particle structs.
- Particle
Type - Derive macro for particle type enums.