Skip to content
Merged
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: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ colorous = "1.0.12"
web-time = "1.0.0"
winit = { version = "0.30.0", default-features = false, features = ["rwh_06"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
glam = { version = "0.31.0", features = ["rand"] }
rand = "0.9.2"
glam = "0.31.0"
rand = "0.10.0"
# Disable unnecessary formats.
image = { version = "0.25.0", default-features = false, features = ["jpeg"] }

Expand All @@ -199,7 +199,7 @@ wasm-bindgen-test = "0.3"
console_error_panic_hook = "0.1"
tracing-web = "0.1"
# Allow `rand` crate to compile.
getrandom = { version = "0.3.4", features = ["wasm_js"] }
getrandom = { version = "0.4.1", features = ["wasm_js"] }

# DRM example.
[target.'cfg(not(any(target_os = "android", target_vendor = "apple", target_os = "redox", target_family = "wasm", target_os = "windows")))'.dev-dependencies]
Expand Down
18 changes: 8 additions & 10 deletions examples/raytracing/game.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::{Duration, Instant};

use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng};
use rand::rngs::{SmallRng, SysRng};
use rand::{RngExt, SeedableRng};
use softbuffer::{Buffer, Pixel};

use crate::camera::Camera;
Expand All @@ -27,7 +27,7 @@ const DURATION_BETWEEN_TICKS: Duration = Duration::from_millis(10);

impl Game {
pub fn new() -> Self {
let mut rng = SmallRng::from_os_rng();
let mut rng = SmallRng::try_from_rng(&mut SysRng).unwrap();
let position = Point3::new(13.0, 2.0, 3.0);
let looking_at = Point3::new(0.0, 0.0, 0.0);
let camera_direction = (looking_at - position).normalize();
Expand Down Expand Up @@ -91,16 +91,14 @@ impl Game {
{
use rayon::prelude::*;

pixels
.par_iter_mut()
.enumerate()
.for_each_init(SmallRng::from_os_rng, move |rng, (i, pixel)| {
each_pixel(rng, i, pixel)
});
pixels.par_iter_mut().enumerate().for_each_init(
|| SmallRng::try_from_rng(&mut SysRng).unwrap(),
move |rng, (i, pixel)| each_pixel(rng, i, pixel),
);
};
#[cfg(target_family = "wasm")]
{
let mut rng = SmallRng::from_os_rng();
let mut rng = SmallRng::try_from_rng(&mut SysRng).unwrap();
pixels
.iter_mut()
.enumerate()
Expand Down
2 changes: 1 addition & 1 deletion examples/raytracing/material.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rand::Rng;
use rand::{Rng, RngExt};

use crate::objects::Hit;
use crate::ray::Ray;
Expand Down
10 changes: 9 additions & 1 deletion examples/raytracing/vec3.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
use rand::Rng;
use rand::{Rng, RngExt};

pub use glam::Vec3;
pub type Point3 = Vec3;
pub type Color = Vec3;

pub fn random_color(rng: &mut impl Rng) -> Color {
Vec3::new(
rng.random_range(0.0..=1.0),
rng.random_range(0.0..=1.0),
rng.random_range(0.0..=1.0),
)
}

pub fn random_in_unit_sphere(rng: &mut impl Rng) -> Vec3 {
loop {
let p = Vec3::new(
Expand Down
6 changes: 3 additions & 3 deletions examples/raytracing/world.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::ops::Range;

use rand::Rng;
use rand::{Rng, RngExt};

use crate::material::{Dielectric, Lambertian, Material, Metal};
use crate::objects::{Hit, Sphere};
use crate::ray::Ray;
use crate::vec3::{Color, Point3, Vec3};
use crate::vec3::{random_color, Color, Point3, Vec3};

#[derive(Default, Debug)]
pub struct World {
Expand Down Expand Up @@ -35,7 +35,7 @@ impl World {
if (center - Point3::new(4.0, 0.2, 0.0)).length() > 0.9 {
if choose_mat < 0.8 {
// Diffuse
let albedo = rng.random::<Color>() * rng.random::<Color>();
let albedo = random_color(rng) * random_color(rng);
let sphere_material = Material::Lambertian(Lambertian::new(albedo));
spheres.push(Sphere::new(center, 0.2, sphere_material));
} else if choose_mat < 0.95 {
Expand Down