Skip to content

Commit dc89206

Browse files
committed
Merge remote-tracking branch 'upstream' into fix-forward-decal-with-oit
2 parents 800411f + f2592b0 commit dc89206

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

examples/3d/clustered_decal_maps.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use bevy::{
1111
prelude::*,
1212
render::view::Hdr,
1313
};
14-
use rand::Rng;
14+
use rand::{Rng, SeedableRng};
15+
use rand_chacha::ChaCha8Rng;
1516

1617
use crate::widgets::{RadioButton, RadioButtonText, WidgetClickEvent, WidgetClickSender};
1718

@@ -159,9 +160,13 @@ fn main() {
159160
Update,
160161
handle_emission_type_change.after(widgets::handle_ui_interactions::<AppSetting>),
161162
)
163+
.insert_resource(SeededRng(ChaCha8Rng::seed_from_u64(19878367467712)))
162164
.run();
163165
}
164166

167+
#[derive(Resource)]
168+
struct SeededRng(ChaCha8Rng);
169+
165170
/// Spawns all the objects in the scene.
166171
fn setup(
167172
mut commands: Commands,
@@ -279,6 +284,7 @@ fn spawn_decal(
279284
app_textures: Res<AppTextures>,
280285
time: Res<Time>,
281286
mut decal_spawn_timer: Local<Option<Timer>>,
287+
mut seeded_rng: ResMut<SeededRng>,
282288
) {
283289
// Tick the decal spawn timer. Check to see if we should spawn a new decal,
284290
// and bail out if it's not yet time to.
@@ -290,18 +296,17 @@ fn spawn_decal(
290296
}
291297

292298
// Generate a random position along the plane.
293-
let mut rng = rand::rng();
294299
let decal_position = vec3(
295-
rng.random_range(-PLANE_HALF_SIZE..PLANE_HALF_SIZE),
296-
rng.random_range(-PLANE_HALF_SIZE..PLANE_HALF_SIZE),
300+
seeded_rng.0.random_range(-PLANE_HALF_SIZE..PLANE_HALF_SIZE),
301+
seeded_rng.0.random_range(-PLANE_HALF_SIZE..PLANE_HALF_SIZE),
297302
0.0,
298303
);
299304

300305
// Generate a random size for the decal.
301-
let decal_size = rng.random_range(DECAL_MIN_SIZE..DECAL_MAX_SIZE);
306+
let decal_size = seeded_rng.0.random_range(DECAL_MIN_SIZE..DECAL_MAX_SIZE);
302307

303308
// Generate a random rotation for the decal.
304-
let theta = rng.random_range(0.0f32..PI);
309+
let theta = seeded_rng.0.random_range(0.0f32..PI);
305310

306311
// Now spawn the decal.
307312
commands.spawn((

0 commit comments

Comments
 (0)