Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1#import noisy_bevy::fbm_simplex_2d_seeded
2#import bevy_sprite::mesh2d_functions::{
3 get_world_from_local,
4 mesh2d_position_local_to_clip,
5}
7struct AsteroidMaterial {
8 params: vec4<f32>
9}
11@group(2) @binding(0) var<uniform> material: AsteroidMaterial;
13struct Vertex {
14 @builtin(instance_index) instance_index: u32,
15 @location(0) position: vec3<f32>,
16 @location(1) blend_color: vec4<f32>,
17};
19struct VertexOutput {
20 @builtin(position) clip_position: vec4<f32>,
21 @location(0) object_position: vec2<f32>,
22};
24@vertex
25fn vertex(vertex: Vertex) -> VertexOutput {
26 var out: VertexOutput;
27 // Project the world position of the mesh into screen position
28 let model = get_world_from_local(vertex.instance_index);
29 out.clip_position = mesh2d_position_local_to_clip(model, vec4<f32>(vertex.position, 1.0));
30 out.object_position = vertex.position.xy;
31 return out;
34@fragment
35fn fragment(
36 vertex_output: VertexOutput,
37) -> @location(0) vec4<f32> {
38 var p = vertex_output.object_position;
39 let params = material.params;
40 let freq_scale = params.x;
41 let amp_scale = params.y;
42 let radius = params.z;
43 let seed = params.w;
45 let r = sqrt(p.x * p.x + p.y * p.y);
46 let d = r - radius;
48 // smooth noise same as used on cpu...
49 // let n = simplex_noise_2d(p * freq_scale) * amp_scale;
51 // ...or add some extra turbulence to the "atmosphere"
52 let n = fbm_simplex_2d_seeded(p * freq_scale, 7, 2.0, 0.5, seed) * amp_scale;
54 var v = d - n;
55 v = pow(-v * 0.1 + 0.3, 2.1);
57 return vec4(v, v, v, 1.);
Contents