@@ -455,6 +455,31 @@ fn remap_time(parent_t: f32, start_time: f32, end_time: f32) -> f32 {
455
455
return f32:: clamp ( ( parent_t - start_time) / duration, 0.0 , 1.0 ) ;
456
456
}
457
457
458
+ /// Signed distance function for a box centered at the origin.
459
+ /// `p` is the point to evaluate.
460
+ /// `b` is the half-dimensions of the box.
461
+ fn sd_box ( p : Vec2 , b : Vec2 ) -> f32 {
462
+ let d = p. abs ( ) - b;
463
+ let outside = d. max ( Vec2 :: ZERO ) ;
464
+ let inside = d. x . max ( d. y ) . min ( 0.0 ) ;
465
+ outside. length ( ) + inside
466
+ }
467
+
468
+ /// Draws the outline of a rectangle using the signed distance function.
469
+ /// `uv`: coordinates relative to the center of the rectangle.
470
+ /// `aspect`: half-dimensions of the rectangle (half-width, half-height).
471
+ /// `stroke`: thickness of the rectangle outline.
472
+ fn draw_viewport_rect_outline ( uv : Vec2 , aspect : Vec2 , stroke : f32 , aa_width : f32 ) -> f32 {
473
+ let distance = sd_box ( uv, aspect) ;
474
+ let half_stroke = stroke * 0.5 ;
475
+
476
+ smoothstep (
477
+ half_stroke + aa_width,
478
+ half_stroke - aa_width,
479
+ distance. abs ( ) ,
480
+ )
481
+ }
482
+
458
483
/// Alpha compositing using "over" operator
459
484
fn composite_layers < const N : usize > ( overlay_colors : & [ Vec4 ; N ] ) -> Vec4 {
460
485
let mut result = Vec4 :: ZERO ;
@@ -476,10 +501,17 @@ impl Inputs {
476
501
// Determine the shorter dimension of the screen.
477
502
let shorter_dim = screen_xy. min_element ( ) ;
478
503
504
+ let debug_zoom = 10.0 ;
505
+ let debug_translate = vec2 ( 0.0 , 9.0 ) ;
506
+
507
+ let debug_zoom = 5.0 ;
508
+ let debug_translate = vec2 ( 0.0 , 4.5 ) ;
509
+
479
510
// Compute normalized pixel coordinates.
480
511
// This maps the center of the screen to (0,0) and the shortest side to [-1,1].
481
512
// Aspect ratio is preserved.
482
- let uv = ( frag_coord - screen_xy * 0.5 ) / shorter_dim * 2.0 ;
513
+ let uv = ( frag_coord - screen_xy * 0.5 ) / shorter_dim * 2.0 * debug_zoom - debug_translate;
514
+ let uv = ( frag_coord - screen_xy * 0.5 ) / shorter_dim * 2.0 * debug_zoom - debug_translate;
483
515
let aa_width = 2.0 / screen_xy. max_element ( ) ;
484
516
485
517
let aspect = screen_xy / shorter_dim;
@@ -488,6 +520,9 @@ impl Inputs {
488
520
let mut debug_red_alpha: f32 = 0.0 ;
489
521
let mut debug_blue_alpha: f32 = 0.0 ;
490
522
523
+ let m_viewport_rect = draw_viewport_rect_outline ( uv, aspect, 0.1 , aa_width) ;
524
+ debug_red_alpha = debug_red_alpha. max ( m_viewport_rect) ;
525
+
491
526
let center = vec2 ( 0.0 , 0.0 ) ;
492
527
let bottom_middle = vec2 ( 0.0 , -aspect. y ) ;
493
528
let top_middle = vec2 ( 0.0 , aspect. y ) ;
@@ -497,9 +532,8 @@ impl Inputs {
497
532
let start_radius = ( bottom_middle - center) . length ( ) ;
498
533
let target_radius = 0.2 ;
499
534
let target_stroke = 0.05 ;
500
- let m_target = sdf_circle_outline ( uv, center, target_radius, target_stroke) ;
501
- //combined_mask = combined_mask.max(m_target);
502
- let period = 4.0 ; // seconds
535
+ let period = 8.0 ; //4.0; // seconds
536
+ let period = 8.0 ; //4.0; // seconds
503
537
let t_master = ( self . time / period) . fract ( ) ;
504
538
//let t_master = 0.95;
505
539
//let t_master = 0.8;
0 commit comments