Skip to content

Commit 107d3b4

Browse files
authored
Merge pull request #7 from DGriffin91/main
Update shared to use short vec functions
2 parents 4adb72d + 2aedd6b commit 107d3b4

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

shared/src/lib.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use core::f32::consts::PI;
99
use core::ops::{Add, Mul, Sub};
10-
use spirv_std::glam::{Vec2, Vec3, Vec4};
10+
use spirv_std::glam::{vec2, vec3, Vec2, Vec3, Vec4};
1111

1212
// Note: This cfg is incorrect on its surface, it really should be "are we compiling with std", but
1313
// we tie #[no_std] above to the same condition, so it's fine.
@@ -34,11 +34,11 @@ pub fn saturate(x: f32) -> f32 {
3434
}
3535

3636
pub fn pow(v: Vec3, power: f32) -> Vec3 {
37-
Vec3::new(v.x.powf(power), v.y.powf(power), v.z.powf(power))
37+
vec3(v.x.powf(power), v.y.powf(power), v.z.powf(power))
3838
}
3939

4040
pub fn exp(v: Vec3) -> Vec3 {
41-
Vec3::new(v.x.exp(), v.y.exp(), v.z.exp())
41+
vec3(v.x.exp(), v.y.exp(), v.z.exp())
4242
}
4343

4444
/// Based on: https://seblagarde.wordpress.com/2014/12/01/inverse-trigonometric-functions-gpu-optimization-for-amd-gcn-architecture/
@@ -151,35 +151,35 @@ fn step(edge: f32, x: f32) -> f32 {
151151

152152
impl VecExt for Vec2 {
153153
fn gl_fract(self) -> Vec2 {
154-
Vec2::new(self.x.gl_fract(), self.y.gl_fract())
154+
vec2(self.x.gl_fract(), self.y.gl_fract())
155155
}
156156

157157
fn sin(self) -> Vec2 {
158-
Vec2::new(self.x.sin(), self.y.sin())
158+
vec2(self.x.sin(), self.y.sin())
159159
}
160160

161161
fn cos(self) -> Vec2 {
162-
Vec2::new(self.x.cos(), self.y.cos())
162+
vec2(self.x.cos(), self.y.cos())
163163
}
164164

165165
fn powf_vec(self, p: Vec2) -> Vec2 {
166-
Vec2::new(self.x.powf(p.x), self.y.powf(p.y))
166+
vec2(self.x.powf(p.x), self.y.powf(p.y))
167167
}
168168

169169
fn sqrt(self) -> Vec2 {
170-
Vec2::new(self.x.sqrt(), self.y.sqrt())
170+
vec2(self.x.sqrt(), self.y.sqrt())
171171
}
172172

173173
fn ln(self) -> Vec2 {
174-
Vec2::new(self.x.ln(), self.y.ln())
174+
vec2(self.x.ln(), self.y.ln())
175175
}
176176

177177
fn rem_euclid(self, m: f32) -> Vec2 {
178-
Vec2::new(self.x.rem_euclid(m), self.y.rem_euclid(m))
178+
vec2(self.x.rem_euclid(m), self.y.rem_euclid(m))
179179
}
180180

181181
fn step(self, other: Vec2) -> Vec2 {
182-
Vec2::new(step(self.x, other.x), step(self.y, other.y))
182+
vec2(step(self.x, other.x), step(self.y, other.y))
183183
}
184184

185185
fn reflect(self, normal: Vec2) -> Vec2 {
@@ -191,45 +191,45 @@ impl VecExt for Vec2 {
191191
}
192192

193193
fn gl_sign(self) -> Vec2 {
194-
Vec2::new(self.x.gl_sign(), self.y.gl_sign())
194+
vec2(self.x.gl_sign(), self.y.gl_sign())
195195
}
196196
}
197197

198198
impl VecExt for Vec3 {
199199
fn gl_fract(self) -> Vec3 {
200-
Vec3::new(self.x.gl_fract(), self.y.gl_fract(), self.z.gl_fract())
200+
vec3(self.x.gl_fract(), self.y.gl_fract(), self.z.gl_fract())
201201
}
202202

203203
fn sin(self) -> Vec3 {
204-
Vec3::new(self.x.sin(), self.y.sin(), self.z.sin())
204+
vec3(self.x.sin(), self.y.sin(), self.z.sin())
205205
}
206206

207207
fn cos(self) -> Vec3 {
208-
Vec3::new(self.x.cos(), self.y.cos(), self.z.cos())
208+
vec3(self.x.cos(), self.y.cos(), self.z.cos())
209209
}
210210

211211
fn powf_vec(self, p: Vec3) -> Vec3 {
212-
Vec3::new(self.x.powf(p.x), self.y.powf(p.y), self.z.powf(p.z))
212+
vec3(self.x.powf(p.x), self.y.powf(p.y), self.z.powf(p.z))
213213
}
214214

215215
fn sqrt(self) -> Vec3 {
216-
Vec3::new(self.x.sqrt(), self.y.sqrt(), self.z.sqrt())
216+
vec3(self.x.sqrt(), self.y.sqrt(), self.z.sqrt())
217217
}
218218

219219
fn ln(self) -> Vec3 {
220-
Vec3::new(self.x.ln(), self.y.ln(), self.z.ln())
220+
vec3(self.x.ln(), self.y.ln(), self.z.ln())
221221
}
222222

223223
fn rem_euclid(self, m: f32) -> Vec3 {
224-
Vec3::new(
224+
vec3(
225225
self.x.rem_euclid(m),
226226
self.y.rem_euclid(m),
227227
self.z.rem_euclid(m),
228228
)
229229
}
230230

231231
fn step(self, other: Vec3) -> Vec3 {
232-
Vec3::new(
232+
vec3(
233233
step(self.x, other.x),
234234
step(self.y, other.y),
235235
step(self.z, other.z),
@@ -245,6 +245,6 @@ impl VecExt for Vec3 {
245245
}
246246

247247
fn gl_sign(self) -> Vec3 {
248-
Vec3::new(self.x.gl_sign(), self.y.gl_sign(), self.z.gl_sign())
248+
vec3(self.x.gl_sign(), self.y.gl_sign(), self.z.gl_sign())
249249
}
250250
}

0 commit comments

Comments
 (0)