add ring types to shader, remove shadow from ring for uranus/neptune

This commit is contained in:
yuni 2024-11-30 01:38:01 +01:00
parent 2310fdf83d
commit c4d78c1116
4 changed files with 33 additions and 10 deletions

View file

@ -5,9 +5,14 @@
@group(2) @binding(0) var<uniform> ring_radius: f32; @group(2) @binding(0) var<uniform> ring_radius: f32;
@group(2) @binding(1) var<uniform> jupiter_radius: f32; @group(2) @binding(1) var<uniform> jupiter_radius: f32;
@group(2) @binding(2) var<uniform> ringtype: i32;
const jupiter_radius_Mm: f32 = 69.911; const jupiter_radius_Mm: f32 = 69.911;
const brightness = 0.025; 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 { fn smooth_edge(start: f32, end: f32, value: f32) -> f32 {
var x: f32 = (value - start) / (end - start); var x: f32 = (value - start) / (end - start);
@ -79,7 +84,8 @@ fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(color, 0.0); return vec4<f32>(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 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 side_dist = abs(in.uv[1] - 0.5);

View file

@ -22,6 +22,11 @@ pub const ID_PLAYER: &str = "player";
pub const ID_EARTH: &str = "earth"; pub const ID_EARTH: &str = "earth";
pub const ID_SOL: &str = "sol"; pub const ID_SOL: &str = "sol";
pub const ID_JUPITER: &str = "jupiter"; 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; pub struct CmdPlugin;
impl Plugin for CmdPlugin { impl Plugin for CmdPlugin {
@ -110,7 +115,7 @@ struct ParserState {
orbit_object_id: Option<String>, orbit_object_id: Option<String>,
orbit_phase: Option<f64>, orbit_phase: Option<f64>,
has_physics: bool, has_physics: bool,
has_ring: bool, has_ring: i32,
has_aurora: bool, has_aurora: bool,
wants_maxrotation: Option<f64>, wants_maxrotation: Option<f64>,
wants_maxvelocity: Option<f64>, wants_maxvelocity: Option<f64>,
@ -178,7 +183,7 @@ impl Default for ParserState {
orbit_object_id: None, orbit_object_id: None,
orbit_phase: None, orbit_phase: None,
has_physics: true, has_physics: true,
has_ring: false, has_ring: 0,
has_aurora: false, has_aurora: false,
wants_maxrotation: None, wants_maxrotation: None,
wants_maxvelocity: None, wants_maxvelocity: None,
@ -484,8 +489,17 @@ pub fn load_defs(mut ew_spawn: EventWriter<SpawnEvent>) {
["sun", "yes"] => { ["sun", "yes"] => {
state.is_sun = true; state.is_sun = true;
} }
["ring", "yes"] => { ["ring", "jupiter"] => {
state.has_ring = true; 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"] => { ["aurora", "yes"] => {
state.has_aurora = true; state.has_aurora = true;
@ -1692,7 +1706,7 @@ fn spawn_entities(
load_asset(model, &mut entitycmd, &*asset_server); load_asset(model, &mut entitycmd, &*asset_server);
} }
if state.has_ring { if state.has_ring > 0 {
let ring_radius = let ring_radius =
state.model_scale * (nature::JUPITER_RING_RADIUS / nature::JUPITER_RADIUS) as f32; state.model_scale * (nature::JUPITER_RING_RADIUS / nature::JUPITER_RADIUS) as f32;
commands.spawn(( commands.spawn((
@ -1703,6 +1717,7 @@ fn spawn_entities(
alpha_mode: AlphaMode::Blend, alpha_mode: AlphaMode::Blend,
ring_radius: nature::JUPITER_RING_RADIUS as f32, ring_radius: nature::JUPITER_RING_RADIUS as f32,
jupiter_radius: nature::JUPITER_RADIUS as f32, jupiter_radius: nature::JUPITER_RADIUS as f32,
ringtype: state.has_ring,
}), }),
transform: Transform::from_translation(absolute_pos.as_vec3()), transform: Transform::from_translation(absolute_pos.as_vec3()),
..default() ..default()

View file

@ -90,7 +90,7 @@ actor 0 0 0
displayed_mass_kg 1.8982e27 displayed_mass_kg 1.8982e27
planet yes planet yes
sphere yes sphere yes
ring yes ring jupiter
aurora yes aurora yes
atmosphere jupiter atmosphere jupiter
physics off physics off
@ -262,7 +262,7 @@ actor 0 0 0
name Saturn name Saturn
planet yes planet yes
sphere yes sphere yes
ring yes ring saturn
aurora yes aurora yes
physics off physics off
scale 58232e3 scale 58232e3
@ -278,7 +278,7 @@ actor 0 0 0
name Uranus name Uranus
planet yes planet yes
sphere yes sphere yes
ring yes ring uranus
physics off physics off
scale 25362e3 scale 25362e3
displayed_mass_kg 8.6810e25 displayed_mass_kg 8.6810e25
@ -293,7 +293,7 @@ actor 0 0 0
name Neptune name Neptune
planet yes planet yes
sphere yes sphere yes
ring yes ring neptune
physics off physics off
scale 24622e3 scale 24622e3
displayed_mass_kg 1.02409e26 displayed_mass_kg 1.02409e26

View file

@ -102,6 +102,8 @@ pub struct JupitersRing {
pub ring_radius: f32, pub ring_radius: f32,
#[uniform(1)] #[uniform(1)]
pub jupiter_radius: f32, pub jupiter_radius: f32,
#[uniform(2)]
pub ringtype: i32,
} }
impl Material for JupitersRing { impl Material for JupitersRing {