Implement a basic Sierpinski Gasket IFS
CI / cargo fmt (push) Failing after 1m23s
CI / cargo test (push) Failing after 33s
CI / cargo test (GPU) (push) Successful in 20m4s

This commit is contained in:
2026-06-22 20:46:47 -04:00
parent 90f886f971
commit beb1c8526f
8 changed files with 1103 additions and 56 deletions
+3 -51
View File
@@ -3,12 +3,12 @@
#![warn(missing_docs)]
pub mod camera;
pub mod chaos_game;
pub mod transform;
use bytemuck::{Pod, Zeroable};
use core::f32::consts::PI;
use glam::{Affine2, Vec2, Vec3, Vec4, vec2, vec3};
use rand::distr::StandardUniform;
use rand::{Rng, RngExt};
use glam::{Affine2, Vec3, Vec4, vec2, vec3};
#[cfg(target_arch = "spirv")]
use spirv_std::num_traits::Float;
use spirv_std::spirv;
@@ -75,54 +75,6 @@ impl Coefficients2 for Affine2 {
}
}
#[derive(Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct Transform {
pub coefficients: Affine2,
}
impl Transform {
pub fn new(coefficients: Affine2) -> Self {
Transform { coefficients }
}
pub fn transform_point(&self, point: Vec2) -> Vec2 {
self.coefficients.transform_point2(point)
}
}
/// Iterate one step in the chaos game; choose the next transform, apply it,
/// and return the resulting point. Also returns the transform index so that
/// path-dependent weights (the "Xaos" table in Apophysis) can be chosen
/// for the next iteration step.
///
/// # Arguments
///
/// * `weights` - Weights are assumed to be normalized; adding all elements together should return the value 1
pub fn step_chaos_game<R: Rng>(
rng: &mut R,
point: Vec2,
weights: &[f32],
transforms: &[Transform],
) -> (Vec2, u32) {
let mut choice_weight = rng.sample::<f32, _>(StandardUniform);
let mut transform_index: u32 = 0;
for weight in weights {
choice_weight -= weight;
if choice_weight <= 0.0 {
break;
}
transform_index += 1;
}
(
transforms[transform_index as usize].transform_point(point),
transform_index,
)
}
#[derive(Copy, Clone, Pod, Zeroable)]
#[repr(C)]
pub struct ShaderConstants {