Skip to content

Commit 56774fd

Browse files
committed
rename f32::gl_sign() to f32::sign_gl()
1 parent fc3bf82 commit 56774fd

File tree

8 files changed

+38
-38
lines changed

8 files changed

+38
-38
lines changed

shaders/src/a_lot_of_spheres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl Inputs {
150150
// trace grid
151151
let mut pos: Vec3 = (ro / GRIDSIZE).floor() * GRIDSIZE;
152152
let ri: Vec3 = 1.0 / rd;
153-
let rs: Vec3 = rd.gl_sign() * GRIDSIZE;
153+
let rs: Vec3 = rd.sign_gl() * GRIDSIZE;
154154
let mut dis: Vec3 = (pos - ro + 0.5 * Vec3::splat(GRIDSIZE) + rs * 0.5) * ri;
155155
let mut mm: Vec3;
156156

shaders/src/a_question_of_time.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl Inputs {
203203

204204
// needles rotation
205205
let uvrh: Vec2 = uvr_rotate(
206-
(hash(Vec2::splat(uv_apo.z)) * d * 180.0).cos().gl_sign()
206+
(hash(Vec2::splat(uv_apo.z)) * d * 180.0).cos().sign_gl()
207207
* d
208208
* self.time
209209
* (1.0 / uv_apo.z * 10.0)
@@ -214,7 +214,7 @@ impl Inputs {
214214
let uvrm: Vec2 = uvr_rotate(
215215
(hash(Vec2::splat(uv_apo.z) * 4.0) * d * 180.0)
216216
.cos()
217-
.gl_sign()
217+
.sign_gl()
218218
* d
219219
* self.time
220220
* (1.0 / uv_apo.z * 120.0)
@@ -258,7 +258,7 @@ impl Inputs {
258258
let uvrg: Vec2 = uvr_rotate(
259259
(hash(Vec2::splat(uv_apo.z + 2.0)) * d * 180.0)
260260
.cos()
261-
.gl_sign()
261+
.sign_gl()
262262
* d
263263
* self.time
264264
* (1.0 / uv_apo.z * 20.0),

shaders/src/geodesic_tiling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn p_reflect(p: &mut Vec3, plane_normal: Vec3, offset: f32) -> f32 {
7272
if t < 0.0 {
7373
*p = *p - (2. * t) * plane_normal;
7474
}
75-
t.gl_sign()
75+
t.sign_gl()
7676
}
7777

7878
fn smax(a: f32, b: f32, r: f32) -> f32 {

shaders/src/raymarching_primitives.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn sd_hex_prism(mut p: Vec3, h: Vec2) -> f32 {
101101
p = p.abs();
102102
p = (p.xy() - 2.0 * k.xy().dot(p.xy()).min(0.0) * k.xy()).extend(p.z);
103103
let d: Vec2 = vec2(
104-
(p.xy() - vec2(p.x.clamp(-k.z * h.x, k.z * h.x), h.x)).length() * (p.y - h.x).gl_sign(),
104+
(p.xy() - vec2(p.x.clamp(-k.z * h.x, k.z * h.x), h.x)).length() * (p.y - h.x).sign_gl(),
105105
p.z - h.y,
106106
);
107107
d.x.max(d.y).min(0.0) + d.max(Vec2::ZERO).length()
@@ -119,7 +119,7 @@ fn sd_octogon_prism(mut p: Vec3, r: f32, h: f32) -> f32 {
119119
p = (p.xy() - 2.0 * vec2(-k.x, k.y).dot(p.xy()).min(0.0) * vec2(-k.x, k.y)).extend(p.z);
120120
// polygon side
121121
p = (p.xy() - vec2(p.x.clamp(-k.z * r, k.z * r), r)).extend(p.z);
122-
let d: Vec2 = vec2(p.xy().length() * p.y.gl_sign(), p.z - h);
122+
let d: Vec2 = vec2(p.xy().length() * p.y.sign_gl(), p.z - h);
123123
d.x.max(d.y).min(0.0) + d.max(Vec2::ZERO).length()
124124
}
125125

@@ -164,11 +164,11 @@ fn sd_round_cone(p: Vec3, a: Vec3, b: Vec3, r1: f32, r2: f32) -> f32 {
164164
let z2: f32 = z * z * l2;
165165

166166
// single square root!
167-
let k: f32 = rr.gl_sign() * rr * rr * x2;
168-
if z.gl_sign() * a2 * z2 > k {
167+
let k: f32 = rr.sign_gl() * rr * rr * x2;
168+
if z.sign_gl() * a2 * z2 > k {
169169
return (x2 + z2).sqrt() * il2 - r2;
170170
}
171-
if y.gl_sign() * a2 * y2 < k {
171+
if y.sign_gl() * a2 * y2 < k {
172172
return (x2 + y2).sqrt() * il2 - r1;
173173
}
174174
((x2 * a2 * il2).sqrt() + y * rr) * il2 - r1
@@ -184,7 +184,7 @@ fn sd_tri_prism(mut p: Vec3, mut h: Vec2) -> f32 {
184184
p = (vec2(p.x - k * p.y, -k * p.x - p.y) / 2.0).extend(p.z);
185185
}
186186
p.x -= p.x.clamp(-2.0, 0.0);
187-
let d1: f32 = p.xy().length() * (-p.y).gl_sign() * h.x;
187+
let d1: f32 = p.xy().length() * (-p.y).sign_gl() * h.x;
188188
let d2: f32 = p.z.abs() - h.y;
189189
vec2(d1, d2).max(Vec2::ZERO).length() + d1.max(d2).min(0.0)
190190
}
@@ -211,7 +211,7 @@ fn sd_cylinder(p: Vec3, a: Vec3, b: Vec3, r: f32) -> f32 {
211211
} else {
212212
(if x > 0.0 { x2 } else { 0.0 }) + if y > 0.0 { y2 } else { 0.0 }
213213
};
214-
d.gl_sign() * d.abs().sqrt() / baba
214+
d.sign_gl() * d.abs().sqrt() / baba
215215
}
216216

217217
// vertical
@@ -221,10 +221,10 @@ fn sd_cone(p: Vec3, c: Vec2, h: f32) -> f32 {
221221

222222
let a: Vec2 = w - q * (w.dot(q) / q.dot(q)).clamp(0.0, 1.0);
223223
let b: Vec2 = w - q * vec2((w.x / q.x).clamp(0.0, 1.0), 1.0);
224-
let k: f32 = q.y.gl_sign();
224+
let k: f32 = q.y.sign_gl();
225225
let d: f32 = a.dot(a).min(b.dot(b));
226226
let s: f32 = (k * (w.x * q.y - w.y * q.x)).max(k * (w.y - q.y));
227-
d.sqrt() * s.gl_sign()
227+
d.sqrt() * s.sign_gl()
228228
}
229229

230230
fn sd_capped_cone_vertical(p: Vec3, h: f32, r1: f32, r2: f32) -> f32 {
@@ -270,7 +270,7 @@ fn sd_solid_angle(pos: Vec3, c: Vec2, ra: f32) -> f32 {
270270
let p: Vec2 = vec2(pos.xz().length(), pos.y);
271271
let l: f32 = p.length() - ra;
272272
let m: f32 = (p - c * p.dot(c).clamp(0.0, ra)).length();
273-
l.max(m * (c.y * p.x - c.x * p.y).gl_sign())
273+
l.max(m * (c.y * p.x - c.x * p.y).sign_gl())
274274
}
275275

276276
fn sd_octahedron(mut p: Vec3, s: f32) -> f32 {
@@ -333,7 +333,7 @@ fn sd_pyramid(mut p: Vec3, h: f32) -> f32 {
333333
};
334334

335335
// recover 3D and scale, and add sign
336-
((d2 + q.z * q.z) / m2).sqrt() * q.z.max(-p.y).gl_sign()
336+
((d2 + q.z * q.z) / m2).sqrt() * q.z.max(-p.y).sign_gl()
337337
}
338338

339339
// la,lb=semi axis, h=height, ra=corner
@@ -343,7 +343,7 @@ fn sd_rhombus(mut p: Vec3, la: f32, lb: f32, h: f32, ra: f32) -> f32 {
343343
let f: f32 = (ndot(b, b - 2.0 * p.xz()) / b.dot(b)).clamp(-1.0, 1.0);
344344
let q: Vec2 = vec2(
345345
(p.xz() - 0.5 * b * vec2(1.0 - f, 1.0 + f)).length()
346-
* (p.x * b.y + p.z * b.x - b.x * b.y).gl_sign()
346+
* (p.x * b.y + p.z * b.x - b.x * b.y).sign_gl()
347347
- ra,
348348
p.y - h,
349349
);

shaders/src/skyline.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ impl<C0> State<C0> {
201201
.floor()
202202
* 0.1;
203203
let mut mask: f32 = saturate((ray_dir.y * 8.0 - skyline - 2.5 + height) * 24.0);
204-
let vert: f32 = (radial * 32.0).sin().gl_sign() * 0.5 + 0.5;
205-
let hor: f32 = (ray_dir.y * 256.0).sin().gl_sign() * 0.5 + 0.5;
204+
let vert: f32 = (radial * 32.0).sin().sign_gl() * 0.5 + 0.5;
205+
let hor: f32 = (ray_dir.y * 256.0).sin().sign_gl() * 0.5 + 0.5;
206206
mask = saturate(mask + (1.0 - hor * vert) * 0.05);
207207
final_color = mix(final_color * vec3(0.1, 0.07, 0.05), final_color, mask);
208208

@@ -366,7 +366,7 @@ fn city_block(p: Vec3, pint: Vec2) -> Vec2 {
366366
height + height2,
367367
(rand2.y - 0.5) * base_rad,
368368
);
369-
let big: f32 = box_pos.x.gl_sign();
369+
let big: f32 = box_pos.x.sign_gl();
370370
box_pos.x = box_pos.x.abs() - 0.02 - base_rad * 0.3 * rand.w;
371371
d = d.min(sd_box(
372372
box_pos,
@@ -425,8 +425,8 @@ impl<C0> State<C0> {
425425

426426
rep.z += p2.x.floor(); // shift so less repitition between parallel blocks
427427
rep.x = repeat(p2.x - 0.5, 1.0); // repeat every block
428-
rep.z = rep.z * rep.x.gl_sign(); // mirror but keep cars facing the right way
429-
rep.x = (rep.x * rep.x.gl_sign()) - 0.09;
428+
rep.z = rep.z * rep.x.sign_gl(); // mirror but keep cars facing the right way
429+
rep.x = (rep.x * rep.x.sign_gl()) - 0.09;
430430
rep.z -= car_time * cross_street; // make cars move
431431
let unique_id: f32 = (rep.z / repeat_dist).floor(); // each car gets a unique ID that we can use for colors
432432
rep.z = repeat(rep.z, repeat_dist); // repeat the line of cars every quarter block
@@ -955,7 +955,7 @@ impl<C0: SampleCube> State<C0> {
955955
final_color *= 0.9;
956956
// fog that fades to reddish plus the sun color so that fog is brightest towards sun
957957
let mut rv2: Vec3 = ray_vec;
958-
rv2.y *= saturate(rv2.y.gl_sign());
958+
rv2.y *= saturate(rv2.y.sign_gl());
959959
let mut fog_color: Vec3 = self.get_env_map(rv2, self.sun_dir);
960960
fog_color = Vec3::splat(9.0).min(fog_color);
961961
final_color = mix(fog_color, final_color, (-t * 0.02).exp());

shaders/src/tokyo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl State {
180180
let mut d: f32;
181181

182182
pd.x = pd.x.abs();
183-
pd.z *= -p.x.gl_sign();
183+
pd.z *= -p.x.sign_gl();
184184

185185
let ch: f32 = hash(((pd.z + 18.0 * self.time()) / 40.0).floor());
186186
let lh: f32 = hash((pd.z / 13.0).floor());
@@ -408,7 +408,7 @@ impl State {
408408

409409
let mut pd: Vec3 = pos;
410410
pd.x = pd.x.abs();
411-
pd.z *= -pos.x.gl_sign();
411+
pd.z *= -pos.x.sign_gl();
412412

413413
let ch: f32 = hash(((pd.z + 18. * self.time()) / 40.0).floor());
414414
let mut pdc: Vec3 = vec3(

shaders/src/voxel_pac_man.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl State {
165165
let mut ray_length: f32 = 0.0;
166166
let mut ray_length_in_voxel: f32 = 0.0;
167167
let mut ray_length_check_voxel: f32 = 0.0;
168-
let ray_sign: Vec3 = ray.gl_sign();
168+
let ray_sign: Vec3 = ray.sign_gl();
169169
let ray_delta_voxel: Vec3 = ray_sign / ray;
170170
for _ in 0..RAY_STEP_MAX {
171171
if ray_length < ray_length_in_voxel {

shared/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Clamp for f32 {
7575
pub trait FloatExt {
7676
fn fract_gl(self) -> Self;
7777
fn rem_euclid(self, rhs: Self) -> Self;
78-
fn gl_sign(self) -> Self;
78+
fn sign_gl(self) -> Self;
7979
fn step(self, x: Self) -> Self;
8080
}
8181

@@ -93,7 +93,7 @@ impl FloatExt for f32 {
9393
}
9494
}
9595

96-
fn gl_sign(self) -> f32 {
96+
fn sign_gl(self) -> f32 {
9797
if self < 0.0 {
9898
-1.0
9999
} else if self == 0.0 {
@@ -119,7 +119,7 @@ pub trait VecExt {
119119
fn sqrt(self) -> Self;
120120
fn ln(self) -> Self;
121121
fn step(self, other: Self) -> Self;
122-
fn gl_sign(self) -> Self;
122+
fn sign_gl(self) -> Self;
123123
}
124124

125125
impl VecExt for Vec2 {
@@ -147,8 +147,8 @@ impl VecExt for Vec2 {
147147
vec2(self.x.step(other.x), self.y.step(other.y))
148148
}
149149

150-
fn gl_sign(self) -> Vec2 {
151-
vec2(self.x.gl_sign(), self.y.gl_sign())
150+
fn sign_gl(self) -> Vec2 {
151+
vec2(self.x.sign_gl(), self.y.sign_gl())
152152
}
153153
}
154154

@@ -181,8 +181,8 @@ impl VecExt for Vec3 {
181181
)
182182
}
183183

184-
fn gl_sign(self) -> Vec3 {
185-
vec3(self.x.gl_sign(), self.y.gl_sign(), self.z.gl_sign())
184+
fn sign_gl(self) -> Vec3 {
185+
vec3(self.x.sign_gl(), self.y.sign_gl(), self.z.sign_gl())
186186
}
187187
}
188188

@@ -221,12 +221,12 @@ impl VecExt for Vec4 {
221221
)
222222
}
223223

224-
fn gl_sign(self) -> Vec4 {
224+
fn sign_gl(self) -> Vec4 {
225225
vec4(
226-
self.x.gl_sign(),
227-
self.y.gl_sign(),
228-
self.z.gl_sign(),
229-
self.w.gl_sign(),
226+
self.x.sign_gl(),
227+
self.y.sign_gl(),
228+
self.z.sign_gl(),
229+
self.w.sign_gl(),
230230
)
231231
}
232232
}

0 commit comments

Comments
 (0)