add first draft of aurora shader
This commit is contained in:
parent
cb9fe1d500
commit
c87a68b778
25
assets/shaders/aurora.wgsl
Normal file
25
assets/shaders/aurora.wgsl
Normal file
|
@ -0,0 +1,25 @@
|
|||
#import bevy_pbr::{
|
||||
mesh_view_bindings::globals,
|
||||
forward_io::VertexOutput,
|
||||
}
|
||||
|
||||
const latitude_cutoff = 50.0;
|
||||
const tau = 6.283185307179586;
|
||||
|
||||
@fragment
|
||||
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||
let color = vec3<f32>(2.0, 6.0, 20.0);
|
||||
var alpha = 0.0;
|
||||
|
||||
let lat = 180.0 * abs(in.uv[1] - 0.5);
|
||||
let phase = in.uv[0] * 2.0 * 3.14159;
|
||||
if (lat > latitude_cutoff) {
|
||||
let y = (lat - latitude_cutoff) / (90.0 - latitude_cutoff);
|
||||
//alpha = sin(phase * 5.0) + sin(5.0 * y);
|
||||
alpha = 0.1 * clamp(-4.0 * cos(tau * sqrt(y + 0.01 * sin(phase * 20.0) + 0.1 * sin(phase))) - 3.0, 0.0, 1.0);
|
||||
alpha += 0.3 * clamp(-1000.0 * cos(tau * sqrt(y + 0.01 * sin(phase * 30.0) + 0.1 * sin(phase + 0.3))) - 992.0, 0.0, 1.0);
|
||||
alpha += 0.2 * clamp(-1000.0 * cos(tau * sqrt(-0.13 + y + 0.01 * sin(phase * 20.0) + 0.2 * sin(phase + 0.4))) - 992.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
return vec4<f32>(color, clamp(alpha, 0.0, 1.0));
|
||||
}
|
26
src/cmd.rs
26
src/cmd.rs
|
@ -106,6 +106,7 @@ struct ParserState {
|
|||
orbit_phase: Option<f64>,
|
||||
has_physics: bool,
|
||||
has_ring: bool,
|
||||
has_aurora: bool,
|
||||
wants_maxrotation: Option<f64>,
|
||||
wants_maxvelocity: Option<f64>,
|
||||
wants_tolookat_id: Option<String>,
|
||||
|
@ -169,6 +170,7 @@ impl Default for ParserState {
|
|||
orbit_phase: None,
|
||||
has_physics: true,
|
||||
has_ring: false,
|
||||
has_aurora: false,
|
||||
wants_maxrotation: None,
|
||||
wants_maxvelocity: None,
|
||||
wants_tolookat_id: None,
|
||||
|
@ -473,6 +475,9 @@ pub fn load_defs(mut ew_spawn: EventWriter<SpawnEvent>) {
|
|||
["ring", "yes"] => {
|
||||
state.has_ring = true;
|
||||
}
|
||||
["aurora", "yes"] => {
|
||||
state.has_aurora = true;
|
||||
}
|
||||
["tidally", "locked"] => {
|
||||
state.is_tidally_locked = true;
|
||||
}
|
||||
|
@ -907,6 +912,7 @@ fn spawn_entities(
|
|||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
mut materials_jupiter: ResMut<Assets<load::JupitersRing>>,
|
||||
mut materials_aurora: ResMut<Assets<load::JupitersAurora>>,
|
||||
mut id2pos: ResMut<game::Id2Pos>,
|
||||
mut achievement_tracker: ResMut<var::AchievementTracker>,
|
||||
mut ew_updateavatar: EventWriter<hud::UpdateAvatarEvent>,
|
||||
|
@ -1301,6 +1307,26 @@ fn spawn_entities(
|
|||
NotShadowReceiver,
|
||||
));
|
||||
}
|
||||
|
||||
if state.has_aurora {
|
||||
let radius = state.model_scale * 1.01;
|
||||
commands.spawn((
|
||||
world::DespawnOnPlayerDeath,
|
||||
MaterialMeshBundle {
|
||||
mesh: meshes.add(Sphere::new(radius).mesh().uv(128, 128)),
|
||||
material: materials_aurora.add(load::JupitersAurora {
|
||||
alpha_mode: AlphaMode::Blend,
|
||||
}),
|
||||
transform: Transform::from_translation(absolute_pos.as_vec3()),
|
||||
..default()
|
||||
},
|
||||
Position::new(absolute_pos),
|
||||
//Rotation::default(),
|
||||
Rotation::from(Quat::from_rotation_x(-90f32.to_radians())),
|
||||
NotShadowCaster,
|
||||
NotShadowReceiver,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ actor 0 0 0
|
|||
planet yes
|
||||
sphere yes
|
||||
ring yes
|
||||
aurora yes
|
||||
physics off
|
||||
rotationy 3.13
|
||||
rotationz 135
|
||||
|
|
16
src/load.rs
16
src/load.rs
|
@ -19,6 +19,7 @@ pub struct LoadPlugin;
|
|||
impl Plugin for LoadPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins(MaterialPlugin::<JupitersRing>::default());
|
||||
app.add_plugins(MaterialPlugin::<JupitersAurora>::default());
|
||||
app.add_plugins(MaterialPlugin::<SkyBox>::default());
|
||||
app.add_plugins(MaterialPlugin::<
|
||||
ExtendedMaterial<StandardMaterial, AsteroidSurface>,
|
||||
|
@ -103,6 +104,21 @@ impl Material for JupitersRing {
|
|||
}
|
||||
}
|
||||
|
||||
// Jupiter's Aurora
|
||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||
pub struct JupitersAurora {
|
||||
pub alpha_mode: AlphaMode,
|
||||
}
|
||||
|
||||
impl Material for JupitersAurora {
|
||||
fn fragment_shader() -> ShaderRef {
|
||||
"shaders/aurora.wgsl".into()
|
||||
}
|
||||
fn alpha_mode(&self) -> AlphaMode {
|
||||
self.alpha_mode
|
||||
}
|
||||
}
|
||||
|
||||
// Sky Box
|
||||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
||||
pub struct SkyBox {}
|
||||
|
|
Loading…
Reference in a new issue