2024-04-01 00:05:38 +00:00
|
|
|
#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;
|
|
|
|
|
2024-04-01 01:12:59 +00:00
|
|
|
const jupiter_radius_Mm: f32 = 71.492;
|
2024-04-02 05:05:17 +00:00
|
|
|
const brightness = 0.025;
|
2024-04-01 01:12:59 +00:00
|
|
|
|
2024-04-01 01:58:32 +00:00
|
|
|
fn smooth_edge(start: f32, end: f32, value: f32) -> f32 {
|
2024-04-01 01:45:32 +00:00
|
|
|
var x: f32 = (value - start) / (end - start);
|
|
|
|
return 4 * x * x * (1 - x * x);
|
|
|
|
}
|
|
|
|
|
2024-10-12 01:00:23 +00:00
|
|
|
//fn rand(co: vec2<f32>) -> f32 {
|
|
|
|
//return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
|
|
|
|
//}
|
2024-10-06 15:57:32 +00:00
|
|
|
|
|
|
|
//const PHI: f32 = 1.61803398874989484820459;
|
|
|
|
//fn gold_noise(xy: vec2<f32>, seed: f32) -> f32 {
|
|
|
|
//return fract(tan(distance(xy*PHI, xy)*seed)*xy.x);
|
|
|
|
//}
|
|
|
|
|
2024-04-01 02:00:57 +00:00
|
|
|
fn ring_density(radius: f32) -> f32 {
|
2024-04-02 05:05:17 +00:00
|
|
|
// NOTE: Keep this in sync with src/nature.rs::ring_density
|
|
|
|
// Input: distance to center of jupiter in million meters
|
|
|
|
// Output: relative brightness of the ring
|
2024-04-01 01:45:32 +00:00
|
|
|
let halo_inner: f32 = 92.0;
|
|
|
|
let halo_outer: f32 = 122.5;
|
|
|
|
let main_inner: f32 = 122.5;
|
|
|
|
let main_outer: f32 = 129.0;
|
|
|
|
let amalthea_inner: f32 = 129.0;
|
|
|
|
let amalthea_outer: f32 = 182.0;
|
|
|
|
let thebe_inner: f32 = 129.0;
|
|
|
|
let thebe_outer: f32 = 229.0;
|
|
|
|
let metis_notch_center: f32 = 128.0;
|
2024-05-01 15:17:56 +00:00
|
|
|
let metis_notch_width: f32 = 0.1;
|
2024-04-01 01:45:32 +00:00
|
|
|
|
2024-04-02 05:05:17 +00:00
|
|
|
let halo_brightness: f32 = 0.75;
|
|
|
|
let main_brightness: f32 = 1.0;
|
|
|
|
let almathea_brightness: f32 = 0.5;
|
|
|
|
let thebe_brightness: f32 = 0.5;
|
2024-04-01 01:45:32 +00:00
|
|
|
|
|
|
|
var density: f32 = 0.0;
|
|
|
|
|
|
|
|
if (radius >= halo_inner && radius <= halo_outer) {
|
2024-04-01 01:58:32 +00:00
|
|
|
density = halo_brightness * smooth_edge(halo_inner, halo_outer, radius);
|
2024-04-01 01:45:32 +00:00
|
|
|
} else if (radius >= main_inner && radius <= main_outer) {
|
|
|
|
var metis_notch_effect: f32 = 1.0;
|
|
|
|
if (radius > metis_notch_center - metis_notch_width * 0.5 && radius < metis_notch_center + metis_notch_width * 0.5) {
|
2024-05-01 15:17:56 +00:00
|
|
|
metis_notch_effect = 0.8 * (1.0 - smooth_edge(metis_notch_center - metis_notch_width * 0.5, metis_notch_center + metis_notch_width * 0.5, radius));
|
2024-04-01 01:45:32 +00:00
|
|
|
}
|
2024-04-01 01:58:32 +00:00
|
|
|
density = main_brightness * metis_notch_effect * smooth_edge(main_inner, main_outer, radius);
|
2024-04-01 01:45:32 +00:00
|
|
|
} else {
|
|
|
|
if (radius >= amalthea_inner && radius <= amalthea_outer) {
|
2024-04-01 01:58:32 +00:00
|
|
|
density = almathea_brightness * smooth_edge(amalthea_inner, amalthea_outer, radius);
|
2024-04-01 01:45:32 +00:00
|
|
|
}
|
|
|
|
if (radius >= thebe_inner && radius <= thebe_outer) {
|
2024-04-01 01:58:32 +00:00
|
|
|
density += thebe_brightness * smooth_edge(thebe_inner, thebe_outer, radius);
|
2024-04-01 01:45:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return density;
|
|
|
|
}
|
|
|
|
|
2024-04-01 00:05:38 +00:00
|
|
|
@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);
|
2024-04-01 13:40:33 +00:00
|
|
|
var alpha = brightness;
|
2024-04-01 01:12:59 +00:00
|
|
|
let r_uv = 2 * distance(in.uv, vec2<f32>(0.5));
|
|
|
|
let r = r_uv * ring_radius / jupiter_radius * jupiter_radius_Mm;
|
|
|
|
|
2024-04-01 02:00:57 +00:00
|
|
|
alpha *= ring_density(r);
|
2024-04-04 22:23:01 +00:00
|
|
|
alpha -= 0.001;
|
2024-04-01 01:12:59 +00:00
|
|
|
if alpha <= 0.0 {
|
2024-04-04 22:23:01 +00:00
|
|
|
return vec4<f32>(color, 0.0);
|
2024-04-01 01:12:59 +00:00
|
|
|
}
|
2024-04-01 00:05:38 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2024-10-06 15:57:32 +00:00
|
|
|
//if (sin(in.uv[0] * 1000.0) + cos(in.uv[1] * 10412.0) > 1.999) {
|
|
|
|
//if (sin(in.uv[0] * 10000.0 + in.uv[1] * 5132.0) + cos(in.uv[0] * 12399.0 + in.uv[1] * 10412.0) > 1.999) {
|
|
|
|
//if (sin(sin(in.uv[0] * 10000000.0) * 412.0 + cos(in.uv[1] * 11132000.0) * 12.0) + cos(sin(in.uv[0] * 12309900.0) * 93.0 + sin(in.uv[1] * 10410200.0) * 115.0) > 1.999) {
|
2024-10-12 01:00:23 +00:00
|
|
|
//if (rand(in.uv) + rand(vec2(in.uv[1]*10.0, in.uv[0]*10.0)) > 1.997) {
|
|
|
|
//alpha *= 200.0;
|
|
|
|
//}
|
2024-04-01 00:05:38 +00:00
|
|
|
return vec4<f32>(color, alpha);
|
|
|
|
}
|