Skip to content

Commit

Permalink
Merge pull request #1 from janhohenheim/bevy-0.14.0-rc.2
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim authored Jun 11, 2024
2 parents 52aee5c + 80c05a5 commit 7a92168
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 30 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_wind_waker_shader"
version = "0.1.2"
version = "0.2.0-rc"
authors = ["Jan Hohenheim <[email protected]>"]
edition = "2021"
exclude = ["./assets/"]
Expand All @@ -11,11 +11,11 @@ keywords = ["bevy", "shader", "zelda", "toon", "wind-waker"]
categories = ["game-development"]

[dependencies.bevy]
version = "0.13"
version = "0.14.0-rc.2"
default-features = false
features = ["png", "bevy_asset", "bevy_pbr", "bevy_gltf"]

[dev-dependencies.bevy]
version = "0.13"
version = "0.14.0-rc.2"
default-features = true
features = ["multi-threaded", "file_watcher"]
features = ["multi_threaded", "file_watcher"]
25 changes: 10 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,33 @@

# Wind Waker Shader

[![crates.io](https://img.shields.io/crates/v/bevy_wind_waker_shader)](https://crates.io/crates/bevy_wind_waker_shader)
[![docs.rs](https://docs.rs/bevy_wind_waker_shader/badge.svg)](https://docs.rs/bevy_wind_waker_shader)

A toon shader that looks like the one used for characters in The Legend of Zelda: The Wind Waker.
A toon shader that looks like the one used for characters in The Legend of Zelda: The Wind Waker.
The main code is taken from the ideas presented in [this video](https://www.youtube.com/watch?v=mnxs6CR6Zrk).


## Showcase

Sphere:

![Sphere](https://github.com/janhohenheim/bevy_wind_waker_shader/assets/9047632/c5493f3e-fd09-4795-b62c-aa6b33a23089)


Scene throughout day:


<https://github.com/janhohenheim/bevy_wind_waker_shader/assets/9047632/80aa9851-f425-4439-88f1-558918caa9f1>



Scene in daylight:

![Scene in daylight](https://github.com/janhohenheim/bevy_wind_waker_shader/assets/9047632/664c3830-c053-408d-9444-29a10004c60e)



Scene at night:

![Scene at night](https://github.com/janhohenheim/bevy_wind_waker_shader/assets/9047632/4e483e73-2c8e-4a0c-a9cf-c4ea8b182a4f)



## Functionality

The shader has the following properties:

- It is a toon shader with only two colors: the highlight and the shadow.
- The edge between the two colors is not entirely hard but has an ever-so-slight gradient.
- The color palette used is based on the time of day and the weather.
Expand All @@ -45,7 +36,9 @@ The shader has the following properties:
All colors and the texture mask are taken from The Legend of Zelda: The Wind Waker.

Differences to The Wind Waker:
- This shader supports multiple light sources, like in Breath of the Wild. The original Wind Waker only supports a single light source.

- This shader supports multiple light sources, like in Breath of the Wild. The original Wind Waker only supports a
single light source.
- The rim highlight also comes from Breath of the Wild.
- The Wind Waker uses even more weather conditions, but I find most of them too specific to include in this shader.

Expand Down Expand Up @@ -79,7 +72,9 @@ fn spawn_character(mut commands: Commands, asset_server: Res<AssetServer>) {
```

## Compatibility
| bevy | bevy_wind_waker_shader |
|------|------------------------|
| 0.13 | 0.1 |

| bevy | bevy_wind_waker_shader |
|-------------|------------------------|
| 0.14.0-rc.2 | 0.2-rc |
| 0.13 | 0.1 |

18 changes: 9 additions & 9 deletions src/components.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::asset::{Asset, Handle};
use bevy::pbr::{MaterialExtension, StandardMaterial};
use bevy::prelude::{Color, Component, Image, Reflect, Shader};
use bevy::prelude::*;
use bevy::render::render_resource::{AsBindGroup, ShaderRef};

pub(crate) const SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(4_326_875_112_478_868_553);
Expand All @@ -21,13 +21,13 @@ pub struct WindWakerShader {
mask: Handle<Image>,
/// The parts of the model that are facing the light source and are not in shadow.
#[uniform(102)]
pub highlight_color: Color,
pub highlight_color: LinearRgba,
/// The parts of the model that are not facing the light source and are in shadow.
#[uniform(103)]
pub shadow_color: Color,
pub shadow_color: LinearRgba,
/// The color of the edge of the model, which gets a slight specular highlight to make the model pop.
#[uniform(104)]
pub rim_color: Color,
pub rim_color: LinearRgba,
}

impl Default for WindWakerShader {
Expand Down Expand Up @@ -135,16 +135,16 @@ impl WindWakerShaderBuilder {
};
let highlight_color = self
.override_highlight_color
.unwrap_or_else(|| Color::hex(highlight_hex).unwrap());
.unwrap_or_else(|| Srgba::hex(highlight_hex).unwrap().into());
let shadow_color = self
.override_shadow_color
.unwrap_or_else(|| Color::hex(shadow_hex).unwrap());
.unwrap_or_else(|| Srgba::hex(shadow_hex).unwrap().into());
let rim_color = self.override_rim_color.unwrap_or(Color::WHITE);
WindWakerShader {
mask: TEXTURE_HANDLE.clone(),
highlight_color,
shadow_color,
rim_color,
highlight_color: highlight_color.into(),
shadow_color: shadow_color.into(),
rim_color: rim_color.into(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ impl Plugin for WindWakerShaderPlugin {
render_asset_usages,
)
.unwrap();
app.world
app.world_mut()
.resource_mut::<Assets<Image>>()
.insert(TEXTURE_HANDLE, img);
.insert(TEXTURE_HANDLE.id(), img);

app.add_plugins(MaterialPlugin::<crate::ExtendedMaterial>::default())
.add_systems(
Expand Down

0 comments on commit 7a92168

Please sign in to comment.