|
|
|
|
@ -1,8 +1,14 @@
|
|
|
|
|
use bevy::core_pipeline::experimental::taa::TemporalAntiAliasSettings;
|
|
|
|
|
use bevy::core_pipeline::prepass::MotionVectorPrepass;
|
|
|
|
|
use bevy::core_pipeline::tonemapping::DebandDither;
|
|
|
|
|
use bevy::core_pipeline::Skybox;
|
|
|
|
|
use bevy::pbr::ExtendedMaterial;
|
|
|
|
|
use bevy::pbr::MaterialExtension;
|
|
|
|
|
use bevy::pbr::OpaqueRendererMethod;
|
|
|
|
|
use bevy::pbr::ScreenSpaceAmbientOcclusionBundle;
|
|
|
|
|
use bevy::prelude::*;
|
|
|
|
|
use bevy::render::render_resource::*;
|
|
|
|
|
use bevy::render::view::ColorGrading;
|
|
|
|
|
|
|
|
|
|
type MyMat = ExtendedMaterial<StandardMaterial, MatExt>;
|
|
|
|
|
|
|
|
|
|
@ -12,7 +18,9 @@ fn main() {
|
|
|
|
|
DefaultPlugins.set(ImagePlugin::default_nearest()),
|
|
|
|
|
MaterialPlugin::<MyMat>::default(),
|
|
|
|
|
))
|
|
|
|
|
.insert_resource(Msaa::Off)
|
|
|
|
|
.add_systems(Startup, setup)
|
|
|
|
|
.add_systems(Update, apply_skybox)
|
|
|
|
|
.add_systems(Update, set_scene)
|
|
|
|
|
.add_systems(Update, rotate)
|
|
|
|
|
.add_systems(Update, toggle_material.run_if(
|
|
|
|
|
@ -29,7 +37,10 @@ fn main() {
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct Root;
|
|
|
|
|
|
|
|
|
|
fn setup(mut commands: Commands) {
|
|
|
|
|
fn setup(
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
assets: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
commands.spawn((SceneBundle { ..default() }, Root));
|
|
|
|
|
|
|
|
|
|
commands.spawn(PointLightBundle {
|
|
|
|
|
@ -41,10 +52,49 @@ fn setup(mut commands: Commands) {
|
|
|
|
|
..default()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
commands.spawn(Camera3dBundle {
|
|
|
|
|
transform: Transform::from_xyz(-1.0, 1.5, 4.0).looking_at(Vec3::ZERO, Vec3::Y),
|
|
|
|
|
..default()
|
|
|
|
|
});
|
|
|
|
|
commands.spawn((
|
|
|
|
|
Camera3dBundle {
|
|
|
|
|
transform: Transform::from_xyz(-1.0, 1.5, 4.0).looking_at(Vec3::ZERO, Vec3::Y),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn apply_skybox(
|
|
|
|
|
cameras: Query<Entity, With<Camera>>,
|
|
|
|
|
mut images: ResMut<Assets<Image>>,
|
|
|
|
|
assets: Res<AssetServer>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
mut done: Local<bool>,
|
|
|
|
|
mut handle: Local<Handle<Image>>,
|
|
|
|
|
) {
|
|
|
|
|
if !*done {
|
|
|
|
|
info!("Applying skybox...");
|
|
|
|
|
*handle = assets.load("images/skybox.png");
|
|
|
|
|
if let Some(image) = images.get_mut(handle.clone()) {
|
|
|
|
|
info!("Loaded skybox image");
|
|
|
|
|
// NOTE: PNGs do not have any metadata that could indicate they contain a cubemap texture,
|
|
|
|
|
// so they appear as one texture. The following code reconfigures the texture as necessary.
|
|
|
|
|
if image.texture_descriptor.array_layer_count() == 1 {
|
|
|
|
|
image.reinterpret_stacked_2d_as_array(
|
|
|
|
|
image.texture_descriptor.size.height / image.texture_descriptor.size.width,
|
|
|
|
|
);
|
|
|
|
|
image.texture_view_descriptor = Some(TextureViewDescriptor {
|
|
|
|
|
dimension: Some(TextureViewDimension::Cube),
|
|
|
|
|
..default()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
cameras.iter().for_each(|e| {
|
|
|
|
|
commands.entity(e).insert(Skybox(handle.clone()));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
*done = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
*done = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set_scene(
|
|
|
|
|
@ -90,7 +140,6 @@ fn init_materials(
|
|
|
|
|
.clone();
|
|
|
|
|
|
|
|
|
|
base.opaque_render_method = OpaqueRendererMethod::Auto;
|
|
|
|
|
base.alpha_mode = AlphaMode::Mask(0.5);
|
|
|
|
|
|
|
|
|
|
let ext_handle = materials.add(ExtendedMaterial { base, extension });
|
|
|
|
|
|
|
|
|
|
@ -155,4 +204,4 @@ fn rotate(
|
|
|
|
|
materials.iter_mut().for_each(|(_id, m)| {
|
|
|
|
|
m.extension.cutoff = time.elapsed_seconds().sin().abs();
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|