chore: try to fix an error...needs fixing
This commit is contained in:
parent
08c4cbcbe8
commit
249f61f973
98
flake.lock
98
flake.lock
|
@ -1,98 +0,0 @@
|
|||
{
|
||||
"nodes": {
|
||||
"fenix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"rust-analyzer-src": "rust-analyzer-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1697178193,
|
||||
"narHash": "sha256-LBDLUWlwSDPMA1Ui9wC9YcQEnJL0UP627RoUmtz4TTo=",
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"rev": "ff6c27356cbde594e598e388a32d79ef79cbe1b1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1697009197,
|
||||
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"fenix": "fenix",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"utils": "utils"
|
||||
}
|
||||
},
|
||||
"rust-analyzer-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1697098808,
|
||||
"narHash": "sha256-OfatUxSwuzYd17IDy9eNOedwioq0dX6mOuiTghKol3s=",
|
||||
"owner": "rust-lang",
|
||||
"repo": "rust-analyzer",
|
||||
"rev": "84e1d273439413ab4ca1718db0b574dffba443ce",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "rust-lang",
|
||||
"ref": "nightly",
|
||||
"repo": "rust-analyzer",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
28
flake.nix
28
flake.nix
|
@ -1,27 +1,30 @@
|
|||
{
|
||||
description = "Rust development template using fenix";
|
||||
description = "Rust development environment for Aspiration using fenix";
|
||||
|
||||
inputs = {
|
||||
fenix = {
|
||||
url = "github:nix-community/fenix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.nixpkgs.follows = "nixpkgs-unstable";
|
||||
};
|
||||
utils.url = "github:numtide/flake-utils";
|
||||
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
nixgl.url = "github:guibou/nixGL";
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
nixpkgs-unstable,
|
||||
utils,
|
||||
fenix,
|
||||
nixgl,
|
||||
...
|
||||
}:
|
||||
utils.lib.eachDefaultSystem
|
||||
(
|
||||
system: let
|
||||
pkgs = import nixpkgs {
|
||||
pkgs = import nixpkgs-unstable {
|
||||
inherit system;
|
||||
overlays = [fenix.overlays.default];
|
||||
overlays = [fenix.overlays.default nixgl.overlay];
|
||||
};
|
||||
toolchain = pkgs.fenix.complete;
|
||||
in rec
|
||||
|
@ -33,7 +36,7 @@
|
|||
inherit (toolchain) cargo rustc;
|
||||
})
|
||||
.buildRustPackage {
|
||||
pname = "template";
|
||||
pname = "aspiration";
|
||||
version = "0.1.0";
|
||||
src = ./.;
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
|
@ -46,7 +49,14 @@
|
|||
apps.default = utils.lib.mkApp {drv = packages.default;};
|
||||
|
||||
# Used by `nix develop`
|
||||
devShells.default = pkgs.mkShell {
|
||||
devShells.default = pkgs.mkShell rec {
|
||||
shellHook = ''export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath [
|
||||
pkgs.vulkan-loader
|
||||
pkgs.xorg.libX11
|
||||
pkgs.xorg.libXcursor
|
||||
pkgs.xorg.libXi
|
||||
pkgs.xorg.libXrandr
|
||||
]}"'';
|
||||
# Use nightly cargo & rustc provided by fenix. Add for packages for the dev shell here
|
||||
buildInputs = with pkgs; [
|
||||
(with toolchain; [
|
||||
|
@ -55,11 +65,13 @@
|
|||
xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr # To use the x11 feature
|
||||
libxkbcommon wayland # To use the wayland feature
|
||||
|
||||
udev alsa-lib vulkan-loader
|
||||
pkgs.nixgl.nixVulkanIntel
|
||||
|
||||
mold
|
||||
clang
|
||||
pkg-config
|
||||
];
|
||||
|
||||
# Specify the rust-src path (many editors rely on this)
|
||||
RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library";
|
||||
};
|
||||
|
|
208
src/main.rs
208
src/main.rs
|
@ -1,3 +1,209 @@
|
|||
//! Illustrates bloom post-processing in 2d.
|
||||
|
||||
use bevy::{
|
||||
core_pipeline::{
|
||||
bloom::{BloomCompositeMode, BloomSettings},
|
||||
tonemapping::Tonemapping,
|
||||
},
|
||||
prelude::*,
|
||||
sprite::MaterialMesh2dBundle,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, update_bloom_settings)
|
||||
.run();
|
||||
}
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
) {
|
||||
commands.spawn((
|
||||
Camera2dBundle {
|
||||
camera: Camera {
|
||||
hdr: true, // 1. HDR is required for bloom
|
||||
..default()
|
||||
},
|
||||
tonemapping: Tonemapping::TonyMcMapface, // 2. Using a tonemapper that desaturates to white is recommended
|
||||
..default()
|
||||
},
|
||||
BloomSettings::default(), // 3. Enable bloom for the camera
|
||||
));
|
||||
|
||||
// Sprite
|
||||
commands.spawn(SpriteBundle {
|
||||
texture: asset_server.load("branding/bevy_bird_dark.png"),
|
||||
sprite: Sprite {
|
||||
color: Color::rgb(5.0, 5.0, 5.0), // 4. Put something bright in a dark environment to see the effect
|
||||
custom_size: Some(Vec2::splat(160.0)),
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
});
|
||||
|
||||
// Circle mesh
|
||||
commands.spawn(MaterialMesh2dBundle {
|
||||
mesh: meshes.add(shape::Circle::new(100.).into()).into(),
|
||||
// 4. Put something bright in a dark environment to see the effect
|
||||
material: materials.add(ColorMaterial::from(Color::rgb(7.5, 0.0, 7.5))),
|
||||
transform: Transform::from_translation(Vec3::new(-200., 0., 0.)),
|
||||
..default()
|
||||
});
|
||||
|
||||
// Hexagon mesh
|
||||
commands.spawn(MaterialMesh2dBundle {
|
||||
mesh: meshes
|
||||
.add(shape::RegularPolygon::new(100., 6).into())
|
||||
.into(),
|
||||
// 4. Put something bright in a dark environment to see the effect
|
||||
material: materials.add(ColorMaterial::from(Color::rgb(6.25, 9.4, 9.1))),
|
||||
transform: Transform::from_translation(Vec3::new(200., 0., 0.)),
|
||||
..default()
|
||||
});
|
||||
|
||||
// UI
|
||||
commands.spawn(
|
||||
TextBundle::from_section(
|
||||
"",
|
||||
TextStyle {
|
||||
font_size: 18.0,
|
||||
color: Color::WHITE,
|
||||
..default()
|
||||
},
|
||||
)
|
||||
.with_style(Style {
|
||||
position_type: PositionType::Absolute,
|
||||
bottom: Val::Px(10.0),
|
||||
left: Val::Px(10.0),
|
||||
..default()
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
fn update_bloom_settings(
|
||||
mut camera: Query<(Entity, Option<&mut BloomSettings>), With<Camera>>,
|
||||
mut text: Query<&mut Text>,
|
||||
mut commands: Commands,
|
||||
keycode: Res<Input<KeyCode>>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let bloom_settings = camera.single_mut();
|
||||
let mut text = text.single_mut();
|
||||
let text = &mut text.sections[0].value;
|
||||
|
||||
match bloom_settings {
|
||||
(entity, Some(mut bloom_settings)) => {
|
||||
*text = "BloomSettings (Toggle: Space)\n".to_string();
|
||||
text.push_str(&format!("(Q/A) Intensity: {}\n", bloom_settings.intensity));
|
||||
text.push_str(&format!(
|
||||
"(W/S) Low-frequency boost: {}\n",
|
||||
bloom_settings.low_frequency_boost
|
||||
));
|
||||
text.push_str(&format!(
|
||||
"(E/D) Low-frequency boost curvature: {}\n",
|
||||
bloom_settings.low_frequency_boost_curvature
|
||||
));
|
||||
text.push_str(&format!(
|
||||
"(R/F) High-pass frequency: {}\n",
|
||||
bloom_settings.high_pass_frequency
|
||||
));
|
||||
text.push_str(&format!(
|
||||
"(T/G) Mode: {}\n",
|
||||
match bloom_settings.composite_mode {
|
||||
BloomCompositeMode::EnergyConserving => "Energy-conserving",
|
||||
BloomCompositeMode::Additive => "Additive",
|
||||
}
|
||||
));
|
||||
text.push_str(&format!(
|
||||
"(Y/H) Threshold: {}\n",
|
||||
bloom_settings.prefilter_settings.threshold
|
||||
));
|
||||
text.push_str(&format!(
|
||||
"(U/J) Threshold softness: {}\n",
|
||||
bloom_settings.prefilter_settings.threshold_softness
|
||||
));
|
||||
|
||||
if keycode.just_pressed(KeyCode::Space) {
|
||||
commands.entity(entity).remove::<BloomSettings>();
|
||||
}
|
||||
|
||||
let dt = time.delta_seconds();
|
||||
|
||||
if keycode.pressed(KeyCode::A) {
|
||||
bloom_settings.intensity -= dt / 10.0;
|
||||
}
|
||||
if keycode.pressed(KeyCode::Q) {
|
||||
bloom_settings.intensity += dt / 10.0;
|
||||
}
|
||||
bloom_settings.intensity = bloom_settings.intensity.clamp(0.0, 1.0);
|
||||
|
||||
if keycode.pressed(KeyCode::S) {
|
||||
bloom_settings.low_frequency_boost -= dt / 10.0;
|
||||
}
|
||||
if keycode.pressed(KeyCode::W) {
|
||||
bloom_settings.low_frequency_boost += dt / 10.0;
|
||||
}
|
||||
bloom_settings.low_frequency_boost = bloom_settings.low_frequency_boost.clamp(0.0, 1.0);
|
||||
|
||||
if keycode.pressed(KeyCode::D) {
|
||||
bloom_settings.low_frequency_boost_curvature -= dt / 10.0;
|
||||
}
|
||||
if keycode.pressed(KeyCode::E) {
|
||||
bloom_settings.low_frequency_boost_curvature += dt / 10.0;
|
||||
}
|
||||
bloom_settings.low_frequency_boost_curvature =
|
||||
bloom_settings.low_frequency_boost_curvature.clamp(0.0, 1.0);
|
||||
|
||||
if keycode.pressed(KeyCode::F) {
|
||||
bloom_settings.high_pass_frequency -= dt / 10.0;
|
||||
}
|
||||
if keycode.pressed(KeyCode::R) {
|
||||
bloom_settings.high_pass_frequency += dt / 10.0;
|
||||
}
|
||||
bloom_settings.high_pass_frequency = bloom_settings.high_pass_frequency.clamp(0.0, 1.0);
|
||||
|
||||
if keycode.pressed(KeyCode::G) {
|
||||
bloom_settings.composite_mode = BloomCompositeMode::Additive;
|
||||
}
|
||||
if keycode.pressed(KeyCode::T) {
|
||||
bloom_settings.composite_mode = BloomCompositeMode::EnergyConserving;
|
||||
}
|
||||
|
||||
if keycode.pressed(KeyCode::H) {
|
||||
bloom_settings.prefilter_settings.threshold -= dt;
|
||||
}
|
||||
if keycode.pressed(KeyCode::Y) {
|
||||
bloom_settings.prefilter_settings.threshold += dt;
|
||||
}
|
||||
bloom_settings.prefilter_settings.threshold =
|
||||
bloom_settings.prefilter_settings.threshold.max(0.0);
|
||||
|
||||
if keycode.pressed(KeyCode::J) {
|
||||
bloom_settings.prefilter_settings.threshold_softness -= dt / 10.0;
|
||||
}
|
||||
if keycode.pressed(KeyCode::U) {
|
||||
bloom_settings.prefilter_settings.threshold_softness += dt / 10.0;
|
||||
}
|
||||
bloom_settings.prefilter_settings.threshold_softness = bloom_settings
|
||||
.prefilter_settings
|
||||
.threshold_softness
|
||||
.clamp(0.0, 1.0);
|
||||
}
|
||||
|
||||
(entity, None) => {
|
||||
*text = "Bloom: Off (Toggle: Space)".to_string();
|
||||
|
||||
if keycode.just_pressed(KeyCode::Space) {
|
||||
commands.entity(entity).insert(BloomSettings::default());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue