Skip to content

Commit

Permalink
Merge branch 'feat/pixels'
Browse files Browse the repository at this point in the history
  • Loading branch information
thombruce committed Oct 4, 2023
2 parents d431de4 + 7f124cc commit f6925af
Show file tree
Hide file tree
Showing 7 changed files with 690 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- (Optional) pixelation shader for retro effect
- (Optional) chromatic aberration shader

## [0.0.10] - 2023-10-04

### Added
Expand Down
27 changes: 27 additions & 0 deletions assets/shaders/chromatic_aberration.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#import bevy_pbr::utils
#import bevy_core_pipeline::fullscreen_vertex_shader FullscreenVertexOutput

@group(0) @binding(0) var screen_texture: texture_2d<f32>;
@group(0) @binding(1) var texture_sampler: sampler;
struct ChromaticAberrationSettings {
intensity: f32,
#ifdef SIXTEEN_BYTE_ALIGNMENT
// WebGL2 structs must be 16 byte aligned.
_webgl2_padding: vec3<f32>
#endif
}
@group(0) @binding(2) var<uniform> settings: ChromaticAberrationSettings;

@fragment
fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
// Chromatic aberration strength
let offset_strength = settings.intensity;

// Sample each color channel with an arbitrary shift
return vec4<f32>(
textureSample(screen_texture, texture_sampler, in.uv + vec2<f32>(offset_strength, -offset_strength)).r,
textureSample(screen_texture, texture_sampler, in.uv + vec2<f32>(-offset_strength, 0.0)).g,
textureSample(screen_texture, texture_sampler, in.uv + vec2<f32>(0.0, offset_strength)).b,
1.0
);
}
22 changes: 20 additions & 2 deletions src/camera.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
use bevy::prelude::*;

#[allow(unused_imports)]
use crate::shaders::{
chromatic_aberration::{ChromaticAberrationPlugin, ChromaticAberrationSettings},
pixelate::{PixelatePlugin, PixelateSettings},
};

use crate::{ship::Ship, state::AppState};

pub struct CameraPlugin;
impl Plugin for CameraPlugin {
fn build(&self, app: &mut App) {
// app.add_plugins(PixelatePlugin);
// app.add_plugins(ChromaticAberrationPlugin);
app.add_systems(Startup, setup);
app.add_systems(Update, follow_player.run_if(in_state(AppState::Active)));
}
}

fn setup(mut commands: Commands) {
// Spawns game camera
commands.spawn((Camera2dBundle::default(), Name::new("Main Camera")));
commands.spawn((
Camera2dBundle::default(),
PixelateSettings {
block_size: 3.25,
..default()
},
ChromaticAberrationSettings {
intensity: 0.001,
..default()
},
Name::new("Main Camera"),
));
}

pub fn follow_player(
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod orbit;
mod pause;
mod planet;
mod planetary_system;
mod shaders;
mod ship;
mod star;
mod state;
Expand Down Expand Up @@ -67,7 +68,7 @@ fn main() {

#[cfg(debug_assertions)]
app.add_plugins((
RapierDebugRenderPlugin::default(),
// RapierDebugRenderPlugin::default(),
WorldInspectorPlugin::new(),
));

Expand Down
Loading

0 comments on commit f6925af

Please sign in to comment.