6 Commits

Author SHA1 Message Date
bspeice 7ff19631ba Merge pull request 'Add clippy, fix up warnings' (#7) from clippy into main
CI / cargo fmt (push) Successful in 25s
CI / cargo test (push) Successful in 12m39s
CI / cargo test (GPU) (push) Successful in 16m24s
Reviewed-on: #7
2026-07-12 15:50:24 -04:00
bspeice 9ea4261a84 Add clippy, fix up warnings
CI / cargo fmt (push) Successful in 23s
CI / cargo test (push) Successful in 12m44s
CI / cargo test (GPU) (push) Successful in 16m32s
2026-07-12 14:46:06 -04:00
bspeice 81f23c1bd8 Merge pull request 'Implement post-transform coefficients' (#6) from post_transform into main
CI / cargo fmt (push) Successful in 27s
CI / cargo test (push) Successful in 12m43s
CI / cargo test (GPU) (push) Successful in 12m25s
Reviewed-on: #6
2026-07-12 13:43:22 -04:00
bspeice 08ada94bd2 Implement post-transform coefficients
CI / cargo fmt (push) Successful in 1m25s
CI / cargo test (push) Successful in 14m59s
CI / cargo test (GPU) (push) Successful in 16m50s
2026-07-12 10:05:19 -04:00
bspeice 4005e14ab0 Merge pull request 'Include examples as part of cargo check' (#5) from ci_all_targets into main
CI / cargo fmt (push) Successful in 22s
CI / cargo test (push) Successful in 13m7s
CI / cargo test (GPU) (push) Successful in 12m35s
Reviewed-on: #5
2026-07-03 17:48:20 -04:00
bspeice 3bd01da563 Include examples as part of cargo check
CI / cargo fmt (push) Successful in 23s
CI / cargo test (push) Successful in 13m22s
CI / cargo test (GPU) (push) Successful in 12m35s
2026-07-03 16:23:11 -04:00
9 changed files with 93 additions and 38 deletions
+5 -2
View File
@@ -21,7 +21,10 @@ jobs:
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo check with:
components: clippy
- run: cargo check --all-targets
- run: cargo clippy --all-targets
- run: cargo test - run: cargo test
test-gpu: test-gpu:
@@ -30,5 +33,5 @@ jobs:
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo install --git https://github.com/rust-gpu/rust-gpu cargo-gpu - run: cargo install --git https://github.com/rust-gpu/rust-gpu cargo-gpu --rev 67f1ff2
- run: cargo gpu check --auto-install-rust-toolchain -p enkou-shaders - run: cargo gpu check --auto-install-rust-toolchain -p enkou-shaders
+3 -6
View File
@@ -19,15 +19,12 @@ mod test {
} }
fn has_entry_point(execution_model: ExecutionModel, name: &str) -> bool { fn has_entry_point(execution_model: ExecutionModel, name: &str) -> bool {
for ref entry_point in shader().entry_points.iter() { for entry_point in shader().entry_points.iter() {
let operands: Vec<Operand> = entry_point let operands: Vec<Operand> = entry_point
.operands .operands
.iter() .iter()
.filter(|op| match op { .filter(|op| matches!(op, Operand::ExecutionModel(_) | Operand::LiteralString(_)))
Operand::ExecutionModel(_) | Operand::LiteralString(_) => true, .cloned()
_ => false,
})
.map(|op| op.clone())
.collect(); .collect();
assert_eq!(operands.len(), 2); assert_eq!(operands.len(), 2);
+15 -16
View File
@@ -17,21 +17,21 @@ const IMAGE_DIMENSION: UVec2 = uvec2(600, 600);
pub fn main() -> Result<()> { pub fn main() -> Result<()> {
let transforms = [ let transforms = [
{
// F_0: (x / 2, y / 2) // F_0: (x / 2, y / 2)
Transform::new( let coefficients = Affine2::from_coefficients(0.5, 0.0, 0.0, 0.0, 0.5, 0.0);
Affine2::from_coefficients(0.5, 0.0, 0.0, 0.0, 0.5, 0.0), Transform::new(coefficients, Affine2::IDENTITY, uvec2(0, 1))
uvec2(0, 1), },
), {
// F_1: ((x + 1) / 2, y / 2) // F_1: ((x + 1) / 2, y / 2)
Transform::new( let coefficients = Affine2::from_coefficients(0.5, 0.0, 0.5, 0.0, 0.5, 0.0);
Affine2::from_coefficients(0.5, 0.0, 0.5, 0.0, 0.5, 0.0), Transform::new(coefficients, Affine2::IDENTITY, uvec2(0, 1))
uvec2(0, 1), },
), {
// F_2: (x / 2, (y + 1) / 2) // F_2: (x / 2, (y + 1) / 2)
Transform::new( let coefficients = Affine2::from_coefficients(0.5, 0.0, 0.0, 0.0, 0.5, 0.5);
Affine2::from_coefficients(0.5, 0.0, 0.0, 0.0, 0.5, 0.5), Transform::new(coefficients, Affine2::IDENTITY, uvec2(0, 1))
uvec2(0, 1), },
),
]; ];
let weights = [1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0]; let weights = [1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0];
@@ -78,10 +78,9 @@ pub fn main() -> Result<()> {
image.save(temp.path()).context("Unable to save image")?; image.save(temp.path()).context("Unable to save image")?;
let open_program: &str = cfg_select! { let open_program: &str = cfg_select! {
unix => Some("xdg-open"), unix => "xdg-open",
_ => None, _ => panic!("No available program to open images")
} };
.expect("No available program to open images");
Command::new(open_program) Command::new(open_program)
.arg(temp.path()) .arg(temp.path())
+2 -1
View File
@@ -1,6 +1,7 @@
//! # Enkou //! # Enkou
#![no_std] #![no_std]
#![warn(missing_docs)] #![deny(missing_docs)]
#![allow(clippy::needless_range_loop)] // SPIR-V backend has issues with iteration over items
pub mod camera; pub mod camera;
pub mod chaos_game; pub mod chaos_game;
+1 -1
View File
@@ -24,7 +24,7 @@ pub(crate) fn xoshiro256starstar_from_seed(
// - `u64::from_le_bytes` has issues with `OpBitcast` in SPIR-V validation // - `u64::from_le_bytes` has issues with `OpBitcast` in SPIR-V validation
for i in 0..rng_state_actual.len() { for i in 0..rng_state_actual.len() {
for j in 0..size_of::<u64>() { for j in 0..size_of::<u64>() {
rng_state_actual[i] |= (rng_state[i * size_of::<u64>() + j] as u64) << j * 8; rng_state_actual[i] |= (rng_state[i * size_of::<u64>() + j] as u64) << (j * 8);
} }
} }
+52 -3
View File
@@ -13,14 +13,16 @@ use rand::Rng;
#[repr(C)] #[repr(C)]
pub struct Transform { pub struct Transform {
coefficients: Affine2, coefficients: Affine2,
coefficients_post: Affine2,
variation_range: UVec2, variation_range: UVec2,
} }
impl Transform { impl Transform {
/// Create a new transform from an affine transformation matrix /// Create a new transform from an affine transformation matrix
pub fn new(coefficients: Affine2, variation_range: UVec2) -> Self { pub fn new(coefficients: Affine2, coefficients_post: Affine2, variation_range: UVec2) -> Self {
Transform { Transform {
coefficients, coefficients,
coefficients_post,
variation_range, variation_range,
} }
} }
@@ -39,10 +41,57 @@ impl Transform {
let variation_start = self.variation_range.x; let variation_start = self.variation_range.x;
let variation_end = self.variation_range.y; let variation_end = self.variation_range.y;
for variation_index in variation_start..variation_end { for variation_index in variation_start..variation_end {
let ref variation = variations[variation_index as usize]; let variation = &variations[variation_index as usize];
point_output += variation.transform_point(point, rng, &self.coefficients) point_output += variation.transform_point(point, rng, &self.coefficients)
} }
point_output self.coefficients_post.transform_point2(point)
}
}
#[cfg(test)]
mod test {
use crate::rng::xoshiro256starstar_from_seed;
use crate::transform::Transform;
use crate::variation::{Variation, VariationKind};
use glam::{Affine2, uvec2, vec2};
#[test]
fn transform_scaling() {
let scale_coefficients = vec2(2.0, 0.5);
let transform = Transform::new(
Affine2::from_scale(scale_coefficients),
Affine2::IDENTITY,
uvec2(0, 1),
);
let mut rng = xoshiro256starstar_from_seed([0; 32]);
let variations = [Variation::IDENTITY];
let point = vec2(1.0, 1.0);
assert_eq!(
transform.transform_point(&mut rng, &variations, point),
scale_coefficients
);
}
#[test]
fn transform_scaling_post() {
let scale_coefficients = vec2(2.0, 0.5);
let transform_pdj = Transform::new(Affine2::IDENTITY, Affine2::IDENTITY, uvec2(0, 1));
let transform_pdj_post = Transform::new(
Affine2::IDENTITY,
Affine2::from_scale(scale_coefficients),
uvec2(0, 1),
);
let mut rng = xoshiro256starstar_from_seed([0; 32]);
let variations = [Variation::new(VariationKind::Pdj, 1.0, [0.0f32; 4].into())];
let point = vec2(1.0, 1.0);
let point_pdj = transform_pdj.transform_point(&mut rng, &variations, point);
let point_pdj_post = transform_pdj_post.transform_point(&mut rng, &variations, point);
assert_eq!(point_pdj * scale_coefficients, point_pdj_post);
} }
} }
+6
View File
@@ -20,6 +20,12 @@ use rand::{Rng, RngExt};
#[repr(C)] #[repr(C)]
pub struct VariationParams([f32; 4]); pub struct VariationParams([f32; 4]);
impl From<[f32; 4]> for VariationParams {
fn from(v: [f32; 4]) -> Self {
VariationParams(v)
}
}
/// Enum for all supported variation types /// Enum for all supported variation types
/// ///
/// ID numbers are chosen to match the variation identifier also used by `flam3` /// ID numbers are chosen to match the variation identifier also used by `flam3`