Skip to content

Commit d22bfea

Browse files
committed
ANNOTATION!!!!
1 parent f75af10 commit d22bfea

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

shaders/src/shader_prelude.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,24 @@ pub struct ShaderDefinition {
6262
}
6363

6464
#[inline(always)]
65+
#[must_use]
6566
pub fn saturate_vec3(a: Vec3) -> Vec3 {
6667
a.clamp(Vec3::ZERO, Vec3::ONE)
6768
}
6869
#[inline(always)]
70+
#[must_use]
6971
pub fn saturate_vec2(a: Vec2) -> Vec2 {
7072
a.clamp(Vec2::ZERO, Vec2::ONE)
7173
}
7274
#[inline(always)]
75+
#[must_use]
7376
pub fn saturate(a: f32) -> f32 {
7477
a.clamp(0.0, 1.0)
7578
}
7679

7780
/// Based on: https://seblagarde.wordpress.com/2014/12/01/inverse-trigonometric-functions-gpu-optimization-for-amd-gcn-architecture/
7881
#[inline]
82+
#[must_use]
7983
pub fn acos_approx(v: f32) -> f32 {
8084
let x = v.abs();
8185
let mut res = -0.155972 * x + 1.56467; // p(x)
@@ -89,6 +93,7 @@ pub fn acos_approx(v: f32) -> f32 {
8993
}
9094

9195
#[inline(always)]
96+
#[must_use]
9297
pub fn smoothstep(edge0: f32, edge1: f32, x: f32) -> f32 {
9398
// Scale, bias and saturate x to 0..1 range
9499
let x = saturate((x - edge0) / (edge1 - edge0));
@@ -97,6 +102,7 @@ pub fn smoothstep(edge0: f32, edge1: f32, x: f32) -> f32 {
97102
}
98103

99104
#[inline(always)]
105+
#[must_use]
100106
pub fn mix<X: Copy + Mul<A, Output = X> + Add<Output = X> + Sub<Output = X>, A: Copy>(
101107
x: X,
102108
y: X,
@@ -106,6 +112,7 @@ pub fn mix<X: Copy + Mul<A, Output = X> + Add<Output = X> + Sub<Output = X>, A:
106112
}
107113

108114
pub trait Clamp {
115+
#[must_use]
109116
fn clamp(self, min: Self, max: Self) -> Self;
110117
}
111118

@@ -117,9 +124,13 @@ impl Clamp for f32 {
117124
}
118125

119126
pub trait FloatExt {
127+
#[must_use]
120128
fn fract_gl(self) -> Self;
129+
#[must_use]
121130
fn rem_euclid(self, rhs: Self) -> Self;
131+
#[must_use]
122132
fn sign_gl(self) -> Self;
133+
#[must_use]
123134
fn step(self, x: Self) -> Self;
124135
}
125136

@@ -161,12 +172,19 @@ impl FloatExt for f32 {
161172
}
162173

163174
pub trait VecExt {
175+
#[must_use]
164176
fn sin(self) -> Self;
177+
#[must_use]
165178
fn cos(self) -> Self;
179+
#[must_use]
166180
fn powf_vec(self, p: Self) -> Self;
181+
#[must_use]
167182
fn sqrt(self) -> Self;
183+
#[must_use]
168184
fn ln(self) -> Self;
185+
#[must_use]
169186
fn step(self, other: Self) -> Self;
187+
#[must_use]
170188
fn sign_gl(self) -> Self;
171189
}
172190

shaders/src/shaders/loading_repeating_circles.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,79 +40,93 @@ const AA_WIDTH: f32 = 0.01;
4040
struct SDFValue(f32);
4141
impl SDFValue {
4242
/// Creates a new SDFValue.
43+
#[must_use]
4344
pub fn new(value: f32) -> Self {
4445
SDFValue(value)
4546
}
4647

4748
/// Returns the raw f32 distance.
49+
#[must_use]
4850
pub fn value(self) -> f32 {
4951
self.0
5052
}
5153

5254
/// Returns `true` if the SDF value is inside the shape (negative).
55+
#[must_use]
5356
pub fn is_inside(self) -> bool {
5457
self.0 < 0.0
5558
}
5659

5760
/// Returns `true` if the SDF value is outside the shape (positive).
61+
#[must_use]
5862
pub fn is_outside(self) -> bool {
5963
self.0 > 0.0
6064
}
6165

6266
/// Converts the SDF value to an alpha value for anti-aliasing.
6367
/// Alpha is 1.0 deep inside, 0.0 deep outside, and smooth in between.
6468
/// The transition happens from `AA_WIDTH` (alpha 0) to `-AA_WIDTH` (alpha 1).
69+
#[must_use]
6570
pub fn to_alpha(self) -> f32 {
6671
return smoothstep(AA_WIDTH, -AA_WIDTH, self.0);
6772
}
6873

6974
/// Insets the shape by a given thickness.
7075
/// This is done by shrinking the shape and then calculating the difference.
76+
#[must_use]
7177
pub fn inset(self, amount: f32) -> Self {
7278
Self(self.0.max(-(self.0 + amount)))
7379
}
7480

7581
/// Expands (if amount > 0) or shrinks (if amount < 0) the shape.
7682
/// This is equivalent to subtracting from the distance value.
83+
#[must_use]
7784
pub fn offset(&self, amount: f32) -> Self {
7885
Self(self.0 - amount)
7986
}
8087

8188
/// Takes the absolute value of the SDF, effectively creating an infinitely thin shell
8289
/// on the surface of the original shape.
90+
#[must_use]
8391
pub fn shell(self) -> Self {
8492
Self(self.0.abs())
8593
}
8694

8795
/// Creates an outline (hollow shape) from the SDF.
96+
#[must_use]
8897
pub fn to_outline(self, thickness: f32) -> Self {
8998
Self(self.0.abs() - thickness)
9099
}
91100

92101
/// Difference operation (self - other). Result is inside if inside self AND outside other.
93102
/// Equivalent to Intersection(self, Invert(other)).
103+
#[must_use]
94104
pub fn difference(self, other: Self) -> Self {
95105
Self(self.0.max(-other.0))
96106
}
97107

98108
/// Union operation (self U other). Result is inside if inside self OR inside other.
109+
#[must_use]
99110
pub fn union(self, other: Self) -> Self {
100111
Self(self.0.min(other.0))
101112
}
102113

103114
/// Intersection operation (self ∩ other). Result is inside if inside self AND inside other.
115+
#[must_use]
104116
pub fn intersection(self, other: Self) -> Self {
105117
Self(self.0.max(other.0))
106118
}
107119

108120
/// Inverts the SDF (inside becomes outside and vice-versa).
121+
#[must_use]
109122
pub fn invert(self) -> Self {
110123
Self(-self.0)
111124
}
112125
}
113126

114127
/// Calculates the distance from the origin to the center of the initial main circle so that
115128
/// at time `0`, only one border circle is visible, with the others just touching the sides/bottom of the viewport.
129+
#[must_use]
116130
fn calculate_initial_distance_for_main_circle_center(
117131
aspect: Vec2,
118132
border_circle_radius: f32,
@@ -213,6 +227,7 @@ fn calculate_initial_distance_for_main_circle_center(
213227

214228
/// Given an arc radius and its half-stroke width,
215229
/// this function computes the angle that the arc extends beyond its endpoints because of the stroke width.
230+
#[must_use]
216231
fn arc_cap_extension_angle(arc_radius: f32, half_stroke: f32) -> f32 {
217232
// Avoid division by zero.
218233
if arc_radius <= 0.0 {
@@ -244,6 +259,7 @@ fn arc_cap_extension_angle(arc_radius: f32, half_stroke: f32) -> f32 {
244259
/// * `stroke`: Width of the arc body.
245260
///
246261
/// Returns the [`SDFValue`] for the arc.
262+
#[must_use]
247263
fn sdf_arc_filled(
248264
uv: Vec2,
249265
center_shape: Vec2,
@@ -328,6 +344,7 @@ fn sdf_arc_filled(
328344
/// * `fade_intensity`: `0` (fully faded/transparent) to `1` (fully opaque)
329345
///
330346
/// Returns `1` in the opaque region, fades to `0` outside it.
347+
#[must_use]
331348
fn arc_fade_out(
332349
uv: Vec2,
333350
center: Vec2,
@@ -421,6 +438,7 @@ fn arc_fade_out(
421438
///
422439
/// Returns a `Vec2` with the first component being the [`SDFValue`] for the arc outline,
423440
/// and the second component being the fade intensity.
441+
#[must_use]
424442
fn sdf_arc_outline(
425443
uv: Vec2,
426444
center_shape: Vec2,
@@ -432,15 +450,17 @@ fn sdf_arc_outline(
432450
fade_center_angle: f32,
433451
opaque_percentage: f32,
434452
) -> (SDFValue, f32) {
435-
let sdf_outer = sdf_arc_filled(
453+
let mut sdf_value = sdf_arc_filled(
436454
uv,
437455
center_shape,
438456
start_angle,
439457
end_angle,
440458
spine_radius,
441459
outer_radius * 2.0,
442460
);
443-
let sdf_value = sdf_outer.inset(outer_radius - inner_radius);
461+
if inner_radius > EPSILON {
462+
sdf_value = sdf_value.inset(outer_radius - inner_radius);
463+
}
444464
let fade_intensity = arc_fade_out(
445465
uv,
446466
center_shape,
@@ -461,6 +481,7 @@ fn sdf_arc_outline(
461481
/// * `radius`: The radius of the circle.
462482
///
463483
/// Returns the [`SDFValue`] for the circle.
484+
#[must_use]
464485
fn sdf_circle_filled(uv: Vec2, center: Vec2, radius: f32) -> SDFValue {
465486
let p = uv - center;
466487
let d = p.length() - radius;
@@ -475,6 +496,7 @@ fn sdf_circle_filled(uv: Vec2, center: Vec2, radius: f32) -> SDFValue {
475496
///
476497
/// * `t` should be in `0..1`.
477498
/// * `c` is usually in `-2..2`.
499+
#[must_use]
478500
fn exp_time(t: f32, c: f32) -> f32 {
479501
let c = c * 10.0;
480502

@@ -488,6 +510,7 @@ fn exp_time(t: f32, c: f32) -> f32 {
488510
}
489511

490512
/// Returns the derivative of the exponential function.
513+
#[must_use]
491514
fn exp_time_derivative(t: f32, c: f32) -> f32 {
492515
let c = c * 10.0;
493516

@@ -500,6 +523,7 @@ fn exp_time_derivative(t: f32, c: f32) -> f32 {
500523
numerator / denominator
501524
}
502525

526+
#[must_use]
503527
fn offset_loop_time(t: f32, offset: f32) -> f32 {
504528
// Apply offset
505529
let offset_t = t + offset;
@@ -512,6 +536,7 @@ struct RotatingCircleResult {
512536
angle: f32,
513537
}
514538

539+
#[must_use]
515540
fn rotating_discrete_circle(
516541
center: Vec2,
517542
radius: f32,
@@ -541,6 +566,7 @@ fn rotating_discrete_circle(
541566
/// * `end_time`: The point in parent_t (`0..1`) where this sub-animation should end.
542567
///
543568
/// Returns: `0` before `start_time`, `1` after `end_time`, and a `0..1` ramp between them.
569+
#[must_use]
544570
fn remap_time(parent_t: f32, start_time: f32, end_time: f32) -> f32 {
545571
if start_time >= end_time {
546572
// If start and end are the same, or invalid order we do an instant step.
@@ -568,6 +594,7 @@ enum Positioning {
568594
/// * `half_dimensions`: half-width and half-height of the box.
569595
///
570596
/// Returns the signed distance from the box.
597+
#[must_use]
571598
fn sdf_box_filled(uv: Vec2, center: Vec2, positioning: Positioning, half_dimensions: Vec2) -> f32 {
572599
let actual_box_center = match positioning {
573600
Positioning::Centered => center,
@@ -598,6 +625,7 @@ fn sdf_box_filled(uv: Vec2, center: Vec2, positioning: Positioning, half_dimensi
598625
/// * `stroke`: This parameter will define the width of the outline.
599626
///
600627
/// Returns the signed distance from the rectangle outline.
628+
#[must_use]
601629
fn sdf_box_outline(
602630
uv: Vec2,
603631
center: Vec2,
@@ -624,6 +652,7 @@ fn sdf_box_outline(
624652
/// `t`: progress of the bar, from 0.0 (empty) to 1.0 (full).
625653
/// `index`: vertical stacking index of the bar. Index 0 is the top-most bar.
626654
/// Returns an alpha value (0.0 to 1.0) for the pixel, representing the bar's visibility.
655+
#[must_use]
627656
fn draw_time_bar(uv: Vec2, aspect: Vec2, stroke: f32, aa_width: f32, t: f32, index: u32) -> f32 {
628657
// --- Bar Configuration ---
629658
// The `stroke` argument is interpreted as the desired height of the bar.
@@ -704,6 +733,7 @@ fn draw_time_bar(uv: Vec2, aspect: Vec2, stroke: f32, aa_width: f32, t: f32, ind
704733
/// `index`: vertical stacking index of the bar. Index 0 is the top-most bar.
705734
/// `steps`: the number of discrete steps the bar fills in. If 0, bar is invisible. If 1, bar fades in fully.
706735
/// Returns an alpha value (0.0 to 1.0) for the pixel, representing the bar's visibility.
736+
#[must_use]
707737
fn draw_time_bar_discrete(
708738
uv: Vec2,
709739
aspect: Vec2,
@@ -1025,7 +1055,7 @@ impl Inputs {
10251055
-PI / 4.0,
10261056
PI / 4.0,
10271057
1.0,
1028-
0.1,
1058+
0.0,
10291059
0.5,
10301060
-PI / 4.0,
10311061
1.0,

0 commit comments

Comments
 (0)