34 lines
1 KiB
WebGPU Shading Language
34 lines
1 KiB
WebGPU Shading Language
#import bevy_pbr::{
|
|
mesh_view_bindings::globals,
|
|
forward_io::VertexOutput,
|
|
}
|
|
|
|
@group(2) @binding(0) var<uniform> ring_radius: f32;
|
|
@group(2) @binding(1) var<uniform> jupiter_radius: f32;
|
|
|
|
@fragment
|
|
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
|
|
let jupiter_percent = jupiter_radius / ring_radius;
|
|
let color = vec3<f32>(0.3, 0.3, 0.3);
|
|
var alpha = 0.01;
|
|
let r = distance(in.uv, vec2<f32>(0.5));
|
|
|
|
alpha *= (sin(11*r / 0.71 * 3.1415) + 1) / 2;
|
|
alpha *= (cos(r / 0.72 * 3.1415) + 1) / 2;
|
|
|
|
if in.uv[0] < 0.5 {
|
|
let dist = (0.5 - in.uv[0]) * 2.0; // 0.0=jupiter's center, 1.0=edge of the ring
|
|
let side_dist = abs(in.uv[1] - 0.5);
|
|
|
|
let cutoff = 0.5 * jupiter_percent * cos(dist);
|
|
if side_dist < cutoff {
|
|
return vec4<f32>(color, 0.0);
|
|
}
|
|
let fuzzy_boundary = 0.01;
|
|
if side_dist < cutoff + fuzzy_boundary {
|
|
return vec4<f32>(color, alpha * (side_dist - cutoff) / fuzzy_boundary);
|
|
}
|
|
}
|
|
return vec4<f32>(color, alpha);
|
|
}
|