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

Adreno material shader fixes #8589

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ default = [
"android_shared_stdcxx",
"tonemapping_luts",
"default_font",
"limit_directional_light",
]

# Force dynamic linking, which improves iterative compile times
Expand Down Expand Up @@ -82,6 +83,9 @@ bevy_gltf = ["bevy_internal/bevy_gltf", "bevy_asset", "bevy_scene", "bevy_pbr"]
# Adds PBR rendering
bevy_pbr = ["bevy_internal/bevy_pbr", "bevy_asset", "bevy_render", "bevy_core_pipeline"]

# Limit Directional Lights in PBR
limit_directional_light = ["bevy_internal/limit_directional_light"]

# Provides rendering functionality
bevy_render = ["bevy_internal/bevy_render"]

Expand Down Expand Up @@ -241,7 +245,7 @@ bevy_internal = { path = "crates/bevy_internal", version = "0.11.0-dev", default

[target.'cfg(target_arch = "wasm32")'.dependencies]
bevy_internal = { path = "crates/bevy_internal", version = "0.11.0-dev", default-features = false, features = [
"webgl",
"webgl"
] }

[dev-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ subpixel_glyph_atlas = ["bevy_text/subpixel_glyph_atlas"]
# Optimise for WebGL2
webgl = ["bevy_core_pipeline?/webgl", "bevy_pbr?/webgl", "bevy_render?/webgl"]

# Limit directional light to 1 in PBR
limit_directional_light = ["bevy_pbr/limit_directional_light"]

# enable systems that allow for automated testing on CI
bevy_ci_testing = ["bevy_app/bevy_ci_testing", "bevy_render?/ci_limits"]

Expand Down
1 change: 1 addition & 0 deletions crates/bevy_pbr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ keywords = ["bevy"]

[features]
webgl = []
limit_directional_light = []

[dependencies]
# bevy
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/pbr_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ bitflags::bitflags! {

impl StandardMaterialFlags {
const ALPHA_MODE_MASK_BITS: u32 = 0b111;
const ALPHA_MODE_SHIFT_BITS: u32 = 32 - Self::ALPHA_MODE_MASK_BITS.count_ones();
const ALPHA_MODE_SHIFT_BITS: u32 = 16 - Self::ALPHA_MODE_MASK_BITS.count_ones();
}

/// The GPU representation of the uniform data of a [`StandardMaterial`].
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ pub struct GpuLights {

// NOTE: this must be kept in sync with the same constants in pbr.frag
pub const MAX_UNIFORM_BUFFER_POINT_LIGHTS: usize = 256;
#[cfg(feature = "limit_directional_light")]
pub const MAX_DIRECTIONAL_LIGHTS: usize = 1;
#[cfg(not(feature = "limit_directional_light"))]
pub const MAX_DIRECTIONAL_LIGHTS: usize = 10;
#[cfg(not(feature = "webgl"))]
pub const MAX_CASCADES_PER_LIGHT: usize = 4;
Expand Down
17 changes: 10 additions & 7 deletions crates/bevy_pbr/src/render/pbr_types.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ const STANDARD_MATERIAL_FLAGS_TWO_COMPONENT_NORMAL_MAP: u32 = 64u;
const STANDARD_MATERIAL_FLAGS_FLIP_NORMAL_MAP_Y: u32 = 128u;
const STANDARD_MATERIAL_FLAGS_FOG_ENABLED_BIT: u32 = 256u;
const STANDARD_MATERIAL_FLAGS_DEPTH_MAP_BIT: u32 = 512u;
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_RESERVED_BITS: u32 = 3758096384u; // (0b111u32 << 29)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_OPAQUE: u32 = 0u; // (0u32 << 29)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MASK: u32 = 536870912u; // (1u32 << 29)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_BLEND: u32 = 1073741824u; // (2u32 << 29)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_PREMULTIPLIED: u32 = 1610612736u; // (3u32 << 29)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_ADD: u32 = 2147483648u; // (4u32 << 29)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MULTIPLY: u32 = 2684354560u; // (5u32 << 29)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_RESERVED_BITS: u32 = 57344u; // (0b111u32 << 13)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_OPAQUE: u32 = 0u; // (0u32 << 13)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MASK: u32 = 8192u; // (1u32 << 13)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_BLEND: u32 = 16384u; // (2u32 << 13)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_PREMULTIPLIED: u32 = 24576u; // (3u32 << 13)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_ADD: u32 = 32768u; // (4u32 << 13)
const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MULTIPLY: u32 = 40960u; // (5u32 << 13)
// ↑ To calculate/verify the values above, use the following playground:
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7792f8dd6fc6a8d4d0b6b1776898a7f4
// NOTE: the gist is based on a shift of 29 since the blend modes used to be at
// the end of a u32. Because this created an issue with Adreno chipsets it has
// been moved to 13.

// Creates a StandardMaterial with default values
fn standard_material_new() -> StandardMaterial {
Expand Down