From 70185eeb2c9b7ce17032dbbbed476213fcc22710 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 27 Feb 2024 10:00:03 -0800 Subject: [PATCH] Fix invalid WGSL for large `u32` values (#284) --- CHANGELOG.md | 2 ++ src/graph/expr.rs | 4 ++-- src/lib.rs | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf6ca9b0..ac80368d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added a new `ScreenSpaceSizeModifier` which negates the effect of perspective projection, and makes the particle's size a pixel size in screen space, instead of a Bevy world unit size. This replaces the hard-coded behavior previously available on the `SetSizeModifier`. - Added a new `ConformToSphereModifier` acting as an attractor applying a force toward a point (sphere center) to all particles in range, and making particles conform ("stick") to the sphere surface. +- Added `vec2` and `vec3` functions that allow construction of vectors from dynamic parts. ### Changed @@ -23,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed a panic in rendering randomly occurring when no effect is present. +- Fixed invalid WGSL being generated for large `u32` values. ## [0.10.0] 2024-02-24 diff --git a/src/graph/expr.rs b/src/graph/expr.rs index b1a8dec2..e17eed7d 100644 --- a/src/graph/expr.rs +++ b/src/graph/expr.rs @@ -3425,8 +3425,8 @@ mod tests { (sign, "sign", "vec3(1.,-3.1,6.99)"), (sin, "sin", "vec3(1.,-3.1,6.99)"), (tan, "tan", "vec3(1.,-3.1,6.99)"), - (unpack4x8snorm, "unpack4x8snorm", "0"), - (unpack4x8unorm, "unpack4x8unorm", "0"), + (unpack4x8snorm, "unpack4x8snorm", "0u"), + (unpack4x8unorm, "unpack4x8unorm", "0u"), ] { let expr = ctx.eval(&m, expr); assert!(expr.is_ok()); diff --git a/src/lib.rs b/src/lib.rs index 417e995a..b0f8a186 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -396,7 +396,7 @@ impl ToWgslString for IVec4 { impl ToWgslString for u32 { fn to_wgsl_string(&self) -> String { - format!("{}", self) + format!("{}u", self) } } @@ -1532,11 +1532,11 @@ mod tests { #[test] fn to_wgsl_uvec() { let s = UVec2::new(1, 2).to_wgsl_string(); - assert_eq!(s, "vec2(1,2)"); + assert_eq!(s, "vec2(1u,2u)"); let s = UVec3::new(1, 2, 42).to_wgsl_string(); - assert_eq!(s, "vec3(1,2,42)"); + assert_eq!(s, "vec3(1u,2u,42u)"); let s = UVec4::new(1, 2, 42, 5).to_wgsl_string(); - assert_eq!(s, "vec4(1,2,42,5)"); + assert_eq!(s, "vec4(1u,2u,42u,5u)"); } #[test]