outfly/src/shading.rs

88 lines
3.1 KiB
Rust
Raw Normal View History

2024-04-21 16:23:40 +00:00
// ▄████████▄ + ███ + ▄█████████ ███ +
// ███▀ ▀███ + + ███ ███▀ + ███ + +
// ███ + ███ ███ ███ █████████ ███ ███ ███ ███
2024-04-21 17:34:00 +00:00
// ███ +███ ███ ███ ███ ███▐██████ ███ ███ ███
2024-04-21 16:23:40 +00:00
// ███ + ███ ███+ ███ +███ ███ + ███ ███ + ███
// ███▄ ▄███ ███▄ ███ ███ + ███ + ███ ███▄ ███
// ▀████████▀ + ▀███████ ███▄ ███▄ ▀████ ▀███████
// + + + ███
// + ▀████████████████████████████████████████████████████▀
2024-04-16 14:27:17 +00:00
use bevy::prelude::*;
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
use bevy::pbr::{ExtendedMaterial, MaterialExtension, OpaqueRendererMethod};
2024-04-16 14:27:17 +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());
app.add_plugins(MaterialPlugin::<ExtendedMaterial<StandardMaterial, AsteroidSurface, >>::default());
}
}
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-17 02:02:40 +00:00
// Asteroid Surface
#[derive(Asset, Reflect, AsBindGroup, Debug, Clone)]
pub struct AsteroidSurface {
#[uniform(100)]
quantize_steps: u32
}
impl MaterialExtension for AsteroidSurface {
fn fragment_shader() -> ShaderRef {
"shaders/material_asteroid.wgsl".into()
}
fn deferred_fragment_shader() -> ShaderRef {
"shaders/material_asteroid.wgsl".into()
}
}
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,
}
}
}