1- struct VertexInput {
2- @location (0 ) position : vec2 <f32 >,
3- @location (1 ) color : vec3 <f32 >,
4- @location (2 ) center : vec2 <f32 >,
5- @location (3 ) radius : f32 ,
1+ // Instance data: position (xy), radius, color (rgb)
2+ struct InstanceInput {
3+ @location (0 ) pos_radius : vec4 <f32 >, // xy = position, z = radius, w = unused
4+ @location (1 ) color : vec4 <f32 >, // rgb = color, a = unused
65}
76
87struct VertexOutput {
98 @builtin (position ) position : vec4 <f32 >,
109 @location (0 ) color : vec3 <f32 >,
11- @location (1 ) center : vec2 <f32 >,
12- @location (2 ) radius : f32 ,
13- @location (3 ) uv : vec2 <f32 >,
10+ @location (1 ) uv : vec2 <f32 >,
1411}
1512
13+ // Quad vertices (generated in shader)
14+ const QUAD_VERTICES : array <vec2 <f32 >, 6 > = array <vec2 <f32 >, 6 >(
15+ vec2 <f32 >(- 1 .0 , - 1 .0 ),
16+ vec2 <f32 >(1 .0 , - 1 .0 ),
17+ vec2 <f32 >(- 1 .0 , 1 .0 ),
18+ vec2 <f32 >(1 .0 , - 1 .0 ),
19+ vec2 <f32 >(1 .0 , 1 .0 ),
20+ vec2 <f32 >(- 1 .0 , 1 .0 ),
21+ );
22+
1623@vertex
17- fn vs_main (vertex : VertexInput ) -> VertexOutput {
24+ fn vs_main (
25+ instance : InstanceInput ,
26+ @builtin (vertex_index ) vertex_index : u32 ,
27+ ) -> VertexOutput {
1828 var out : VertexOutput ;
19- out . position = vec4 <f32 >(vertex . position , 0 .0 , 1 .0 );
20- out . color = vertex . color ;
21- out . center = vertex . center ;
22- out . radius = vertex . radius ;
23-
24- // Calculate UV coordinates relative to the ball's center
25- out . uv = (vertex . position - vertex . center ) / vertex . radius ;
29+
30+ let quad_pos = QUAD_VERTICES [vertex_index ];
31+ let screen_pos = instance . pos_radius . xy ;
32+ let radius = instance . pos_radius . z ;
2633
34+ // Expand quad by radius with glow extension
35+ let glow_extension = radius * 0 .5 ;
36+ let quad_size = radius + glow_extension ;
37+
38+ out . position = vec4 <f32 >(screen_pos + quad_pos * quad_size , 0 .0 , 1 .0 );
39+ out . color = instance . color . rgb ;
40+ out . uv = quad_pos ; // -1 to 1 range
41+
2742 return out ;
2843}
2944
3045@fragment
3146fn fs_main (in : VertexOutput ) -> @location (0 ) vec4 <f32 > {
32- // Calculate distance from center of the ball
47+ // Distance from center (uv is -1 to 1)
3348 let dist = length (in . uv );
3449
35- // Create a proper circular shape with smooth falloff
36- let circle = smoothstep (1 .0 , 0 .0 , dist );
37-
38- // Create a more pronounced glowing effect with multiple layers
39- let core = smoothstep (1 .0 , 0 .0 , dist * 2 .0 ); // Bright core
40- let glow_inner = smoothstep (1 .0 , 0 .0 , dist * 1 .5 ) * 0 .9 ; // Inner glow
41- let glow_middle = smoothstep (1 .0 , 0 .0 , dist * 1 .2 ) * 0 .7 ; // Middle glow
42- let glow_outer = smoothstep (1 .0 , 0 .0 , dist * 0 .8 ) * 0 .5 ; // Outer glow
43- let glow_far = smoothstep (1 .0 , 0 .0 , dist * 0 .5 ) * 0 .3 ; // Far glow
44-
45- // Combine all glow layers for a more intense effect
50+ // Create glowing ball effect
51+ let core = smoothstep (1 .0 , 0 .0 , dist * 2 .0 );
52+ let glow_inner = smoothstep (1 .0 , 0 .0 , dist * 1 .5 ) * 0 .9 ;
53+ let glow_middle = smoothstep (1 .0 , 0 .0 , dist * 1 .2 ) * 0 .7 ;
54+ let glow_outer = smoothstep (1 .0 , 0 .0 , dist * 0 .8 ) * 0 .5 ;
55+ let glow_far = smoothstep (1 .0 , 0 .0 , dist * 0 .5 ) * 0 .3 ;
56+
4657 let glow = core + glow_inner + glow_middle + glow_outer + glow_far ;
47-
48- // Create the final color with transparency
49- let alpha = glow * 0 .95 ; // More opaque for better visibility
58+ let alpha = glow * 0 .95 ;
5059 let final_color = in . color * glow ;
5160
52- // Add a subtle white glow around the edges for better definition
61+ // White glow for definition
5362 let white_glow = smoothstep (1 .0 , 0 .0 , dist * 0 .4 ) * 0 .2 ;
5463 let final_color_with_glow = final_color + vec3 <f32 >(white_glow );
55-
64+
5665 return vec4 <f32 >(final_color_with_glow , alpha );
57- }
66+ }
0 commit comments