Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream bevy_color_blindness #5606

Closed
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ default = [
"animation",
"bevy_asset",
"bevy_audio",
"bevy_color_blindness",
"bevy_gilrs",
"bevy_scene",
"bevy_winit",
Expand Down Expand Up @@ -57,6 +58,7 @@ render = [
bevy_animation = ["bevy_internal/bevy_animation"]
bevy_asset = ["bevy_internal/bevy_asset"]
bevy_audio = ["bevy_internal/bevy_audio"]
bevy_color_blindness = ["bevy_internal/bevy_color_blindness"]
bevy_core_pipeline = ["bevy_internal/bevy_core_pipeline"]
bevy_dynamic_plugin = ["bevy_internal/bevy_dynamic_plugin"]
bevy_gilrs = ["bevy_internal/bevy_gilrs"]
Expand Down Expand Up @@ -484,6 +486,17 @@ description = "Showcases wireframe rendering"
category = "3D Rendering"
wasm = true

# Accessibility
[[example]]
name = "color_blindness_simulation"
path = "examples/accessibility/color_blindness_simulation.rs"

[package.metadata.example.color_blindness_simulation]
name = "Color Blindness Simulation"
description = "Modify your app's rendering output to simulate color blindness"
category = "Accessibility"
wasm = true

# Animation
[[example]]
name = "animated_fox"
Expand Down
28 changes: 28 additions & 0 deletions crates/bevy_color_blindness/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "bevy_color_blindness"
version = "0.9.0-dev"
edition = "2021"
description = "Provides color blindness simulation for Bevy Engine"
homepage = "https://bevyengine.org"
repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[dependencies]
# bevy
bevy_app = { path = "../bevy_app", version = "0.9.0-dev" }
bevy_asset = { path = "../bevy_asset", version = "0.9.0-dev" }
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.9.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.9.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.9.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.9.0-dev", features = [
"bevy",
] }
bevy_render = { path = "../bevy_render", version = "0.9.0-dev" }
bevy_sprite = { path = "../bevy_sprite", version = "0.9.0-dev" }
bevy_transform = { path = "../bevy_transform", version = "0.9.0-dev" }
bevy_ui = { path = "../bevy_ui", version = "0.9.0-dev" }
bevy_window = { path = "../bevy_window", version = "0.9.0-dev" }

[dev-dependencies]
bevy_input = { path = "../bevy_input", version = "0.9.0-dev" }
34 changes: 34 additions & 0 deletions crates/bevy_color_blindness/src/color_blindness.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#import bevy_pbr::mesh_view_bindings

struct Percentages {
red: vec3<f32>,
green: vec3<f32>,
blue: vec3<f32>,
};

@group(1) @binding(0)
var texture: texture_2d<f32>;

@group(1) @binding(1)
var our_sampler: sampler;

@group(1) @binding(2)
var<uniform> p: Percentages;

@fragment
fn fragment(
@builtin(position) position: vec4<f32>,
#import bevy_sprite::mesh2d_vertex_output
) -> @location(0) vec4<f32> {
// Get screen position with coordinates from 0 to 1
let uv = position.xy / vec2<f32>(view.width, view.height);

var c = textureSample(texture, our_sampler, uv);

return vec4<f32>(
c.r * p.red.x + c.g * p.red.y + c.b * p.red.z,
c.r * p.green.x + c.g * p.green.y + c.b * p.green.z,
c.r * p.blue.x + c.g * p.blue.y + c.b * p.blue.z,
c.a
);
}
Comment on lines +18 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to see an informed comparison with the approach linked in the associated issue: https://github.com/electronicarts/Tunable-Colorblindness-Solution

I translated into bevy if it can help to make a comparison : https://github.com/Vrixyz/bevy/blob/colorblind/assets/shaders/colorblind.wgsl

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not well-versed enough in the mess that is the world of colors to be able to provide any sort of comparison, much less an informed one '^^. Is there any Bevy contributor who does and would be able to help us with this?

Loading