diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index 4810606..0000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Docs -on: - push: - branches: [master] -permissions: - contents: read - pages: write - id-token: write -concurrency: - group: deploy - cancel-in-progress: false -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Install Dependencies - run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev - - name: Setup Rust - uses: dtolnay/rust-toolchain@stable - - name: Configure cache - uses: Swatinem/rust-cache@v2 - - name: Setup pages - id: pages - uses: actions/configure-pages@v4 - - name: Clean docs folder - run: cargo clean --doc - - name: Build docs - run: cargo doc --no-deps - - name: Add redirect - run: echo '' > target/doc/index.html - - name: Remove lock file - run: rm target/doc/.lock - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: target/doc - deploy: - name: Deploy - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 diff --git a/Cargo.toml b/Cargo.toml index 87ccf91..2d99b41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_outline_post_process" -version = "0.1.3" +version = "0.2.0" edition = "2021" [dependencies.bevy] diff --git a/README.md b/README.md index a494357..c9e6e0f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ![Build](https://img.shields.io/github/actions/workflow/status/exvacuum/bevy_outline_post_process/rust.yml) [![Docs](https://img.shields.io/website?url=https%3A%2F%2Fexvacuum.github.io%2Fbevy_outline_post_process%2F&label=docs)](https://exvacuum.github.io/bevy_outline_post_process) -A plugin for the [Bevy](https://bevyengine.org) engine which adds an outline post-processing effect. +A plugin for the [Bevy](https://bevyengine.org) engine which adds an outline post-processing effect. Optionally supports adaptive outlining, so darker areas are outlined in white rather than black, based on luminance. Note: This is a full-screen post process effect and cannot be enabled/disabled for specific objects. @@ -14,16 +14,13 @@ Note: This is a full-screen post process effect and cannot be enabled/disabled f ![](./doc/screenshot_smooth.png) Configuration Used: ```rs -bevy_outline_post_process::components::OutlinePostProcessSettings { - weight: 2.0, - threshold: 0.0, -} +bevy_outline_post_process::components::OutlinePostProcessSettings::new(2.0, 0.0, false); ``` ## Compatibility | Crate Version | Bevy Version | |--- |--- | -| 0.1 | 0.13 | +| 0.2 | 0.13 | ## Installation @@ -56,10 +53,7 @@ When spawning a camera: commands.spawn(( // Camera3dBundle... NormalPrepass, - bevy_outline_post_process::components::OutlinePostProcessSettings { - weight: 2.0, - threshold: 0.0, - } + bevy_outline_post_process::components::OutlinePostProcessSettings::new(2.0, 0.0, false); )); ``` diff --git a/assets/shaders/outline_post_process.wgsl b/assets/shaders/outline_post_process.wgsl index 79c116f..5e0bf9c 100644 --- a/assets/shaders/outline_post_process.wgsl +++ b/assets/shaders/outline_post_process.wgsl @@ -3,9 +3,7 @@ struct OutlinePostProcessSettings { weight: f32, threshold: f32, -#ifdef SIXTEEN_BYTE_ALIGNMENT - _padding: vec2, -#endif + adaptive: u32, } @group(0) @binding(0) var screen_texture: texture_2d; @@ -39,7 +37,11 @@ fn fragment( let delta_clipped = clamp((delta_raw * 2.0) - settings.threshold, 0.0, 1.0); - let outline = vec4f(delta_clipped, delta_clipped, delta_clipped, 0.0); + var outline = vec4f(delta_clipped, delta_clipped, delta_clipped, 0.0); + let luma = (0.2126 * screen_color.r + 0.7152 * screen_color.g + 0.0722 * screen_color.b); + if settings.adaptive != 0 && luma < 0.5 { + outline = outline * -1; + } return screen_color - outline; } diff --git a/src/components.rs b/src/components.rs index 49f4684..7f572e3 100644 --- a/src/components.rs +++ b/src/components.rs @@ -5,11 +5,34 @@ use bevy::{ /// Component which, when inserted into an entity with a camera and normal prepass, enables an outline effect for that /// camera. -#[derive(Component, ShaderType, ExtractComponent, PartialEq, Clone, Default)] +#[derive(Component, ShaderType, ExtractComponent, PartialEq, Clone)] pub struct OutlinePostProcessSettings { /// Weight of outlines in pixels. - pub weight: f32, + weight: f32, /// A threshold for normal differences, values below this threshold will not become outlines. /// Higher values will result in more outlines which may look better on smooth surfaces. - pub threshold: f32, + threshold: f32, + /// Whether to use adaptive outlines. White outlines will be drawn around darker objects, while black ones will be drawn around lighter ones. + adaptive: u32, } + +impl OutlinePostProcessSettings { + /// Create a new instance with the given settings + pub fn new(weight: f32, threshold: f32, adaptive: bool) -> Self { + Self { + weight, + threshold, + adaptive: adaptive as u32, + } + } +} + +impl Default for OutlinePostProcessSettings { + fn default() -> Self { + Self { + weight: 1.0, + threshold: 0.0, + adaptive: 0 + } + } +} \ No newline at end of file