Skip to content

Commit 697bc6c

Browse files
author
xasopheno
committed
smy
1 parent e2638e3 commit 697bc6c

7 files changed

Lines changed: 619 additions & 92 deletions

File tree

ast/src/wgsl/mod.rs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ pub enum VisualOp {
210210
direction: Option<(WgslValue, WgslValue, WgslValue)>,
211211
scale_mul: Option<WgslValue>,
212212
scale_add: Option<WgslValue>,
213+
/// Per-axis scale multipliers (Smx/Smy/Smz). Multiply on top of uniform scale.
214+
scale_x_mul: Option<WgslValue>,
215+
scale_y_mul: Option<WgslValue>,
216+
scale_z_mul: Option<WgslValue>,
213217
velocity_mul: Option<WgslValue>,
214218
velocity_add: Option<WgslValue>,
215219
/// Bend: (bend_vector_x, bend_vector_y, bend_vector_z, strength)
@@ -253,6 +257,9 @@ impl Default for VisualOp {
253257
direction: None,
254258
scale_mul: None,
255259
scale_add: None,
260+
scale_x_mul: None,
261+
scale_y_mul: None,
262+
scale_z_mul: None,
256263
velocity_mul: None,
257264
velocity_add: None,
258265
bend: None,
@@ -297,6 +304,10 @@ pub struct VisualPointOp {
297304
// Scalar modifiers
298305
pub scale_mul: Rational64,
299306
pub scale_add: Rational64,
307+
// Per-axis scale multipliers (multiply on top of uniform scale_mul)
308+
pub scale_x_mul: Rational64,
309+
pub scale_y_mul: Rational64,
310+
pub scale_z_mul: Rational64,
300311
pub velocity_mul: Rational64,
301312
pub velocity_add: Rational64,
302313
pub alpha_mul: Rational64,
@@ -321,6 +332,9 @@ impl Default for VisualPointOp {
321332
direction: None,
322333
scale_mul: Rational64::new(1, 1),
323334
scale_add: Rational64::new(0, 1),
335+
scale_x_mul: Rational64::new(1, 1),
336+
scale_y_mul: Rational64::new(1, 1),
337+
scale_z_mul: Rational64::new(1, 1),
324338
velocity_mul: Rational64::new(1, 1),
325339
velocity_add: Rational64::new(0, 1),
326340
alpha_mul: Rational64::new(1, 1),
@@ -346,6 +360,9 @@ impl Mul for VisualPointOp {
346360
y_mul: self.y_mul * other.y_mul,
347361
z_mul: self.z_mul * other.z_mul,
348362
scale_mul: self.scale_mul * other.scale_mul,
363+
scale_x_mul: self.scale_x_mul * other.scale_x_mul,
364+
scale_y_mul: self.scale_y_mul * other.scale_y_mul,
365+
scale_z_mul: self.scale_z_mul * other.scale_z_mul,
349366
velocity_mul: self.velocity_mul * other.velocity_mul,
350367
alpha_mul: self.alpha_mul * other.alpha_mul,
351368

@@ -550,6 +567,15 @@ impl VisualPointOp {
550567
if self.scale_add != Rational64::new(0, 1) {
551568
lines.push(format!(" scale = scale + {:.6};", rational_to_f32(self.scale_add)));
552569
}
570+
if self.scale_x_mul != Rational64::new(1, 1) {
571+
lines.push(format!(" scale_vec.x = scale_vec.x * {:.6};", rational_to_f32(self.scale_x_mul)));
572+
}
573+
if self.scale_y_mul != Rational64::new(1, 1) {
574+
lines.push(format!(" scale_vec.y = scale_vec.y * {:.6};", rational_to_f32(self.scale_y_mul)));
575+
}
576+
if self.scale_z_mul != Rational64::new(1, 1) {
577+
lines.push(format!(" scale_vec.z = scale_vec.z * {:.6};", rational_to_f32(self.scale_z_mul)));
578+
}
553579
if self.velocity_mul != Rational64::new(1, 1) {
554580
lines.push(format!(" velocity = velocity * {:.6};", rational_to_f32(self.velocity_mul)));
555581
}
@@ -628,6 +654,9 @@ impl VisualOp {
628654
direction,
629655
scale_mul,
630656
scale_add,
657+
scale_x_mul,
658+
scale_y_mul,
659+
scale_z_mul,
631660
velocity_mul,
632661
velocity_add,
633662
bend,
@@ -677,6 +706,9 @@ impl VisualOp {
677706
direction: dir,
678707
scale_mul: get_rational(scale_mul, one),
679708
scale_add: get_rational(scale_add, zero),
709+
scale_x_mul: get_rational(scale_x_mul, one),
710+
scale_y_mul: get_rational(scale_y_mul, one),
711+
scale_z_mul: get_rational(scale_z_mul, one),
680712
velocity_mul: get_rational(velocity_mul, one),
681713
velocity_add: get_rational(velocity_add, zero),
682714
alpha_mul: get_rational(alpha_mul, one),
@@ -752,6 +784,9 @@ impl VisualOp {
752784
direction,
753785
scale_mul,
754786
scale_add,
787+
scale_x_mul,
788+
scale_y_mul,
789+
scale_z_mul,
755790
velocity_mul,
756791
velocity_add,
757792
bend,
@@ -768,6 +803,9 @@ impl VisualOp {
768803
direction,
769804
scale_mul,
770805
scale_add,
806+
scale_x_mul,
807+
scale_y_mul,
808+
scale_z_mul,
771809
velocity_mul,
772810
velocity_add,
773811
bend,
@@ -831,6 +869,9 @@ impl VisualOp {
831869
direction: dir1,
832870
scale_mul: scale_mul1,
833871
scale_add: scale_add1,
872+
scale_x_mul: scale_x_mul1,
873+
scale_y_mul: scale_y_mul1,
874+
scale_z_mul: scale_z_mul1,
834875
velocity_mul: vel_mul1,
835876
velocity_add: vel_add1,
836877
bend: bend1,
@@ -851,6 +892,9 @@ impl VisualOp {
851892
direction: dir2,
852893
scale_mul: scale_mul2,
853894
scale_add: scale_add2,
895+
scale_x_mul: scale_x_mul2,
896+
scale_y_mul: scale_y_mul2,
897+
scale_z_mul: scale_z_mul2,
854898
velocity_mul: vel_mul2,
855899
velocity_add: vel_add2,
856900
bend: bend2,
@@ -872,6 +916,9 @@ impl VisualOp {
872916
direction: dir2.or(dir1), // Later wins
873917
scale_mul: compose_mul(scale_mul1, scale_mul2),
874918
scale_add: compose_add(scale_add1, scale_add2),
919+
scale_x_mul: compose_mul(scale_x_mul1, scale_x_mul2),
920+
scale_y_mul: compose_mul(scale_y_mul1, scale_y_mul2),
921+
scale_z_mul: compose_mul(scale_z_mul1, scale_z_mul2),
875922
velocity_mul: compose_mul(vel_mul1, vel_mul2),
876923
velocity_add: compose_add(vel_add1, vel_add2),
877924
bend: bend2.or(bend1), // Later wins
@@ -962,6 +1009,9 @@ impl VisualOp {
9621009
z_add,
9631010
scale_mul,
9641011
scale_add,
1012+
scale_x_mul,
1013+
scale_y_mul,
1014+
scale_z_mul,
9651015
velocity_mul,
9661016
velocity_add,
9671017
bend,
@@ -984,6 +1034,9 @@ impl VisualOp {
9841034
&& z_add.is_none()
9851035
&& scale_mul.is_none()
9861036
&& scale_add.is_none()
1037+
&& scale_x_mul.is_none()
1038+
&& scale_y_mul.is_none()
1039+
&& scale_z_mul.is_none()
9871040
&& velocity_mul.is_none()
9881041
&& velocity_add.is_none()
9891042
&& bend.is_none()
@@ -1111,6 +1164,15 @@ z += pos.z;"#,
11111164
if let Some(v) = scale_add {
11121165
lines.push(format!("scale = scale + {};", v.to_wgsl()));
11131166
}
1167+
if let Some(v) = scale_x_mul {
1168+
lines.push(format!("scale_vec.x = scale_vec.x * {};", v.to_wgsl()));
1169+
}
1170+
if let Some(v) = scale_y_mul {
1171+
lines.push(format!("scale_vec.y = scale_vec.y * {};", v.to_wgsl()));
1172+
}
1173+
if let Some(v) = scale_z_mul {
1174+
lines.push(format!("scale_vec.z = scale_vec.z * {};", v.to_wgsl()));
1175+
}
11141176
if let Some(v) = velocity_mul {
11151177
lines.push(format!("velocity = velocity * {};", v.to_wgsl()));
11161178
}
@@ -1261,6 +1323,9 @@ z += pos.z;"#,
12611323
direction: None,
12621324
scale_mul: None,
12631325
scale_add: None,
1326+
scale_x_mul: None,
1327+
scale_y_mul: None,
1328+
scale_z_mul: None,
12641329
velocity_mul: None,
12651330
velocity_add: None,
12661331
bend: None,
@@ -1345,6 +1410,30 @@ z += pos.z;"#,
13451410
op
13461411
}
13471412

1413+
pub fn smx(v: impl Into<WgslValue>) -> Self {
1414+
let mut op = Self::simple_default();
1415+
if let VisualOp::Simple { scale_x_mul: ref mut f, .. } = op {
1416+
*f = Some(v.into());
1417+
}
1418+
op
1419+
}
1420+
1421+
pub fn smy(v: impl Into<WgslValue>) -> Self {
1422+
let mut op = Self::simple_default();
1423+
if let VisualOp::Simple { scale_y_mul: ref mut f, .. } = op {
1424+
*f = Some(v.into());
1425+
}
1426+
op
1427+
}
1428+
1429+
pub fn smz(v: impl Into<WgslValue>) -> Self {
1430+
let mut op = Self::simple_default();
1431+
if let VisualOp::Simple { scale_z_mul: ref mut f, .. } = op {
1432+
*f = Some(v.into());
1433+
}
1434+
op
1435+
}
1436+
13481437
pub fn vm(v: impl Into<WgslValue>) -> Self {
13491438
let mut op = Self::simple_default();
13501439
if let VisualOp::Simple { velocity_mul: ref mut f, .. } = op {
@@ -1440,6 +1529,9 @@ z += pos.z;"#,
14401529
z_add,
14411530
scale_mul,
14421531
scale_add,
1532+
scale_x_mul,
1533+
scale_y_mul,
1534+
scale_z_mul,
14431535
velocity_mul,
14441536
velocity_add,
14451537
bend,
@@ -1540,6 +1632,15 @@ z += pos.z;"#,
15401632
if let Some(v) = scale_mul {
15411633
segment_ops.push(format!(" scale = scale * {};", v.to_wgsl()));
15421634
}
1635+
if let Some(v) = scale_x_mul {
1636+
segment_ops.push(format!(" scale_vec.x = scale_vec.x * {};", v.to_wgsl()));
1637+
}
1638+
if let Some(v) = scale_y_mul {
1639+
segment_ops.push(format!(" scale_vec.y = scale_vec.y * {};", v.to_wgsl()));
1640+
}
1641+
if let Some(v) = scale_z_mul {
1642+
segment_ops.push(format!(" scale_vec.z = scale_vec.z * {};", v.to_wgsl()));
1643+
}
15431644
if let Some(v) = velocity_mul {
15441645
segment_ops.push(format!(" velocity = velocity * {};", v.to_wgsl()));
15451646
}
@@ -1640,6 +1741,9 @@ z += pos.z;"#,
16401741
z_add,
16411742
scale_mul,
16421743
scale_add,
1744+
scale_x_mul,
1745+
scale_y_mul,
1746+
scale_z_mul,
16431747
velocity_mul,
16441748
velocity_add,
16451749
bend,
@@ -1785,6 +1889,15 @@ z += pos.z;"#,
17851889
if let Some(v) = scale_mul {
17861890
segment_ops.push(format!(" scale = scale * {};", v.to_wgsl()));
17871891
}
1892+
if let Some(v) = scale_x_mul {
1893+
segment_ops.push(format!(" scale_vec.x = scale_vec.x * {};", v.to_wgsl()));
1894+
}
1895+
if let Some(v) = scale_y_mul {
1896+
segment_ops.push(format!(" scale_vec.y = scale_vec.y * {};", v.to_wgsl()));
1897+
}
1898+
if let Some(v) = scale_z_mul {
1899+
segment_ops.push(format!(" scale_vec.z = scale_vec.z * {};", v.to_wgsl()));
1900+
}
17881901
if let Some(v) = velocity_mul {
17891902
segment_ops.push(format!(" velocity = velocity * {};", v.to_wgsl()));
17901903
}
@@ -2024,6 +2137,7 @@ fn dummy_function() {
20242137
var r: f32 = 0.01;
20252138
var life: f32 = 1.0;
20262139
var scale: f32 = 1.0;
2140+
var scale_vec: vec3<f32> = vec3<f32>(1.0, 1.0, 1.0); // Per-axis scale (Smx/Smy/Smz)
20272141
var time: f32 = 0.0;
20282142
var velocity: f32 = 1.0;
20292143
var seg_length: f32 = 1.0; // Duration multiplier for Seq segments

ast/src/wgsl_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var z: f32 = 0.0;
1616
var r: f32 = 0.0;
1717
var life: f32 = 1.0;
1818
var scale: f32 = 1.0;
19+
var scale_vec: vec3<f32> = vec3<f32>(1.0, 1.0, 1.0);
1920
var time: f32 = 0.0;
2021
2122
fn dummy_function() {

drums_solo_test.wav

0 Bytes
Binary file not shown.

parser/src/wgsl_dsl.lalrpop

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ BaseOp: VisualOp = {
7777
"Za" <v:WgslVal> => VisualOp::za(v),
7878
"Sm" <v:WgslVal> => VisualOp::sm(v),
7979
"Sa" <v:WgslVal> => VisualOp::sa(v),
80+
"Smx" <v:WgslVal> => VisualOp::smx(v),
81+
"Smy" <v:WgslVal> => VisualOp::smy(v),
82+
"Smz" <v:WgslVal> => VisualOp::smz(v),
8083
"Vm" <v:WgslVal> => VisualOp::vm(v),
8184
"Va" <v:WgslVal> => VisualOp::va(v),
8285
"Lm" <v:WgslVal> => VisualOp::lm(v),

parser/src/wgsl_dsl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ fn format_lalrpop_error<T: std::fmt::Debug>(e: &lalrpop_util::ParseError<usize,
271271
/// Check if a line starts with a DSL command
272272
fn starts_with_dsl_command(line: &str) -> bool {
273273
// Short commands need whitespace/comma check to avoid false matches
274-
let short_commands = ["Xm", "Xa", "Ym", "Ya", "Zm", "Za", "Sm", "Sa", "Vm", "Va", "Lm", "Am", "Rx", "Ry", "Rz"];
274+
let short_commands = ["Xm", "Xa", "Ym", "Ya", "Zm", "Za", "Smx", "Smy", "Smz", "Sm", "Sa", "Vm", "Va", "Lm", "Am", "Rx", "Ry", "Rz"];
275275
for cmd in &short_commands {
276276
if line.starts_with(cmd) {
277277
let rest = &line[cmd.len()..];

0 commit comments

Comments
 (0)