Skip to content

Commit fc3bf82

Browse files
committed
rename f32::gl_fract() to f32::fract_gl() to match glam
1 parent 44017f2 commit fc3bf82

12 files changed

+48
-48
lines changed

shaders/src/a_lot_of_spheres.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const SPEED: f32 = 0.5;
4343

4444
const _MR: Mat2 = mat2(vec2(0.84147, 0.54030), vec2(0.54030, -0.84147));
4545
fn hash(n: f32) -> f32 {
46-
(n.sin() * 43758.5453).gl_fract()
46+
(n.sin() * 43758.5453).fract_gl()
4747
}
4848
fn _hash2(n: f32) -> Vec2 {
4949
(vec2(n, n + 1.0).sin() * vec2(2.1459123, 3.3490423)).fract_gl()
@@ -105,7 +105,7 @@ impl Inputs {
105105
fn get_moving_sphere_position(&self, grid: Vec2, sphere_offset: Vec2, center: &mut Vec3) {
106106
// falling?
107107
let s: f32 = 0.1 + hash(grid.x * 1.23114 + 5.342 + 74.324231 * grid.y);
108-
let t: f32 = (14. * s + self.time / s * 0.3).gl_fract();
108+
let t: f32 = (14. * s + self.time / s * 0.3).fract_gl();
109109

110110
let y: f32 = s * MAXHEIGHT * (4.0 * t * (1. - t)).abs();
111111
let offset: Vec2 = grid + sphere_offset;

shaders/src/a_question_of_time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn inversion(uv: Vec2, r: f32) -> Vec2 {
7474
}
7575
// seeded random number
7676
fn hash(s: Vec2) -> f32 {
77-
((s.dot(vec2(12.9898, 78.2333))).sin() * 43758.5453123).gl_fract()
77+
((s.dot(vec2(12.9898, 78.2333))).sin() * 43758.5453123).fract_gl()
7878
}
7979

8080
// this is an algorithm to construct an apollonian packing with a descartes configuration

shaders/src/filtering_procedurals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn mytexture(mut p: Vec3, _n: Vec3, matid: f32) -> Vec3 {
217217
let ip: Vec3 = (p / 20.0).floor();
218218
let fp: Vec3 = (Vec3::splat(0.5) + p / 20.0).fract_gl();
219219

220-
let mut id: f32 = ((ip.dot(vec3(127.1, 311.7, 74.7))).sin() * 58.5453123).gl_fract();
220+
let mut id: f32 = ((ip.dot(vec3(127.1, 311.7, 74.7))).sin() * 58.5453123).fract_gl();
221221
id = mix(id, 0.3, matid);
222222

223223
let f: f32 = (ip.x + (ip.y + ip.z.rem_euclid(2.0)).rem_euclid(2.0)).rem_euclid(2.0);

shaders/src/geodesic_tiling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ impl State {
414414
}
415415
let t: f32 = self.time / SCENE_DURATION;
416416
let scene: f32 = t.rem_euclid(3.0).floor();
417-
let mut blend: f32 = t.gl_fract();
417+
let mut blend: f32 = t.fract_gl();
418418
let delay: f32 = (SCENE_DURATION - CROSSFADE_DURATION) / SCENE_DURATION;
419419
blend = (blend - delay).max(0.0) / (1.0 - delay);
420420
blend = sine_in_out(blend);

shaders/src/luminescence.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const ACCENT_COLOR2: Vec3 = vec3(1.0, 0.5, 0.1);
8787
const SECOND_COLOR2: Vec3 = vec3(0.1, 0.5, 0.6);
8888

8989
fn _n1(x: f32) -> f32 {
90-
(x.sin() * 5346.1764).gl_fract()
90+
(x.sin() * 5346.1764).fract_gl()
9191
}
9292
fn _n2(x: f32, y: f32) -> f32 {
9393
_n1(x + y * 23414.324)
@@ -96,7 +96,7 @@ fn _n2(x: f32, y: f32) -> f32 {
9696
fn n3(mut p: Vec3) -> f32 {
9797
p = (p * 0.3183099 + Vec3::splat(0.1)).fract_gl();
9898
p *= 17.0;
99-
(p.x * p.y * p.z * (p.x + p.y + p.z)).gl_fract()
99+
(p.x * p.y * p.z * (p.x + p.y + p.z)).fract_gl()
100100
}
101101

102102
#[derive(Clone, Copy, Default)]
@@ -452,7 +452,7 @@ impl State {
452452

453453
let mut s2: f32 = 5. * p.x / TWO_PI;
454454
let _id: f32 = s2.floor();
455-
s2 = s2.gl_fract();
455+
s2 = s2.fract_gl();
456456
let ep: Vec2 = vec2(s2 - 0.5, p.y - 0.6);
457457
let ed: f32 = ep.length();
458458
let e: f32 = b(0.35, 0.45, 0.05, ed);

shaders/src/on_off_spikes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ const PIH: f32 = 1.5707963267949;
7373
const _PI: f32 = 3.1415927;
7474
const NUM_OCTAVES: i32 = 4;
7575
fn hash(n: f32) -> f32 {
76-
(n.sin() * 1e4).gl_fract()
76+
(n.sin() * 1e4).fract_gl()
7777
}
7878
fn hash_vec2(p: Vec2) -> f32 {
79-
(1e4 * (17.0 * p.x + p.y * 0.1).sin() * (0.1 + (p.y * 13.0 + p.x).sin().abs())).gl_fract()
79+
(1e4 * (17.0 * p.x + p.y * 0.1).sin() * (0.1 + (p.y * 13.0 + p.x).sin().abs())).fract_gl()
8080
}
8181
fn noise(x: f32) -> f32 {
8282
let i: f32 = x.floor();
83-
let f: f32 = x.gl_fract();
83+
let f: f32 = x.fract_gl();
8484
let u: f32 = f * f * (3.0 - 2.0 * f);
8585
mix(hash(i), hash(i + 1.0), u)
8686
}

shaders/src/seascape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn from_euler(ang: Vec3) -> Mat3 {
7171
}
7272
fn hash(p: Vec2) -> f32 {
7373
let h: f32 = p.dot(vec2(127.1, 311.7));
74-
(h.sin() * 43758.5453123).gl_fract()
74+
(h.sin() * 43758.5453123).fract_gl()
7575
}
7676
fn noise(p: Vec2) -> f32 {
7777
let i: Vec2 = p.floor();

shaders/src/skyline.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ fn v21(a: Vec2) -> f32 {
8585
a.x + a.y * 37.0
8686
}
8787
fn hash11(a: f32) -> f32 {
88-
(a.sin() * 10403.9).gl_fract()
88+
(a.sin() * 10403.9).fract_gl()
8989
}
9090
fn hash21(uv: Vec2) -> f32 {
9191
let f: f32 = uv.x + uv.y * 37.0;
92-
(f.sin() * 104003.9).gl_fract()
92+
(f.sin() * 104003.9).fract_gl()
9393
}
9494
fn hash22(uv: Vec2) -> Vec2 {
9595
let f: f32 = uv.x + uv.y * 37.0;
@@ -99,15 +99,15 @@ fn _hash12(f: f32) -> Vec2 {
9999
(f.cos() * vec2(10003.579, 37049.7)).fract_gl()
100100
}
101101
fn _hash1d(u: f32) -> f32 {
102-
(u.sin() * 143.9).gl_fract() // scale this down to kill the jitters
102+
(u.sin() * 143.9).fract_gl() // scale this down to kill the jitters
103103
}
104104
fn hash2d(uv: Vec2) -> f32 {
105105
let f: f32 = uv.x + uv.y * 37.0;
106-
(f.sin() * 104003.9).gl_fract()
106+
(f.sin() * 104003.9).fract_gl()
107107
}
108108
fn hash3d(uv: Vec3) -> f32 {
109109
let f: f32 = uv.x + uv.y * 37.0 + uv.z * 521.0;
110-
(f.sin() * 110003.9).gl_fract()
110+
(f.sin() * 110003.9).fract_gl()
111111
}
112112
fn mix_p(f0: f32, f1: f32, a: f32) -> f32 {
113113
mix(f0, f1, a * a * (3.0 - 2.0 * a))
@@ -415,7 +415,7 @@ impl<C0> State<C0> {
415415
let mut repeat_dist: f32 = 0.25; // Car density bumper to bumper
416416
// If we are going north/south instead of east/west (?) make cars that are
417417
// stopped in the street so we don't have collisions.
418-
if (rep.x.gl_fract() - 0.5).abs() < 0.35 {
418+
if (rep.x.fract_gl() - 0.5).abs() < 0.35 {
419419
p2.x += 0.05;
420420
p2 = (p2.zx() * vec2(-1.0, 1.0)).extend(p2.y).xzy(); // Rotate 90 degrees
421421
rep = p2.xz().extend(rep.y).xzy();
@@ -463,7 +463,7 @@ fn calc_windows(
463463
window = window.max(mix(
464464
0.2,
465465
1.0,
466-
((pos.y * 20.0 - 0.35).gl_fract() * 2.0 + 0.1).floor(),
466+
((pos.y * 20.0 - 0.35).fract_gl() * 2.0 + 0.1).floor(),
467467
));
468468
if pos.y < 0.05 {
469469
window = 1.0;
@@ -475,12 +475,12 @@ fn calc_windows(
475475
window = window.max(mix(
476476
0.2,
477477
1.0,
478-
((pos.x * 40.0 + 0.05).gl_fract() * win_width).floor(),
478+
((pos.x * 40.0 + 0.05).fract_gl() * win_width).floor(),
479479
));
480480
window = window.max(mix(
481481
0.2,
482482
1.0,
483-
((pos.z * 40.0 + 0.05).gl_fract() * win_width).floor(),
483+
((pos.z * 40.0 + 0.05).fract_gl() * win_width).floor(),
484484
));
485485
if window < 0.5 {
486486
*window_ref += 1.0;
@@ -547,7 +547,7 @@ impl<C0: SampleCube> State<C0> {
547547
let t5: f32 = 16.0;
548548
let t6: f32 = 18.0;*/
549549
// Repeat the animation after time t6
550-
self.local_time = (self.local_time / t6).gl_fract() * t6;
550+
self.local_time = (self.local_time / t6).fract_gl() * t6;
551551
if self.local_time < t1 {
552552
let time: f32 = self.local_time - t0;
553553
let alpha: f32 = time / (t1 - t0);
@@ -648,16 +648,16 @@ impl<C0: SampleCube> State<C0> {
648648
// The distance function is not continuous at city block boundaries,
649649
// so we have to pause our ray march at each voxel boundary.
650650
let mut walk: f32 = dist_and_mat.x;
651-
let mut dx: f32 = -pos.x.gl_fract();
651+
let mut dx: f32 = -pos.x.fract_gl();
652652
if ray_vec.x > 0.0 {
653-
dx = (-pos.x).gl_fract();
653+
dx = (-pos.x).fract_gl();
654654
}
655-
let mut dz: f32 = -pos.z.gl_fract();
655+
let mut dz: f32 = -pos.z.fract_gl();
656656
if ray_vec.z > 0.0 {
657-
dz = (-pos.z).gl_fract();
657+
dz = (-pos.z).fract_gl();
658658
}
659659
let mut nearest_voxel: f32 =
660-
(dx / ray_vec.x).gl_fract().min((dz / ray_vec.z).gl_fract()) + VOXEL_PAD;
660+
(dx / ray_vec.x).fract_gl().min((dz / ray_vec.z).fract_gl()) + VOXEL_PAD;
661661
nearest_voxel = VOXEL_PAD.max(nearest_voxel); // hack that assumes streets and sidewalks are this wide.
662662
//nearestVoxel = nearestVoxel.max(t * 0.02); // hack to stop voxel walking in the distance.
663663
walk = walk.min(nearest_voxel);
@@ -729,17 +729,17 @@ impl<C0: SampleCube> State<C0> {
729729
}
730730

731731
let mut walk: f32 = temp_dist;
732-
let mut dx: f32 = -shadow_pos.x.gl_fract();
732+
let mut dx: f32 = -shadow_pos.x.fract_gl();
733733
if self.sun_dir.x > 0.0 {
734-
dx = (-shadow_pos.x).gl_fract();
734+
dx = (-shadow_pos.x).fract_gl();
735735
}
736-
let mut dz: f32 = -shadow_pos.z.gl_fract();
736+
let mut dz: f32 = -shadow_pos.z.fract_gl();
737737
if self.sun_dir.z > 0.0 {
738-
dz = (-shadow_pos.z).gl_fract();
738+
dz = (-shadow_pos.z).fract_gl();
739739
}
740740
let mut nearest_voxel: f32 = (dx / self.sun_dir.x)
741-
.gl_fract()
742-
.min((dz / self.sun_dir.z).gl_fract())
741+
.fract_gl()
742+
.min((dz / self.sun_dir.z).fract_gl())
743743
+ small_val;
744744
nearest_voxel = nearest_voxel.max(0.2); // hack that assumes streets and sidewalks are this wide.
745745
walk = walk.min(nearest_voxel);
@@ -825,8 +825,8 @@ impl<C0: SampleCube> State<C0> {
825825
normal = (normal + n_temp * 0.2).normalize();
826826
} else {
827827
// Draw the road
828-
let xroad: f32 = ((pos.x + 0.5).gl_fract() - 0.5).abs();
829-
let zroad: f32 = ((pos.z + 0.5).gl_fract() - 0.5).abs();
828+
let xroad: f32 = ((pos.x + 0.5).fract_gl() - 0.5).abs();
829+
let zroad: f32 = ((pos.z + 0.5).fract_gl() - 0.5).abs();
830830
let road: f32 = saturate((xroad.min(zroad) - 0.143) * 480.0);
831831
tex_color *= 1.0 - normal.y * 0.95 * hash21(block * 9.87) * road; // change rooftop color
832832
tex_color *= mix(0.1, 1.0, road);
@@ -841,8 +841,8 @@ impl<C0: SampleCube> State<C0> {
841841
let mut white_line: f32 = saturate(1.0 - (xroad.min(zroad) - 0.06) * 480.0);
842842
white_line *= saturate((xroad.min(zroad) - 0.056) * 480.0);
843843
white_line *= saturate((xroad * xroad + zroad * zroad - 0.05) * 880.0);
844-
white_line *= saturate(1.0 - ((zroad * 8.0).gl_fract() - 0.5) * 280.0); // dotted line
845-
white_line *= saturate(1.0 - ((xroad * 8.0).gl_fract() - 0.5) * 280.0);
844+
white_line *= saturate(1.0 - ((zroad * 8.0).fract_gl() - 0.5) * 280.0); // dotted line
845+
white_line *= saturate(1.0 - ((xroad * 8.0).fract_gl() - 0.5) * 280.0);
846846
tex_color = mix(tex_color, Vec3::splat(0.5), white_line);
847847

848848
white_line = saturate(1.0 - (xroad.min(zroad) - 0.11) * 480.0);
@@ -851,12 +851,12 @@ impl<C0: SampleCube> State<C0> {
851851
tex_color = mix(tex_color, Vec3::splat(0.5), white_line);
852852

853853
// crosswalk
854-
let mut cross_walk: f32 = saturate(1.0 - ((xroad * 40.0).gl_fract() - 0.5) * 280.0);
854+
let mut cross_walk: f32 = saturate(1.0 - ((xroad * 40.0).fract_gl() - 0.5) * 280.0);
855855
cross_walk *= saturate((zroad - 0.15) * 880.0);
856856
cross_walk *= saturate((-zroad + 0.21) * 880.0) * (1.0 - road);
857857
cross_walk *= n * n;
858858
tex_color = mix(tex_color, Vec3::splat(0.25), cross_walk);
859-
cross_walk = saturate(1.0 - ((zroad * 40.0).gl_fract() - 0.5) * 280.0);
859+
cross_walk = saturate(1.0 - ((zroad * 40.0).fract_gl() - 0.5) * 280.0);
860860
cross_walk *= saturate((xroad - 0.15) * 880.0);
861861
cross_walk *= saturate((-xroad + 0.21) * 880.0) * (1.0 - road);
862862
cross_walk *= n * n;
@@ -996,9 +996,9 @@ impl<C0: SampleCube> State<C0> {
996996
let block_res: Vec2 = (self.inputs.resolution.xy() / block_size).floor() + Vec2::ONE;
997997
// ugly bug with mod.
998998
//float blockX = mod(frame, blockRes.x);
999-
let block_x: f32 = (frame / block_res.x).gl_fract() * block_res.x;
999+
let block_x: f32 = (frame / block_res.x).fract_gl() * block_res.x;
10001000
//float blockY = mod(floor(frame / blockRes.x), blockRes.y);
1001-
let block_y: f32 = ((frame / block_res.x).floor() / block_res.y).gl_fract() * block_res.y;
1001+
let block_y: f32 = ((frame / block_res.x).floor() / block_res.y).fract_gl() * block_res.y;
10021002
// Don't draw anything outside the current block.
10031003
if (frag_coord.x - block_x * block_size >= block_size)
10041004
|| (frag_coord.x - (block_x - 1.0) * block_size < block_size)

shaders/src/soft_shadow_variation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn sd_box(p: Vec3, b: Vec3) -> f32 {
4646
//------------------------------------------------------------------
4747

4848
fn map(pos: Vec3) -> f32 {
49-
let qos: Vec3 = vec3((pos.x + 0.5).gl_fract() - 0.5, pos.y, pos.z);
49+
let qos: Vec3 = vec3((pos.x + 0.5).fract_gl() - 0.5, pos.y, pos.z);
5050
return sd_plane(pos - vec3(0.0, 0.00, 0.0))
5151
.min(sd_box(qos - vec3(0.0, 0.25, 0.0), vec3(0.2, 0.5, 0.2)));
5252
}
@@ -192,7 +192,7 @@ impl Inputs {
192192
// camera-to-world transformation
193193
let ca: Mat3 = set_camera(ro, ta, 0.0);
194194

195-
let technique: i32 = if (self.time / 2.0).gl_fract() > 0.5 {
195+
let technique: i32 = if (self.time / 2.0).fract_gl() > 0.5 {
196196
1
197197
} else {
198198
0

shaders/src/tokyo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl State {
7676
// noises
7777

7878
fn hash(n: f32) -> f32 {
79-
(n.sin() * 687.3123).gl_fract()
79+
(n.sin() * 687.3123).fract_gl()
8080
}
8181

8282
fn noise(x: Vec2) -> f32 {

0 commit comments

Comments
 (0)