2024-04-16 14:27:17 +00:00
|
|
|
use bevy::prelude::*;
|
|
|
|
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
|
2024-04-16 16:28:15 +00:00
|
|
|
use bevy::pbr::{ExtendedMaterial, MaterialExtension, OpaqueRendererMethod};
|
2024-04-16 14:27:17 +00:00
|
|
|
|
2024-04-16 14:41:15 +00:00
|
|
|
pub struct ShadingPlugin;
|
|
|
|
impl Plugin for ShadingPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_plugins(MaterialPlugin::<JupitersRing>::default());
|
2024-04-17 02:02:40 +00:00
|
|
|
app.add_plugins(MaterialPlugin::<SkyBox>::default());
|
2024-04-16 16:28:15 +00:00
|
|
|
app.add_plugins(MaterialPlugin::<ExtendedMaterial<StandardMaterial, AsteroidSurface, >>::default());
|
2024-04-16 14:41:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-17 02:02:40 +00:00
|
|
|
// Jupiter's Ring
|
2024-04-16 14:27:17 +00:00
|
|
|
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
|
|
|
pub struct JupitersRing {
|
|
|
|
pub alpha_mode: AlphaMode,
|
|
|
|
#[uniform(0)]
|
|
|
|
pub ring_radius: f32,
|
|
|
|
#[uniform(1)]
|
|
|
|
pub jupiter_radius: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Material for JupitersRing {
|
|
|
|
fn fragment_shader() -> ShaderRef {
|
|
|
|
"shaders/jupiters_rings.wgsl".into()
|
|
|
|
}
|
|
|
|
fn alpha_mode(&self) -> AlphaMode {
|
|
|
|
self.alpha_mode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-17 02:02:40 +00:00
|
|
|
// Sky Box
|
|
|
|
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
|
|
|
pub struct SkyBox {}
|
|
|
|
impl Material for SkyBox {
|
|
|
|
fn fragment_shader() -> ShaderRef {
|
|
|
|
"shaders/skybox.wgsl".into()
|
|
|
|
}
|
|
|
|
}
|
2024-04-16 14:40:20 +00:00
|
|
|
|
2024-04-17 02:02:40 +00:00
|
|
|
// Asteroid Surface
|
2024-04-16 16:28:15 +00:00
|
|
|
#[derive(Asset, Reflect, AsBindGroup, Debug, Clone)]
|
2024-04-16 14:40:20 +00:00
|
|
|
pub struct AsteroidSurface {
|
2024-04-16 16:28:15 +00:00
|
|
|
#[uniform(100)]
|
|
|
|
quantize_steps: u32
|
2024-04-16 14:40:20 +00:00
|
|
|
}
|
|
|
|
|
2024-04-16 16:28:15 +00:00
|
|
|
impl MaterialExtension for AsteroidSurface {
|
2024-04-16 14:40:20 +00:00
|
|
|
fn fragment_shader() -> ShaderRef {
|
|
|
|
"shaders/material_asteroid.wgsl".into()
|
|
|
|
}
|
2024-04-16 16:28:15 +00:00
|
|
|
fn deferred_fragment_shader() -> ShaderRef {
|
|
|
|
"shaders/material_asteroid.wgsl".into()
|
|
|
|
}
|
2024-04-16 14:40:20 +00:00
|
|
|
}
|
|
|
|
|
2024-04-16 16:28:15 +00:00
|
|
|
impl AsteroidSurface {
|
|
|
|
pub fn material() -> ExtendedMaterial<StandardMaterial, AsteroidSurface> {
|
|
|
|
ExtendedMaterial {
|
|
|
|
base: StandardMaterial {
|
|
|
|
base_color: Color::rgb(0.29, 0.255, 0.208),
|
|
|
|
perceptual_roughness: 1.0,
|
|
|
|
opaque_render_method: OpaqueRendererMethod::Auto,
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
extension: Self::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl Default for AsteroidSurface {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
quantize_steps: 3,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|