From c4d78c11163474b4edd6fb3444f4d869734011ac Mon Sep 17 00:00:00 2001 From: yuni Date: Sat, 30 Nov 2024 01:38:01 +0100 Subject: [PATCH] add ring types to shader, remove shadow from ring for uranus/neptune --- assets/shaders/jupiters_rings.wgsl | 8 +++++++- src/cmd.rs | 25 ++++++++++++++++++++----- src/data/defs.txt | 8 ++++---- src/load.rs | 2 ++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/assets/shaders/jupiters_rings.wgsl b/assets/shaders/jupiters_rings.wgsl index 5be2823..a4d37ca 100644 --- a/assets/shaders/jupiters_rings.wgsl +++ b/assets/shaders/jupiters_rings.wgsl @@ -5,9 +5,14 @@ @group(2) @binding(0) var ring_radius: f32; @group(2) @binding(1) var jupiter_radius: f32; +@group(2) @binding(2) var ringtype: i32; const jupiter_radius_Mm: f32 = 69.911; const brightness = 0.025; +const ring_jupiter = 1; +const ring_saturn = 2; +const ring_uranus = 3; +const ring_neptune = 4; fn smooth_edge(start: f32, end: f32, value: f32) -> f32 { var x: f32 = (value - start) / (end - start); @@ -79,7 +84,8 @@ fn fragment(in: VertexOutput) -> @location(0) vec4 { return vec4(color, 0.0); } - if in.uv[0] < 0.5 { + // apply shadow + if ringtype <= ring_saturn && 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); diff --git a/src/cmd.rs b/src/cmd.rs index 0de4e32..564ef28 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -22,6 +22,11 @@ pub const ID_PLAYER: &str = "player"; pub const ID_EARTH: &str = "earth"; pub const ID_SOL: &str = "sol"; pub const ID_JUPITER: &str = "jupiter"; +pub const RING_NONE: i32 = 0; +pub const RING_JUPITER: i32 = 1; +pub const RING_SATURN: i32 = 2; +pub const RING_URANUS: i32 = 3; +pub const RING_NEPTUNE: i32 = 4; pub struct CmdPlugin; impl Plugin for CmdPlugin { @@ -110,7 +115,7 @@ struct ParserState { orbit_object_id: Option, orbit_phase: Option, has_physics: bool, - has_ring: bool, + has_ring: i32, has_aurora: bool, wants_maxrotation: Option, wants_maxvelocity: Option, @@ -178,7 +183,7 @@ impl Default for ParserState { orbit_object_id: None, orbit_phase: None, has_physics: true, - has_ring: false, + has_ring: 0, has_aurora: false, wants_maxrotation: None, wants_maxvelocity: None, @@ -484,8 +489,17 @@ pub fn load_defs(mut ew_spawn: EventWriter) { ["sun", "yes"] => { state.is_sun = true; } - ["ring", "yes"] => { - state.has_ring = true; + ["ring", "jupiter"] => { + state.has_ring = RING_JUPITER; + } + ["ring", "saturn"] => { + state.has_ring = RING_SATURN; + } + ["ring", "uranus"] => { + state.has_ring = RING_URANUS; + } + ["ring", "neptune"] => { + state.has_ring = RING_NEPTUNE; } ["aurora", "yes"] => { state.has_aurora = true; @@ -1692,7 +1706,7 @@ fn spawn_entities( load_asset(model, &mut entitycmd, &*asset_server); } - if state.has_ring { + if state.has_ring > 0 { let ring_radius = state.model_scale * (nature::JUPITER_RING_RADIUS / nature::JUPITER_RADIUS) as f32; commands.spawn(( @@ -1703,6 +1717,7 @@ fn spawn_entities( alpha_mode: AlphaMode::Blend, ring_radius: nature::JUPITER_RING_RADIUS as f32, jupiter_radius: nature::JUPITER_RADIUS as f32, + ringtype: state.has_ring, }), transform: Transform::from_translation(absolute_pos.as_vec3()), ..default() diff --git a/src/data/defs.txt b/src/data/defs.txt index 255aae9..4baaf3f 100644 --- a/src/data/defs.txt +++ b/src/data/defs.txt @@ -90,7 +90,7 @@ actor 0 0 0 displayed_mass_kg 1.8982e27 planet yes sphere yes - ring yes + ring jupiter aurora yes atmosphere jupiter physics off @@ -262,7 +262,7 @@ actor 0 0 0 name Saturn planet yes sphere yes - ring yes + ring saturn aurora yes physics off scale 58232e3 @@ -278,7 +278,7 @@ actor 0 0 0 name Uranus planet yes sphere yes - ring yes + ring uranus physics off scale 25362e3 displayed_mass_kg 8.6810e25 @@ -293,7 +293,7 @@ actor 0 0 0 name Neptune planet yes sphere yes - ring yes + ring neptune physics off scale 24622e3 displayed_mass_kg 1.02409e26 diff --git a/src/load.rs b/src/load.rs index 848922f..f3f0ea7 100644 --- a/src/load.rs +++ b/src/load.rs @@ -102,6 +102,8 @@ pub struct JupitersRing { pub ring_radius: f32, #[uniform(1)] pub jupiter_radius: f32, + #[uniform(2)] + pub ringtype: i32, } impl Material for JupitersRing {