-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[Merged by Bors] - Standard Material Blend Modes #6644
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
Changes from 4 commits
7141282
bbb3420
e2a0c46
e1b54dd
63b7844
4efa604
0562f46
92ca5bd
b34341f
fc33691
295d8d2
4187b15
c8f914c
95aad7e
2c9e22a
7d9989e
a3810fd
d538109
fe052e7
b2196b1
e035576
071a4c6
1ee663a
54591c8
28bfb45
5a14a7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -557,13 +557,16 @@ bitflags::bitflags! { | |
| /// MSAA uses the highest 3 bits for the MSAA log2(sample count) to support up to 128x MSAA. | ||
| pub struct MeshPipelineKey: u32 { | ||
| const NONE = 0; | ||
| const BLEND_RESERVED_BITS = 0b11; // ← Bitmask reserving two bits for the blend state | ||
| const BLEND_OPAQUE = 0; // ← Values are just sequential within the mask, and can range from 0 to 3 | ||
| const BLEND_PREMULTIPLIED_ALPHA = 1; // | ||
| const BLEND_MULTIPLY = 2; // ← We still have room for one more value without adding more bits | ||
| const HDR = (1 << 2); | ||
| const TONEMAP_IN_SHADER = (1 << 3); | ||
| const DEBAND_DITHER = (1 << 4); | ||
| const HDR = (1 << 0); | ||
| const TONEMAP_IN_SHADER = (1 << 1); | ||
| const DEBAND_DITHER = (1 << 2); | ||
| const DEPTH_PREPASS = (1 << 3); | ||
| const NORMAL_PREPASS = (1 << 4); | ||
| const ALPHA_MASK = (1 << 5); | ||
| const BLEND_RESERVED_BITS = Self::BLEND_MASK_BITS << Self::BLEND_SHIFT_BITS; // ← Bitmask reserving bits for the blend state | ||
| const BLEND_OPAQUE = (0 << Self::BLEND_SHIFT_BITS); // ← Values are just sequential within the mask, and can range from 0 to 3 | ||
|
||
| const BLEND_PREMULTIPLIED_ALPHA = (1 << Self::BLEND_SHIFT_BITS); // | ||
| const BLEND_MULTIPLY = (2 << Self::BLEND_SHIFT_BITS); // ← We still have room for one more value without adding more bits | ||
| const MSAA_RESERVED_BITS = Self::MSAA_MASK_BITS << Self::MSAA_SHIFT_BITS; | ||
| const PRIMITIVE_TOPOLOGY_RESERVED_BITS = Self::PRIMITIVE_TOPOLOGY_MASK_BITS << Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS; | ||
| } | ||
|
|
@@ -573,7 +576,11 @@ impl MeshPipelineKey { | |
| const MSAA_MASK_BITS: u32 = 0b111; | ||
| const MSAA_SHIFT_BITS: u32 = 32 - Self::MSAA_MASK_BITS.count_ones(); | ||
| const PRIMITIVE_TOPOLOGY_MASK_BITS: u32 = 0b111; | ||
| const PRIMITIVE_TOPOLOGY_SHIFT_BITS: u32 = Self::MSAA_SHIFT_BITS - 3; | ||
| const PRIMITIVE_TOPOLOGY_SHIFT_BITS: u32 = | ||
| Self::MSAA_SHIFT_BITS - Self::PRIMITIVE_TOPOLOGY_MASK_BITS.count_ones(); | ||
| const BLEND_MASK_BITS: u32 = 0b11; | ||
| const BLEND_SHIFT_BITS: u32 = | ||
| Self::PRIMITIVE_TOPOLOGY_SHIFT_BITS - Self::BLEND_MASK_BITS.count_ones(); | ||
|
|
||
| pub fn from_msaa_samples(msaa_samples: u32) -> Self { | ||
| let msaa_bits = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,15 +17,17 @@ let STANDARD_MATERIAL_FLAGS_METALLIC_ROUGHNESS_TEXTURE_BIT: u32 = 4u; | |
| let STANDARD_MATERIAL_FLAGS_OCCLUSION_TEXTURE_BIT: u32 = 8u; | ||
| let STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT: u32 = 16u; | ||
| let STANDARD_MATERIAL_FLAGS_UNLIT_BIT: u32 = 32u; | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_RESERVED_BITS: u32 = 448u; // (0b111 << 6) | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_OPAQUE: u32 = 0u; // (0 << 6) | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MASK: u32 = 64u; // (1 << 6) | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_BLEND: u32 = 128u; // (2 << 6) | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_PREMULTIPLIED: u32 = 192u; // (3 << 6) | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_ADD: u32 = 256u; // (4 << 6) | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MULTIPLY: u32 = 320u; // (5 << 6) | ||
| let STANDARD_MATERIAL_FLAGS_TWO_COMPONENT_NORMAL_MAP: u32 = 512u; | ||
| let STANDARD_MATERIAL_FLAGS_FLIP_NORMAL_MAP_Y: u32 = 1024u; | ||
| let STANDARD_MATERIAL_FLAGS_TWO_COMPONENT_NORMAL_MAP: u32 = 64u; | ||
| let STANDARD_MATERIAL_FLAGS_FLIP_NORMAL_MAP_Y: u32 = 128u; | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_RESERVED_BITS: u32 = 3758096384u; // (0b111u32 << 29) | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_OPAQUE: u32 = 0u; // (0u32 << 29) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0 means no flags are set, you’ll have to start from 1 << 29.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh… I see. You mean that none of the 3 bits are set. Ok. |
||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MASK: u32 = 536870912u; // (1u32 << 29) | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_BLEND: u32 = 1073741824u; // (2u32 << 29) | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_PREMULTIPLIED: u32 = 1610612736u; // (3u32 << 29) | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_ADD: u32 = 2147483648u; // (4u32 << 29) | ||
| let STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MULTIPLY: u32 = 2684354560u; // (5u32 << 29) | ||
| // ↑ To calculate/verify the values above, use the following playground: | ||
| // https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7792f8dd6fc6a8d4d0b6b1776898a7f4 | ||
|
|
||
| // Creates a StandardMaterial with default values | ||
| fn standard_material_new() -> StandardMaterial { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0 << n won’t work.