Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/main' into maybelocation
Browse files Browse the repository at this point in the history
  • Loading branch information
chescock committed Jan 30, 2025
2 parents 8a3def0 + 7d68ac0 commit c1a64ac
Show file tree
Hide file tree
Showing 138 changed files with 8,700 additions and 1,971 deletions.
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# If your IDE needs additional project specific files, configure git to ignore them:
# https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer

# Rust build artifacts
target
crates/**/target
benches/**/target
tools/**/target
**/*.rs.bk

# DX12 wgpu backend
dxcompiler.dll
dxil.dll

# Cargo
Cargo.lock
.cargo/config
.cargo/config.toml

# IDE files
.idea
.vscode
.zed
dxcompiler.dll
dxil.dll

# Bevy Assets
assets/**/*.meta
crates/bevy_asset/imported_assets
Expand Down
54 changes: 51 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ pbr_anisotropy_texture = ["bevy_internal/pbr_anisotropy_texture"]
# Enable support for PCSS, at the risk of blowing past the global, per-shader sampler limit on older/lower-end GPUs
experimental_pbr_pcss = ["bevy_internal/experimental_pbr_pcss"]

# Enable support for specular textures in the `StandardMaterial`, at the risk of blowing past the global, per-shader texture limit on older/lower-end GPUs
pbr_specular_textures = ["bevy_internal/pbr_specular_textures"]

# Enable some limitations to be able to use WebGL2. Please refer to the [WebGL2 and WebGPU](https://github.com/bevyengine/bevy/tree/latest/examples#webgl2-and-webgpu) section of the examples README for more information on how to run Wasm builds with WebGPU.
webgl2 = ["bevy_internal/webgl"]

Expand Down Expand Up @@ -663,6 +666,17 @@ description = "Animates a sprite in response to an event"
category = "2D Rendering"
wasm = true

[[example]]
name = "sprite_scale"
path = "examples/2d/sprite_scale.rs"
doc-scrape-examples = true

[package.metadata.example.sprite_scale]
name = "Sprite Scale"
description = "Shows how a sprite can be scaled into a rectangle while keeping the aspect ratio"
category = "2D Rendering"
wasm = true

[[example]]
name = "sprite_flipping"
path = "examples/2d/sprite_flipping.rs"
Expand Down Expand Up @@ -764,13 +778,13 @@ wasm = true

[[example]]
name = "bounding_2d"
path = "examples/2d/bounding_2d.rs"
path = "examples/math/bounding_2d.rs"
doc-scrape-examples = true

[package.metadata.example.bounding_2d]
name = "2D Bounding Volume Intersections"
name = "Bounding Volume Intersections (2D)"
description = "Showcases bounding volumes and intersection tests"
category = "2D Rendering"
category = "Math"
wasm = true

[[example]]
Expand Down Expand Up @@ -4009,6 +4023,18 @@ description = "Demonstrates how to make materials that use bindless textures"
category = "Shaders"
wasm = true

[[example]]
name = "specular_tint"
path = "examples/3d/specular_tint.rs"
doc-scrape-examples = true
required-features = ["pbr_specular_textures"]

[package.metadata.example.specular_tint]
name = "Specular Tint"
description = "Demonstrates specular tints and maps"
category = "3D Rendering"
wasm = true

[profile.wasm-release]
inherits = "release"
opt-level = "z"
Expand Down Expand Up @@ -4095,3 +4121,25 @@ name = "Directional Navigation"
description = "Demonstration of Directional Navigation between UI elements"
category = "UI (User Interface)"
wasm = true

[[example]]
name = "clustered_decals"
path = "examples/3d/clustered_decals.rs"
doc-scrape-examples = true

[package.metadata.example.clustered_decals]
name = "Clustered Decals"
description = "Demonstrates clustered decals"
category = "3D Rendering"
wasm = false

[[example]]
name = "occlusion_culling"
path = "examples/3d/occlusion_culling.rs"
doc-scrape-examples = true

[package.metadata.example.occlusion_culling]
name = "Occlusion Culling"
description = "Demonstration of Occlusion Culling"
category = "3D Rendering"
wasm = false
86 changes: 86 additions & 0 deletions assets/shaders/custom_clustered_decal.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// This shader, a part of the `clustered_decals` example, shows how to use the
// decal `tag` field to apply arbitrary decal effects.

#import bevy_pbr::{
clustered_forward,
decal::clustered,
forward_io::{VertexOutput, FragmentOutput},
mesh_view_bindings,
pbr_fragment::pbr_input_from_standard_material,
pbr_functions::{alpha_discard, apply_pbr_lighting, main_pass_post_lighting_processing},
}

@fragment
fn fragment(
in: VertexOutput,
@builtin(front_facing) is_front: bool,
) -> FragmentOutput {
// Generate a `PbrInput` struct from the `StandardMaterial` bindings.
var pbr_input = pbr_input_from_standard_material(in, is_front);

// Alpha discard.
pbr_input.material.base_color = alpha_discard(pbr_input.material, pbr_input.material.base_color);

// Apply the normal decals.
pbr_input.material.base_color = clustered::apply_decal_base_color(
in.world_position.xyz,
in.position.xy,
pbr_input.material.base_color
);

// Here we tint the color based on the tag of the decal.
// We could optionally do other things, such as adjust the normal based on a normal map.
let view_z = clustered::get_view_z(in.world_position.xyz);
let is_orthographic = clustered::view_is_orthographic();
let cluster_index =
clustered_forward::fragment_cluster_index(in.position.xy, view_z, is_orthographic);
var clusterable_object_index_ranges =
clustered_forward::unpack_clusterable_object_index_ranges(cluster_index);
var decal_iterator = clustered::clustered_decal_iterator_new(
in.world_position.xyz,
&clusterable_object_index_ranges
);
while (clustered::clustered_decal_iterator_next(&decal_iterator)) {
var decal_base_color = textureSampleLevel(
mesh_view_bindings::clustered_decal_textures[decal_iterator.texture_index],
mesh_view_bindings::clustered_decal_sampler,
decal_iterator.uv,
0.0
);

switch (decal_iterator.tag) {
case 1u: {
// Tint with red.
decal_base_color = vec4(
mix(pbr_input.material.base_color.rgb, vec3(1.0, 0.0, 0.0), 0.5),
decal_base_color.a,
);
}
case 2u: {
// Tint with blue.
decal_base_color = vec4(
mix(pbr_input.material.base_color.rgb, vec3(0.0, 0.0, 1.0), 0.5),
decal_base_color.a,
);
}
default: {}
}

pbr_input.material.base_color = vec4(
mix(pbr_input.material.base_color.rgb, decal_base_color.rgb, decal_base_color.a),
pbr_input.material.base_color.a + decal_base_color.a
);
}

// Apply lighting.
var out: FragmentOutput;
out.color = apply_pbr_lighting(pbr_input);

// Apply in-shader post processing (fog, alpha-premultiply, and also
// tonemapping, debanding if the camera is non-HDR). Note this does not
// include fullscreen postprocessing effects like bloom.
out.color = main_pass_post_lighting_processing(pbr_input, out.color);

return out;
}

36 changes: 29 additions & 7 deletions assets/shaders/custom_ui_material.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,42 @@

@fragment
fn fragment(in: UiVertexOutput) -> @location(0) vec4<f32> {
// normalized position relative to the center of the UI node
let r = in.uv - 0.5;
let output_color = textureSample(material_color_texture, material_color_sampler, in.uv) * color;

// normalized size of the border closest to the current position
// half size of the UI node
let half_size = 0.5 * in.size;

// position relative to the center of the UI node
let p = in.uv * in.size - half_size;

// thickness of the border closest to the current position
let b = vec2(
select(in.border_widths.x, in.border_widths.y, 0. < r.x),
select(in.border_widths.z, in.border_widths.w, 0. < r.y)
select(in.border_widths.x, in.border_widths.z, 0. < p.x),
select(in.border_widths.y, in.border_widths.w, 0. < p.y)
);

// select radius for the nearest corner
let rs = select(in.border_radius.xy, in.border_radius.wz, 0.0 < p.y);
let radius = select(rs.x, rs.y, 0.0 < p.x);

// distance along each axis from the corner
let d = half_size - abs(p);

// if the distance to the edge from the current position on any axis
// is less than the border width on that axis then the position is within
// the border and we return the border color
if any(0.5 - b < abs(r)) {
return border_color;
if d.x < b.x || d.y < b.y {
// select radius for the nearest corner
let rs = select(in.border_radius.xy, in.border_radius.wz, 0.0 < p.y);
let radius = select(rs.x, rs.y, 0.0 < p.x);

// determine if the point is inside the curved corner and return the corresponding color
let q = radius - d;
if radius < min(max(q.x, q.y), 0.0) + length(vec2(max(q.x, 0.0), max(q.y, 0.0))) {
return vec4(0.0);
} else {
return border_color;
}
}

// sample the texture at this position if it's to the left of the slider value
Expand Down
Binary file added assets/textures/AlphaNoise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 36 additions & 36 deletions benches/benches/bevy_reflect/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn call(c: &mut Criterion) {
.bench_function("function", |b| {
let add = add.into_function();
b.iter_batched(
|| ArgList::new().push_owned(75_i32).push_owned(25_i32),
|| ArgList::new().with_owned(75_i32).with_owned(25_i32),
|args| add.call(args),
BatchSize::SmallInput,
);
Expand All @@ -74,7 +74,7 @@ fn call(c: &mut Criterion) {
let capture = 25;
let add = (|a: i32| a + capture).into_function();
b.iter_batched(
|| ArgList::new().push_owned(75_i32),
|| ArgList::new().with_owned(75_i32),
|args| add.call(args),
BatchSize::SmallInput,
);
Expand All @@ -83,7 +83,7 @@ fn call(c: &mut Criterion) {
let mut capture = 25;
let mut add = (|a: i32| capture += a).into_function_mut();
b.iter_batched(
|| ArgList::new().push_owned(75_i32),
|| ArgList::new().with_owned(75_i32),
|args| add.call(args),
BatchSize::SmallInput,
);
Expand Down Expand Up @@ -246,7 +246,7 @@ fn call_overload(c: &mut Criterion) {
|| {
(
simple::<i8>.into_function().with_overload(simple::<i16>),
ArgList::new().push_owned(75_i8).push_owned(25_i8),
ArgList::new().with_owned(75_i8).with_owned(25_i8),
)
},
|(func, args)| func.call(args),
Expand All @@ -263,16 +263,16 @@ fn call_overload(c: &mut Criterion) {
complex::<i16, i32, i64, i128, u8, u16, u32, u64, u128, i8>,
),
ArgList::new()
.push_owned(1_i8)
.push_owned(2_i16)
.push_owned(3_i32)
.push_owned(4_i64)
.push_owned(5_i128)
.push_owned(6_u8)
.push_owned(7_u16)
.push_owned(8_u32)
.push_owned(9_u64)
.push_owned(10_u128),
.with_owned(1_i8)
.with_owned(2_i16)
.with_owned(3_i32)
.with_owned(4_i64)
.with_owned(5_i128)
.with_owned(6_u8)
.with_owned(7_u16)
.with_owned(8_u32)
.with_owned(9_u64)
.with_owned(10_u128),
)
},
|(func, args)| func.call(args),
Expand All @@ -288,7 +288,7 @@ fn call_overload(c: &mut Criterion) {
.with_overload(simple::<i16>)
.with_overload(simple::<i32>)
.with_overload(simple::<i64>),
ArgList::new().push_owned(75_i32).push_owned(25_i32),
ArgList::new().with_owned(75_i32).with_owned(25_i32),
)
},
|(func, args)| func.call(args),
Expand All @@ -311,16 +311,16 @@ fn call_overload(c: &mut Criterion) {
complex::<i64, i128, u8, u16, u32, u64, u128, i8, i16, i32>,
),
ArgList::new()
.push_owned(1_i32)
.push_owned(2_i64)
.push_owned(3_i128)
.push_owned(4_u8)
.push_owned(5_u16)
.push_owned(6_u32)
.push_owned(7_u64)
.push_owned(8_u128)
.push_owned(9_i8)
.push_owned(10_i16),
.with_owned(1_i32)
.with_owned(2_i64)
.with_owned(3_i128)
.with_owned(4_u8)
.with_owned(5_u16)
.with_owned(6_u32)
.with_owned(7_u64)
.with_owned(8_u128)
.with_owned(9_i8)
.with_owned(10_i16),
)
},
|(func, args)| func.call(args),
Expand All @@ -342,7 +342,7 @@ fn call_overload(c: &mut Criterion) {
.with_overload(simple::<u32>)
.with_overload(simple::<u64>)
.with_overload(simple::<u128>),
ArgList::new().push_owned(75_u8).push_owned(25_u8),
ArgList::new().with_owned(75_u8).with_owned(25_u8),
)
},
|(func, args)| func.call(args),
Expand Down Expand Up @@ -383,16 +383,16 @@ fn call_overload(c: &mut Criterion) {
complex::<u128, i8, i16, i32, i64, i128, u8, u16, u32, u64>,
),
ArgList::new()
.push_owned(1_u8)
.push_owned(2_u16)
.push_owned(3_u32)
.push_owned(4_u64)
.push_owned(5_u128)
.push_owned(6_i8)
.push_owned(7_i16)
.push_owned(8_i32)
.push_owned(9_i64)
.push_owned(10_i128),
.with_owned(1_u8)
.with_owned(2_u16)
.with_owned(3_u32)
.with_owned(4_u64)
.with_owned(5_u128)
.with_owned(6_i8)
.with_owned(7_i16)
.with_owned(8_i32)
.with_owned(9_i64)
.with_owned(10_i128),
)
},
|(func, args)| func.call(args),
Expand Down
Loading

0 comments on commit c1a64ac

Please sign in to comment.