From 69e29977333adb75f9d628a23b56040a75893b38 Mon Sep 17 00:00:00 2001 From: Asger Nyman Christiansen Date: Wed, 20 Nov 2024 12:55:45 +0100 Subject: [PATCH] Update three-d-asset (#510) * Update three-d-asset * Support advanced mip map settings * Improve texture example with texture settings * Update three-d-asset to 0.8 * Fix texture example on web * Fix texture example on web --- Cargo.toml | 5 +- examples/animation/Cargo.toml | 2 +- examples/animation/src/main.rs | 6 +- examples/assets/checkerboard.jpg | Bin 0 -> 41843 bytes examples/environment/Cargo.toml | 2 +- examples/environment/src/main.rs | 2 +- examples/fireworks/src/main.rs | 2 +- examples/fog/Cargo.toml | 2 +- examples/fog/src/main.rs | 2 +- examples/forest/Cargo.toml | 2 +- examples/forest/src/main.rs | 4 +- examples/headless/Cargo.toml | 2 +- examples/image/Cargo.toml | 2 +- examples/instanced_draw_order/src/main.rs | 4 +- examples/instanced_shapes/src/main.rs | 4 +- examples/lighting/Cargo.toml | 2 +- examples/lighting/src/main.rs | 19 ++- examples/lights/Cargo.toml | 2 +- examples/lights/src/main.rs | 4 +- examples/logo/Cargo.toml | 2 +- examples/mandelbrot/src/main.rs | 7 +- examples/normals/Cargo.toml | 2 +- examples/normals/src/main.rs | 4 +- examples/pbr/Cargo.toml | 2 +- examples/pbr/src/main.rs | 2 +- examples/picking/Cargo.toml | 2 +- examples/picking/src/main.rs | 6 +- examples/point_cloud/Cargo.toml | 2 +- examples/point_cloud/src/main.rs | 4 +- examples/shapes/src/main.rs | 6 +- examples/sprites/Cargo.toml | 2 +- examples/statues/Cargo.toml | 2 +- examples/statues/src/main.rs | 12 +- examples/terrain/Cargo.toml | 2 +- examples/terrain/src/main.rs | 2 +- examples/text/src/main.rs | 2 +- examples/texture/Cargo.toml | 4 +- examples/texture/src/main.rs | 126 ++++++++++++++++--- examples/triangle_core/Cargo.toml | 2 +- examples/volume/Cargo.toml | 2 +- examples/volume/src/main.rs | 6 +- examples/winit_window/src/main.rs | 2 +- examples/wireframe/Cargo.toml | 2 +- examples/wireframe/src/main.rs | 12 +- src/core/texture.rs | 42 +++++-- src/core/texture/texture2d.rs | 9 +- src/core/texture/texture2d_array.rs | 9 +- src/core/texture/texture3d.rs | 8 +- src/core/texture/texture_cube_map.rs | 11 +- src/renderer.rs | 6 +- src/renderer/control/first_person_control.rs | 2 +- src/renderer/control/fly_control.rs | 4 +- src/renderer/control/free_orbit_control.rs | 12 +- src/renderer/control/orbit_control.rs | 12 +- src/renderer/geometry/instanced_mesh.rs | 13 +- src/renderer/geometry/line.rs | 2 +- src/renderer/geometry/mesh.rs | 4 +- src/renderer/geometry/rectangle.rs | 2 +- src/renderer/light/directional_light.rs | 12 +- src/renderer/light/environment.rs | 4 +- src/renderer/light/point_light.rs | 4 +- src/renderer/light/spot_light.rs | 14 +-- src/renderer/object/axes.rs | 2 +- src/renderer/object/imposters.rs | 4 +- src/renderer/object/voxel_grid.rs | 2 +- 65 files changed, 290 insertions(+), 173 deletions(-) create mode 100644 examples/assets/checkerboard.jpg diff --git a/Cargo.toml b/Cargo.toml index 197db38d9..f4f250caa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ text = ["swash", "lyon"] # Text mesh generation features [dependencies] glow = "0.14" cgmath = "0.18" -three-d-asset = {version = "0.7"} +three-d-asset = "0.8" thiserror = "2" open-enum = "0.5" winit = {version = "0.28", optional = true} @@ -51,7 +51,7 @@ instant = "0.1.11" [dev-dependencies] rand = "0.7" -three-d-asset = {version = "0.7", features = ["hdr", "gltf", "obj", "vol", "pcd", "png", "jpeg", "http", "data-url"] } +three-d-asset = {version = "0.8", features = ["hdr", "gltf", "obj", "vol", "pcd", "png", "jpeg", "http", "data-url"] } noise = {version = "0.6", default-features = false} winit = "0.28" @@ -118,6 +118,7 @@ path = "examples/sprites/src/main.rs" [[example]] name = "texture" path = "examples/texture/src/main.rs" +required-features = ["egui-gui"] [[example]] name = "volume" diff --git a/examples/animation/Cargo.toml b/examples/animation/Cargo.toml index fdb6d0f57..9a2587cb8 100644 --- a/examples/animation/Cargo.toml +++ b/examples/animation/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7", features = ["gltf", "png", "jpeg", "http", "data-url"] } +three-d-asset = {version = "0.8", features = ["gltf", "png", "jpeg", "http", "data-url"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/animation/src/main.rs b/examples/animation/src/main.rs index c1bf653b3..faa8a53ff 100644 --- a/examples/animation/src/main.rs +++ b/examples/animation/src/main.rs @@ -25,7 +25,7 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 1000.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 1000.0); // Source: https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0 let mut loaded = if let Ok(loaded) = @@ -47,8 +47,8 @@ pub async fn run() { .for_each(|part| part.compute_normals()); let mut model = Model::::new(&context, &cpu_model).unwrap(); - let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, -0.5, -0.5)); - let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, 0.5, 0.5)); + let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, -0.5, -0.5)); + let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, 0.5, 0.5)); // main loop window.render_loop(move |mut frame_input| { diff --git a/examples/assets/checkerboard.jpg b/examples/assets/checkerboard.jpg new file mode 100644 index 0000000000000000000000000000000000000000..efcfb0eb08ff27a38d72b1e5a90f3b7b14f31f99 GIT binary patch literal 41843 zcmeI5e^e9Kw#N@53ZkO*DgLUdwbizIL5o6dtJ7+g+FMKeTBQ^*i&8+ukc(8~56HAu z!CR_msinxOdG?3;YBg0Lk)n)(1r;#<1`;qJzx+W+KuiMj_iPyMI)d zCoB|@Ios@+Ip?$Y`Oeb&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&iV}M~Ns@>pi5|@)QHfBd5!DtEjLk^9)fSNXD}~IIB)2H!^}?$fm)ycg9}?9T zDutqihaHV8l%!%QH|K|U)HI758ls9t+|U5Ag`{G!*EnRi{4bQbL@a-$){AnP!)>uk zIgprTM5#gjGoSA65!FAz49$?86OeY0os&m$=OmT==S`Ya50Z3!pcBi?E6)&R?Zc%a zCdyi(tR>1?qO2v#TB58a%39d1?qO2v# zTB58a%37kVCCb`IuqPT())HkcQPz^0wVkBXAL;b>M|Aol%37kVy+InIk;ZeRvETpM zIFTr8iL#a`Yo*3UL|IFewWQnM1JLb{C~JwbR`U?n6mVctvo<$3?iES*W20A}9 zNNp?&n5OCX+gOsPugTNbfB4hap9uA|*q>mj+(wkOL|IFewM1D1?)VrNdph|m?7!a|SjkPq$lV-R zZlYVpNX>!w_ccIs;GDJBOjdKDzh%BH$bOzr=M>N!xLO?|HV5uHST2i!$4OG4IdILd z@urdrT0tiZJJSXScR}CfW7&=`1FV57JL8rp&jdQx)L7~;dJT>YToMxPrb44~^1F$&wgCDjunuk#q?MPXEw4fHe8 zHjsO)S$Ox5El6mV_r+Y9+Q(}fhca4&^XUrizqF0() * 2.0 - 1.0, rng.gen::() * 2.0 - 1.0, diff --git a/examples/logo/Cargo.toml b/examples/logo/Cargo.toml index 59951939f..3c0e3e3c7 100644 --- a/examples/logo/Cargo.toml +++ b/examples/logo/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["png", "http"] } +three-d-asset = {version = "0.8",features = ["png", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/mandelbrot/src/main.rs b/examples/mandelbrot/src/main.rs index 547b1b780..58eb98f83 100644 --- a/examples/mandelbrot/src/main.rs +++ b/examples/mandelbrot/src/main.rs @@ -82,9 +82,8 @@ pub fn main() { if button == Some(MouseButton::Left) { let speed = 0.003 * camera.position().z.abs(); let right = camera.right_direction(); - let up = right.cross(camera.view_direction()); - let delta = -right * speed * delta.0 + up * speed * delta.1; - camera.translate(&delta); + let up = camera.up_orthogonal(); + camera.translate(-right * speed * delta.0 + up * speed * delta.1); redraw = true; } } @@ -94,7 +93,7 @@ pub fn main() { let distance = camera.position().z.abs(); let mut target = camera.position_at_pixel(position); target.z = 0.0; - camera.zoom_towards(&target, distance * 0.05 * delta.1, 0.00001, 10.0); + camera.zoom_towards(target, distance * 0.05 * delta.1, 0.00001, 10.0); redraw = true; } _ => {} diff --git a/examples/normals/Cargo.toml b/examples/normals/Cargo.toml index 7c95bf34d..58236f9c1 100644 --- a/examples/normals/Cargo.toml +++ b/examples/normals/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["gltf", "png", "http"] } +three-d-asset = {version = "0.8",features = ["gltf", "png", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/normals/src/main.rs b/examples/normals/src/main.rs index c95e3a630..d5da76e8a 100644 --- a/examples/normals/src/main.rs +++ b/examples/normals/src/main.rs @@ -76,10 +76,10 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE); - let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(0.0, -1.0, 0.0)); + let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(0.0, -1.0, 0.0)); // main loop window.render_loop(move |mut frame_input| { diff --git a/examples/pbr/Cargo.toml b/examples/pbr/Cargo.toml index bc47d18e3..09d37452d 100644 --- a/examples/pbr/Cargo.toml +++ b/examples/pbr/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["gltf", "hdr", "jpeg", "http"] } +three-d-asset = {version = "0.8",features = ["gltf", "hdr", "jpeg", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/pbr/src/main.rs b/examples/pbr/src/main.rs index c0e4c605e..4997233d1 100644 --- a/examples/pbr/src/main.rs +++ b/examples/pbr/src/main.rs @@ -25,7 +25,7 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); let mut gui = three_d::GUI::new(&context); let mut loaded = if let Ok(loaded) = three_d_asset::io::load_async(&[ diff --git a/examples/picking/Cargo.toml b/examples/picking/Cargo.toml index 05e927d93..9ab67f51c 100644 --- a/examples/picking/Cargo.toml +++ b/examples/picking/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["obj", "http"] } +three-d-asset = {version = "0.8",features = ["obj", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/picking/src/main.rs b/examples/picking/src/main.rs index 35c88a35f..4224cba59 100644 --- a/examples/picking/src/main.rs +++ b/examples/picking/src/main.rs @@ -25,10 +25,10 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); let mut sphere = CpuMesh::sphere(8); - sphere.transform(&Mat4::from_scale(0.1)).unwrap(); + sphere.transform(Mat4::from_scale(0.1)).unwrap(); let mut pick_mesh = Gm::new( Mesh::new(&context, &sphere), PhysicalMaterial::new_opaque( @@ -41,7 +41,7 @@ pub async fn run() { ); let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE); - let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(-1.0, -1.0, -1.0)); + let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(-1.0, -1.0, -1.0)); let mut loaded = three_d_asset::io::load_async(&["examples/assets/suzanne.obj"]) .await diff --git a/examples/point_cloud/Cargo.toml b/examples/point_cloud/Cargo.toml index 159df2b50..5a9c8ca60 100644 --- a/examples/point_cloud/Cargo.toml +++ b/examples/point_cloud/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["pcd", "http"] } +three-d-asset = {version = "0.8",features = ["pcd", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1.16", features = ["macros", "rt-multi-thread"] } diff --git a/examples/point_cloud/src/main.rs b/examples/point_cloud/src/main.rs index 0a905f7cc..43f382e66 100644 --- a/examples/point_cloud/src/main.rs +++ b/examples/point_cloud/src/main.rs @@ -25,7 +25,7 @@ pub async fn run() { 0.01, 100.0, ); - let mut control = OrbitControl::new(*camera.target(), 0.1, 3.0); + let mut control = OrbitControl::new(camera.target(), 0.1, 3.0); // Load point cloud let mut loaded = three_d_asset::io::load_async(&["examples/assets/hand.pcd"]) @@ -34,7 +34,7 @@ pub async fn run() { let cpu_point_cloud: PointCloud = loaded.deserialize("hand.pcd").unwrap(); let mut point_mesh = CpuMesh::sphere(4); - point_mesh.transform(&Mat4::from_scale(0.001)).unwrap(); + point_mesh.transform(Mat4::from_scale(0.001)).unwrap(); let mut point_cloud = Gm { geometry: InstancedMesh::new(&context, &cpu_point_cloud.into(), &point_mesh), diff --git a/examples/shapes/src/main.rs b/examples/shapes/src/main.rs index 671bdb1df..f03dc9ee6 100644 --- a/examples/shapes/src/main.rs +++ b/examples/shapes/src/main.rs @@ -18,7 +18,7 @@ pub fn main() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); let mut sphere = Gm::new( Mesh::new(&context, &CpuMesh::sphere(16)), @@ -92,8 +92,8 @@ pub fn main() { }, ); - let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, -0.5, -0.5)); - let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, 0.5, 0.5)); + let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, -0.5, -0.5)); + let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, 0.5, 0.5)); window.render_loop(move |mut frame_input| { camera.set_viewport(frame_input.viewport); diff --git a/examples/sprites/Cargo.toml b/examples/sprites/Cargo.toml index e0ee4e716..d99c312bf 100644 --- a/examples/sprites/Cargo.toml +++ b/examples/sprites/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["jpeg", "http"] } +three-d-asset = {version = "0.8",features = ["jpeg", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/statues/Cargo.toml b/examples/statues/Cargo.toml index f8102c365..2fefe7943 100644 --- a/examples/statues/Cargo.toml +++ b/examples/statues/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["obj", "png", "http"] } +three-d-asset = {version = "0.8",features = ["obj", "png", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/statues/src/main.rs b/examples/statues/src/main.rs index 54afd6f97..d10e76559 100644 --- a/examples/statues/src/main.rs +++ b/examples/statues/src/main.rs @@ -42,9 +42,9 @@ pub async fn run() { 10000.0, ); let mut control = OrbitControl::new( - *primary_camera.target(), - 0.5 * primary_camera.target().distance(*primary_camera.position()), - 5.0 * primary_camera.target().distance(*primary_camera.position()), + primary_camera.target(), + 0.5 * primary_camera.target().distance(primary_camera.position()), + 5.0 * primary_camera.target().distance(primary_camera.position()), ); // Models from http://texturedmesh.isti.cnr.it/ @@ -95,7 +95,7 @@ pub async fn run() { &context, 10.0, Srgba::new_opaque(204, 178, 127), - &vec3(0.0, -1.0, -1.0), + vec3(0.0, -1.0, -1.0), ); directional.generate_shadow_map( 1024, @@ -112,7 +112,7 @@ pub async fn run() { ..Default::default() }, )); - aabb.expand_with_aabb(&geometry.aabb()); + aabb.expand_with_aabb(geometry.aabb()); } bounding_boxes.push(Gm::new( BoundingBox::new_with_thickness(&context, aabb, 3.0), @@ -169,7 +169,7 @@ pub async fn run() { .iter() .flatten() .chain(&fountain) - .filter(|o| primary_camera.in_frustum(&o.aabb())) + .filter(|o| primary_camera.in_frustum(o.aabb())) { object.render(camera, &[&ambient, &directional]); } diff --git a/examples/terrain/Cargo.toml b/examples/terrain/Cargo.toml index a49abe818..221dc4ffb 100644 --- a/examples/terrain/Cargo.toml +++ b/examples/terrain/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["gltf", "jpeg", "png", "hdr", "http"] } +three-d-asset = {version = "0.8",features = ["gltf", "jpeg", "png", "hdr", "http"] } noise = {version = "0.6", default-features = false} [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/examples/terrain/src/main.rs b/examples/terrain/src/main.rs index b33591d46..d0c63e94d 100644 --- a/examples/terrain/src/main.rs +++ b/examples/terrain/src/main.rs @@ -232,7 +232,7 @@ pub async fn run() { camera.target().y + y_new - camera.position().y, camera.target().z, ); - let up = *camera.up(); + let up = camera.up(); camera.set_view(vec3(p.x, y_new, p.y), target, up); terrain.set_center(p); diff --git a/examples/text/src/main.rs b/examples/text/src/main.rs index e330015cf..841574b85 100644 --- a/examples/text/src/main.rs +++ b/examples/text/src/main.rs @@ -72,7 +72,7 @@ pub fn main() { let right = camera.right_direction(); let up = right.cross(camera.view_direction()); let delta = -right * speed * delta.0 + up * speed * delta.1; - camera.translate(&delta); + camera.translate(delta); } } _ => {} diff --git a/examples/texture/Cargo.toml b/examples/texture/Cargo.toml index a2d5b6b71..42368695a 100644 --- a/examples/texture/Cargo.toml +++ b/examples/texture/Cargo.toml @@ -8,8 +8,8 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["obj", "png", "jpeg", "http"] } +three-d = { path = "../../", features=["egui-gui"] } +three-d-asset = {version = "0.8",features = ["obj", "png", "jpeg", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/texture/src/main.rs b/examples/texture/src/main.rs index e75250696..8539000c7 100644 --- a/examples/texture/src/main.rs +++ b/examples/texture/src/main.rs @@ -18,14 +18,14 @@ pub async fn run() { let mut camera = Camera::new_perspective( window.viewport(), - vec3(4.0, 1.5, 4.0), + vec3(0.0, 1.0, 20.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 1.0, 0.0), degrees(45.0), 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); let mut loaded = three_d_asset::io::load_async(&[ "examples/assets/skybox_evening/right.jpg", @@ -35,6 +35,7 @@ pub async fn run() { "examples/assets/skybox_evening/back.jpg", "examples/assets/Skybox_example.png", "examples/assets/PenguinBaseMesh.obj", + "examples/assets/checkerboard.jpg", ]) .await .unwrap(); @@ -71,28 +72,123 @@ pub async fn run() { m.material.render_states.cull = Cull::Back; }); + // Ground + let mut cpu_texture: CpuTexture = loaded.deserialize("checkerboard").unwrap(); + cpu_texture.data.to_color(); + let mut ground_geometry = CpuMesh::square(); + ground_geometry + .uvs + .as_mut() + .unwrap() + .iter_mut() + .for_each(|uv| *uv = 5.0 * (*uv - vec2(0.4, 0.4))); + let mut ground_object = Gm::new( + Mesh::new(&context, &ground_geometry), + ColorMaterial::default(), + ); + ground_object.set_transformation( + Mat4::from_translation(vec3(0.0, -1.0, 0.0)) + * Mat4::from_angle_x(degrees(-90.0)) + * Mat4::from_scale(20.0), + ); + // Lights let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE); - let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(0.0, -1.0, -1.0)); + let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(0.0, -1.0, -1.0)); + + // GUI + let mut gui = three_d::GUI::new(&context); + let mut max_ratio = 1; + let mut max_levels = 8; + let mut mipmap_filter = Interpolation::Nearest; + let mut min_filter = Interpolation::Nearest; + let mut mag_filter = Interpolation::Nearest; + let mut wrap_s = Wrapping::Repeat; + let mut wrap_t = Wrapping::Repeat; // main loop window.render_loop(move |mut frame_input| { - let mut redraw = frame_input.first_frame; - redraw |= camera.set_viewport(frame_input.viewport); - redraw |= control.handle_events(&mut camera, &mut frame_input.events); + let mut panel_width = 0.0; + gui.update( + &mut frame_input.events, + frame_input.accumulated_time, + frame_input.viewport, + frame_input.device_pixel_ratio, + |gui_context| { + use three_d::egui::*; + SidePanel::left("side_panel").show(gui_context, |ui| { + ui.heading("Debug panel for ground texture"); + ui.label("Wrap s"); + ui.radio_value(&mut wrap_s, Wrapping::ClampToEdge, "ClampToEdge"); + ui.radio_value(&mut wrap_s, Wrapping::MirroredRepeat, "MirroredRepeat"); + ui.radio_value(&mut wrap_s, Wrapping::Repeat, "Repeat"); + ui.label("Wrap t"); + ui.radio_value(&mut wrap_t, Wrapping::ClampToEdge, "ClampToEdge"); + ui.radio_value(&mut wrap_t, Wrapping::MirroredRepeat, "MirroredRepeat"); + ui.radio_value(&mut wrap_t, Wrapping::Repeat, "Repeat"); + ui.label("Min filter"); + ui.radio_value(&mut min_filter, Interpolation::Nearest, "Nearest"); + ui.radio_value(&mut min_filter, Interpolation::Linear, "Linear"); + ui.label("Mag filter"); + ui.radio_value(&mut mag_filter, Interpolation::Nearest, "Nearest"); + ui.radio_value(&mut mag_filter, Interpolation::Linear, "Linear"); + ui.label("Mipmap settings"); + ui.add(Slider::new(&mut max_levels, 1..=8).text("Max levels")); + ui.add(Slider::new(&mut max_ratio, 1..=8).text("Max ratio of anisotropy")); + ui.radio_value(&mut mipmap_filter, Interpolation::Nearest, "Nearest"); + ui.radio_value(&mut mipmap_filter, Interpolation::Linear, "Linear"); + }); + panel_width = gui_context.used_rect().width(); + }, + ); + + let viewport = Viewport { + x: (panel_width * frame_input.device_pixel_ratio) as i32, + y: 0, + width: frame_input.viewport.width + - (panel_width * frame_input.device_pixel_ratio) as u32, + height: frame_input.viewport.height, + }; + camera.set_viewport(viewport); + control.handle_events(&mut camera, &mut frame_input.events); + + // Update ground texture texture settings + let mipmap = Some(Mipmap { + max_ratio, + max_levels, + filter: mipmap_filter, + }); + if cpu_texture.mipmap != mipmap + || cpu_texture.min_filter != min_filter + || cpu_texture.mag_filter != mag_filter + || cpu_texture.wrap_s != wrap_s + || cpu_texture.wrap_t != wrap_t + { + cpu_texture.min_filter = min_filter; + cpu_texture.mag_filter = mag_filter; + cpu_texture.mipmap = mipmap; + cpu_texture.wrap_s = wrap_s; + cpu_texture.wrap_t = wrap_t; + ground_object.material.texture = + Some(Texture2DRef::from_cpu_texture(&context, &cpu_texture)); + } // draw - if redraw { - frame_input.screen().clear(ClearState::default()).render( + frame_input + .screen() + .clear(ClearState::default()) + .render( &camera, - penguin.into_iter().chain(&box_object).chain(&skybox), + penguin + .into_iter() + .chain(&box_object) + .chain(&ground_object) + .chain(&skybox), &[&ambient, &directional], - ); - } + ) + .write(|| gui.render()) + .unwrap(); - FrameOutput { - swap_buffers: redraw, - ..Default::default() - } + FrameOutput::default() }); } diff --git a/examples/triangle_core/Cargo.toml b/examples/triangle_core/Cargo.toml index d9132c3e1..0234258bd 100644 --- a/examples/triangle_core/Cargo.toml +++ b/examples/triangle_core/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7"} +three-d-asset = {version = "0.8"} [target.'cfg(target_arch = "wasm32")'.dependencies] log = "0.4" diff --git a/examples/volume/Cargo.toml b/examples/volume/Cargo.toml index f7baa0b12..b9276ab11 100644 --- a/examples/volume/Cargo.toml +++ b/examples/volume/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["vol", "http"] } +three-d-asset = {version = "0.8",features = ["vol", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/volume/src/main.rs b/examples/volume/src/main.rs index 9282e4f87..d0c65b71d 100644 --- a/examples/volume/src/main.rs +++ b/examples/volume/src/main.rs @@ -25,7 +25,7 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 0.25, 100.0); + let mut control = OrbitControl::new(camera.target(), 0.25, 100.0); // Source: https://web.cs.ucdavis.edu/~okreylos/PhDStudies/Spring2000/ECS277/DataSets.html let cpu_voxel_grid = three_d_asset::io::load_async(&["examples/assets/Skull.vol"]) @@ -36,8 +36,8 @@ pub async fn run() { let mut voxel_grid = VoxelGrid::::new(&context, &cpu_voxel_grid); let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE); - let directional1 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(-1.0, -1.0, -1.0)); - let directional2 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(1.0, 1.0, 1.0)); + let directional1 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(-1.0, -1.0, -1.0)); + let directional2 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(1.0, 1.0, 1.0)); // main loop let mut gui = three_d::GUI::new(&context); diff --git a/examples/winit_window/src/main.rs b/examples/winit_window/src/main.rs index 3e4274673..fe8af5bba 100644 --- a/examples/winit_window/src/main.rs +++ b/examples/winit_window/src/main.rs @@ -40,7 +40,7 @@ pub fn main() { 0.1, 10.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); // Create model let mut model = Gm::new( diff --git a/examples/wireframe/Cargo.toml b/examples/wireframe/Cargo.toml index c3b6f4a0b..6ccaa999c 100644 --- a/examples/wireframe/Cargo.toml +++ b/examples/wireframe/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["obj", "http"] } +three-d-asset = {version = "0.8",features = ["obj", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/wireframe/src/main.rs b/examples/wireframe/src/main.rs index a4b9c15a0..f69ccd334 100644 --- a/examples/wireframe/src/main.rs +++ b/examples/wireframe/src/main.rs @@ -27,7 +27,7 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 0.1 * scene_radius, 100.0 * scene_radius); + let mut control = OrbitControl::new(camera.target(), 0.1 * scene_radius, 100.0 * scene_radius); let mut loaded = three_d_asset::io::load_async(&["examples/assets/suzanne.obj"]) .await @@ -35,7 +35,7 @@ pub async fn run() { let mut cpu_mesh: CpuMesh = loaded.deserialize("suzanne.obj").unwrap(); cpu_mesh - .transform(&Mat4::from_translation(vec3(0.0, 2.0, 0.0))) + .transform(Mat4::from_translation(vec3(0.0, 2.0, 0.0))) .unwrap(); let mut model_material = PhysicalMaterial::new_opaque( &context, @@ -60,7 +60,7 @@ pub async fn run() { wireframe_material.render_states.cull = Cull::Back; let mut cylinder = CpuMesh::cylinder(10); cylinder - .transform(&Mat4::from_nonuniform_scale(1.0, 0.007, 0.007)) + .transform(Mat4::from_nonuniform_scale(1.0, 0.007, 0.007)) .unwrap(); let edges = Gm::new( InstancedMesh::new(&context, &edge_transformations(&cpu_mesh), &cylinder), @@ -68,15 +68,15 @@ pub async fn run() { ); let mut sphere = CpuMesh::sphere(8); - sphere.transform(&Mat4::from_scale(0.015)).unwrap(); + sphere.transform(Mat4::from_scale(0.015)).unwrap(); let vertices = Gm::new( InstancedMesh::new(&context, &vertex_transformations(&cpu_mesh), &sphere), wireframe_material, ); let ambient = AmbientLight::new(&context, 0.7, Srgba::WHITE); - let directional0 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(-1.0, -1.0, -1.0)); - let directional1 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(1.0, 1.0, 1.0)); + let directional0 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(-1.0, -1.0, -1.0)); + let directional1 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(1.0, 1.0, 1.0)); // main loop window.render_loop(move |mut frame_input| { diff --git a/src/core/texture.rs b/src/core/texture.rs index abe499bd1..c8c17c8f0 100644 --- a/src/core/texture.rs +++ b/src/core/texture.rs @@ -39,7 +39,8 @@ pub(in crate::core) use depth_texture2d_multisample::*; use data_type::*; pub use three_d_asset::texture::{ - Interpolation, Texture2D as CpuTexture, Texture3D as CpuTexture3D, TextureData, Wrapping, + Interpolation, Mipmap, Texture2D as CpuTexture, Texture3D as CpuTexture3D, TextureData, + Wrapping, }; /// The basic data type used for each channel of each pixel in a texture. @@ -282,19 +283,22 @@ fn set_parameters( target: u32, min_filter: Interpolation, mag_filter: Interpolation, - mip_map_filter: Option, + mipmap: Option, wrap_s: Wrapping, wrap_t: Wrapping, wrap_r: Option, ) { unsafe { - match mip_map_filter { + match mipmap { None => context.tex_parameter_i32( target, crate::context::TEXTURE_MIN_FILTER, interpolation_from(min_filter), ), - Some(Interpolation::Nearest) => { + Some(Mipmap { + filter: Interpolation::Nearest, + .. + }) => { if min_filter == Interpolation::Nearest { context.tex_parameter_i32( target, @@ -309,7 +313,10 @@ fn set_parameters( ) } } - Some(Interpolation::Linear) => { + Some(Mipmap { + filter: Interpolation::Linear, + .. + }) => { if min_filter == Interpolation::Nearest { context.tex_parameter_i32( target, @@ -326,6 +333,25 @@ fn set_parameters( } _ => panic!("Can only sample textures using 'NEAREST' or 'LINEAR' interpolation"), } + if let Some(Mipmap { max_ratio, .. }) = mipmap { + let extensions = context.supported_extensions(); + // Desktop + if extensions.contains("GL_ARB_texture_filter_anisotropic") || + extensions.contains("GL_EXT_texture_filter_anisotropic") || + // Web + extensions.contains("EXT_texture_filter_anisotropic") + { + let max_ratio = max_ratio.min( + context.get_parameter_i32(crate::context::MAX_TEXTURE_MAX_ANISOTROPY_EXT) + as u32, + ); + context.tex_parameter_i32( + target, + crate::context::TEXTURE_MAX_ANISOTROPY_EXT, + max_ratio as i32, + ); + } + } context.tex_parameter_i32( target, crate::context::TEXTURE_MAG_FILTER, @@ -348,7 +374,7 @@ fn set_parameters( } fn calculate_number_of_mip_maps( - mip_map_filter: Option, + mipmap: Option, width: u32, height: u32, depth: Option, @@ -360,13 +386,13 @@ fn calculate_number_of_mip_maps( return 1; } - if mip_map_filter.is_some() { + if let Some(Mipmap { max_levels, .. }) = mipmap { let max_size = width.max(height).max(depth.unwrap_or(0)); if max_size < 2 { 1 } else { let power_of_two = max_size.next_power_of_two(); - (power_of_two as f64).log2() as u32 + ((power_of_two as f64).log2() as u32).min(max_levels.max(1)) } } else { 1 diff --git a/src/core/texture/texture2d.rs b/src/core/texture/texture2d.rs index 2f557187a..5fb66b0a7 100644 --- a/src/core/texture/texture2d.rs +++ b/src/core/texture/texture2d.rs @@ -46,7 +46,7 @@ impl Texture2D { cpu_texture.height, cpu_texture.min_filter, cpu_texture.mag_filter, - cpu_texture.mip_map_filter, + cpu_texture.mipmap, cpu_texture.wrap_s, cpu_texture.wrap_t, ); @@ -67,13 +67,12 @@ impl Texture2D { height: u32, min_filter: Interpolation, mag_filter: Interpolation, - mip_map_filter: Option, + mipmap: Option, wrap_s: Wrapping, wrap_t: Wrapping, ) -> Self { let id = generate(context); - let number_of_mip_maps = - calculate_number_of_mip_maps::(mip_map_filter, width, height, None); + let number_of_mip_maps = calculate_number_of_mip_maps::(mipmap, width, height, None); let texture = Self { context: context.clone(), id, @@ -91,7 +90,7 @@ impl Texture2D { if number_of_mip_maps == 1 { None } else { - mip_map_filter + mipmap }, wrap_s, wrap_t, diff --git a/src/core/texture/texture2d_array.rs b/src/core/texture/texture2d_array.rs index eee992dfe..871c8908f 100644 --- a/src/core/texture/texture2d_array.rs +++ b/src/core/texture/texture2d_array.rs @@ -136,7 +136,7 @@ impl Texture2DArray { data.len() as u32, cpu_texture.min_filter, cpu_texture.mag_filter, - cpu_texture.mip_map_filter, + cpu_texture.mipmap, cpu_texture.wrap_s, cpu_texture.wrap_t, ); @@ -156,13 +156,12 @@ impl Texture2DArray { depth: u32, min_filter: Interpolation, mag_filter: Interpolation, - mip_map_filter: Option, + mipmap: Option, wrap_s: Wrapping, wrap_t: Wrapping, ) -> Self { let id = generate(context); - let number_of_mip_maps = - calculate_number_of_mip_maps::(mip_map_filter, width, height, None); + let number_of_mip_maps = calculate_number_of_mip_maps::(mipmap, width, height, None); let texture = Self { context: context.clone(), id, @@ -181,7 +180,7 @@ impl Texture2DArray { if number_of_mip_maps == 1 { None } else { - mip_map_filter + mipmap }, wrap_s, wrap_t, diff --git a/src/core/texture/texture3d.rs b/src/core/texture/texture3d.rs index 90cd1db8a..e48a3f1ef 100644 --- a/src/core/texture/texture3d.rs +++ b/src/core/texture/texture3d.rs @@ -47,7 +47,7 @@ impl Texture3D { cpu_texture.depth, cpu_texture.min_filter, cpu_texture.mag_filter, - cpu_texture.mip_map_filter, + cpu_texture.mipmap, cpu_texture.wrap_s, cpu_texture.wrap_t, cpu_texture.wrap_r, @@ -68,14 +68,14 @@ impl Texture3D { depth: u32, min_filter: Interpolation, mag_filter: Interpolation, - mip_map_filter: Option, + mipmap: Option, wrap_s: Wrapping, wrap_t: Wrapping, wrap_r: Wrapping, ) -> Self { let id = generate(context); let number_of_mip_maps = - calculate_number_of_mip_maps::(mip_map_filter, width, height, Some(depth)); + calculate_number_of_mip_maps::(mipmap, width, height, Some(depth)); let texture = Self { context: context.clone(), id, @@ -94,7 +94,7 @@ impl Texture3D { if number_of_mip_maps == 1 { None } else { - mip_map_filter + mipmap }, wrap_s, wrap_t, diff --git a/src/core/texture/texture_cube_map.rs b/src/core/texture/texture_cube_map.rs index 9e65d9d84..7406bd698 100644 --- a/src/core/texture/texture_cube_map.rs +++ b/src/core/texture/texture_cube_map.rs @@ -282,7 +282,7 @@ impl TextureCubeMap { cpu_texture.height, cpu_texture.min_filter, cpu_texture.mag_filter, - cpu_texture.mip_map_filter, + cpu_texture.mipmap, cpu_texture.wrap_s, cpu_texture.wrap_t, wrap_r, @@ -309,14 +309,13 @@ impl TextureCubeMap { height: u32, min_filter: Interpolation, mag_filter: Interpolation, - mip_map_filter: Option, + mipmap: Option, wrap_s: Wrapping, wrap_t: Wrapping, wrap_r: Wrapping, ) -> Self { let id = generate(context); - let number_of_mip_maps = - calculate_number_of_mip_maps::(mip_map_filter, width, height, None); + let number_of_mip_maps = calculate_number_of_mip_maps::(mipmap, width, height, None); let texture = Self { context: context.clone(), id, @@ -334,7 +333,7 @@ impl TextureCubeMap { if number_of_mip_maps == 1 { None } else { - mip_map_filter + mipmap }, wrap_s, wrap_t, @@ -453,7 +452,7 @@ impl TextureCubeMap { texture_size, Interpolation::Linear, Interpolation::Linear, - Some(Interpolation::Linear), + Some(Mipmap::default()), Wrapping::ClampToEdge, Wrapping::ClampToEdge, Wrapping::ClampToEdge, diff --git a/src/renderer.rs b/src/renderer.rs index cf25ca672..da0851a11 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -93,7 +93,7 @@ macro_rules! impl_render_target_extensions_body { ) -> &Self { let (mut deferred_objects, mut forward_objects): (Vec<_>, Vec<_>) = objects .into_iter() - .filter(|o| camera.in_frustum(&o.aabb())) + .filter(|o| camera.in_frustum(o.aabb())) .partition(|o| o.material_type() == MaterialType::Deferred); // Deferred @@ -197,7 +197,7 @@ macro_rules! impl_render_target_extensions_body { self.write_partially::(scissor_box, || { for geometry in geometries .into_iter() - .filter(|o| camera.in_frustum(&o.aabb())) + .filter(|o| camera.in_frustum(o.aabb())) { render_with_material(&self.context, camera, geometry, material, lights); } @@ -248,7 +248,7 @@ macro_rules! impl_render_target_extensions_body { self.write_partially::(scissor_box, || { for geometry in geometries .into_iter() - .filter(|o| camera.in_frustum(&o.aabb())) + .filter(|o| camera.in_frustum(o.aabb())) { render_with_effect( &self.context, diff --git a/src/renderer/control/first_person_control.rs b/src/renderer/control/first_person_control.rs index df719e5a6..9aed7f1f9 100644 --- a/src/renderer/control/first_person_control.rs +++ b/src/renderer/control/first_person_control.rs @@ -38,7 +38,7 @@ impl FirstPersonControl { Event::MouseWheel { delta, handled, .. } => { if !*handled { let v = camera.view_direction() * self.speed * delta.1; - camera.translate(&v); + camera.translate(v); *handled = true; change = true; } diff --git a/src/renderer/control/fly_control.rs b/src/renderer/control/fly_control.rs index 6face8aa1..5415f3ba0 100644 --- a/src/renderer/control/fly_control.rs +++ b/src/renderer/control/fly_control.rs @@ -37,7 +37,7 @@ impl FlyControl { let right = camera.right_direction(); let up = right.cross(camera.view_direction()); camera.translate( - &(-right * delta.0 * self.speed + up * delta.1 * self.speed), + -right * delta.0 * self.speed + up * delta.1 * self.speed, ); *handled = true; change = true; @@ -47,7 +47,7 @@ impl FlyControl { Event::MouseWheel { delta, handled, .. } => { if !*handled { let v = camera.view_direction() * self.speed * delta.1; - camera.translate(&v); + camera.translate(v); *handled = true; change = true; } diff --git a/src/renderer/control/free_orbit_control.rs b/src/renderer/control/free_orbit_control.rs index 61b386268..9ee65cd32 100644 --- a/src/renderer/control/free_orbit_control.rs +++ b/src/renderer/control/free_orbit_control.rs @@ -36,8 +36,8 @@ impl FreeOrbitControl { } => { if !*handled { if Some(MouseButton::Left) == *button { - let speed = 0.01 * self.target.distance(*camera.position()) + 0.001; - camera.rotate_around(&self.target, speed * delta.0, speed * delta.1); + let speed = 0.01 * self.target.distance(camera.position()) + 0.001; + camera.rotate_around(self.target, speed * delta.0, speed * delta.1); *handled = true; change = true; } @@ -45,9 +45,9 @@ impl FreeOrbitControl { } Event::MouseWheel { delta, handled, .. } => { if !*handled { - let speed = 0.01 * self.target.distance(*camera.position()) + 0.001; + let speed = 0.01 * self.target.distance(camera.position()) + 0.001; camera.zoom_towards( - &self.target, + self.target, speed * delta.1, self.min_distance, self.max_distance, @@ -58,9 +58,9 @@ impl FreeOrbitControl { } Event::PinchGesture { delta, handled, .. } => { if !*handled { - let speed = self.target.distance(*camera.position()) + 0.1; + let speed = self.target.distance(camera.position()) + 0.1; camera.zoom_towards( - &self.target, + self.target, speed * *delta, self.min_distance, self.max_distance, diff --git a/src/renderer/control/orbit_control.rs b/src/renderer/control/orbit_control.rs index 1ee85a3cc..ae55c5c7b 100644 --- a/src/renderer/control/orbit_control.rs +++ b/src/renderer/control/orbit_control.rs @@ -36,9 +36,9 @@ impl OrbitControl { } => { if !*handled { if Some(MouseButton::Left) == *button { - let speed = 0.01 * self.target.distance(*camera.position()) + 0.001; + let speed = 0.01 * self.target.distance(camera.position()) + 0.001; camera.rotate_around_with_fixed_up( - &self.target, + self.target, speed * delta.0, speed * delta.1, ); @@ -49,9 +49,9 @@ impl OrbitControl { } Event::MouseWheel { delta, handled, .. } => { if !*handled { - let speed = 0.01 * self.target.distance(*camera.position()) + 0.001; + let speed = 0.01 * self.target.distance(camera.position()) + 0.001; camera.zoom_towards( - &self.target, + self.target, speed * delta.1, self.min_distance, self.max_distance, @@ -62,9 +62,9 @@ impl OrbitControl { } Event::PinchGesture { delta, handled, .. } => { if !*handled { - let speed = self.target.distance(*camera.position()) + 0.1; + let speed = self.target.distance(camera.position()) + 0.1; camera.zoom_towards( - &self.target, + self.target, speed * *delta, self.min_distance, self.max_distance, diff --git a/src/renderer/geometry/instanced_mesh.rs b/src/renderer/geometry/instanced_mesh.rs index aa8e50043..577a83d74 100644 --- a/src/renderer/geometry/instanced_mesh.rs +++ b/src/renderer/geometry/instanced_mesh.rs @@ -88,9 +88,10 @@ impl InstancedMesh { fn update_aabb(&mut self) { let mut aabb = AxisAlignedBoundingBox::EMPTY; for transformation in self.instances.transformations.iter() { - let mut aabb2 = self.aabb_local; - aabb2.transform(&(transformation * self.transformation)); - aabb.expand_with_aabb(&aabb2); + aabb.expand_with_aabb( + self.aabb_local + .transformed(transformation * self.transformation), + ); } self.aabb = aabb; } @@ -100,7 +101,7 @@ impl InstancedMesh { /// fn update_instance_buffers(&self, camera: Option<&Camera>) { let mut s = self.instance_buffers.write().unwrap(); - let indices = if let Some(position) = camera.map(|c| *c.position()) { + let indices = if let Some(position) = camera.map(|c| c.position()) { s.1 = position; // Need to order by using the position. let distances = self @@ -222,7 +223,7 @@ impl Geometry for InstancedMesh { ) { // Check if we need a reorder, this only applies to transparent materials. if render_states.blend != Blend::Disabled - && *camera.position() != self.instance_buffers.read().unwrap().1 + && camera.position() != self.instance_buffers.read().unwrap().1 { self.update_instance_buffers(Some(camera)); } @@ -328,7 +329,7 @@ impl Geometry for InstancedMesh { fn aabb(&self) -> AxisAlignedBoundingBox { let mut aabb = self.aabb; - aabb.transform(&self.current_transformation); + aabb.transform(self.current_transformation); aabb } diff --git a/src/renderer/geometry/line.rs b/src/renderer/geometry/line.rs index 1cf78fad7..8383a36d5 100644 --- a/src/renderer/geometry/line.rs +++ b/src/renderer/geometry/line.rs @@ -21,7 +21,7 @@ impl Line { thickness: f32, ) -> Self { let mut mesh = CpuMesh::square(); - mesh.transform(&(Mat4::from_scale(0.5) * Mat4::from_translation(vec3(1.0, 0.0, 0.0)))) + mesh.transform(Mat4::from_scale(0.5) * Mat4::from_translation(vec3(1.0, 0.0, 0.0))) .unwrap(); let mut line = Self { mesh: Mesh::new(context, &mesh), diff --git a/src/renderer/geometry/mesh.rs b/src/renderer/geometry/mesh.rs index 77f39a4ce..e69495cf5 100644 --- a/src/renderer/geometry/mesh.rs +++ b/src/renderer/geometry/mesh.rs @@ -127,9 +127,7 @@ impl<'a> IntoIterator for &'a Mesh { impl Geometry for Mesh { fn aabb(&self) -> AxisAlignedBoundingBox { - let mut aabb = self.aabb; - aabb.transform(&self.current_transformation); - aabb + self.aabb.transformed(self.current_transformation) } fn animate(&mut self, time: f32) { diff --git a/src/renderer/geometry/rectangle.rs b/src/renderer/geometry/rectangle.rs index 0a3d3eaec..f194c4111 100644 --- a/src/renderer/geometry/rectangle.rs +++ b/src/renderer/geometry/rectangle.rs @@ -23,7 +23,7 @@ impl Rectangle { height: f32, ) -> Self { let mut mesh = CpuMesh::square(); - mesh.transform(&(Mat4::from_scale(0.5))).unwrap(); + mesh.transform(Mat4::from_scale(0.5)).unwrap(); let mut rectangle = Self { mesh: Mesh::new(context, &mesh), width, diff --git a/src/renderer/light/directional_light.rs b/src/renderer/light/directional_light.rs index 5be2bf7df..ce3e0799c 100644 --- a/src/renderer/light/directional_light.rs +++ b/src/renderer/light/directional_light.rs @@ -24,7 +24,7 @@ impl DirectionalLight { context: &Context, intensity: f32, color: Srgba, - direction: &Vec3, + direction: Vec3, ) -> DirectionalLight { DirectionalLight { context: context.clone(), @@ -32,7 +32,7 @@ impl DirectionalLight { shadow_texture: None, intensity, color, - direction: *direction, + direction, } } @@ -61,15 +61,15 @@ impl DirectionalLight { let viewport = Viewport::new_at_origo(texture_size, texture_size); let mut aabb = AxisAlignedBoundingBox::EMPTY; for geometry in geometries.clone() { - aabb.expand_with_aabb(&geometry.aabb()); + aabb.expand_with_aabb(geometry.aabb()); } if aabb.is_empty() { return; } let target = aabb.center(); let position = target - aabb.max().distance(aabb.min()) * self.direction; - let z_far = aabb.distance_max(&position); - let z_near = aabb.distance(&position); + let z_far = aabb.distance_max(position); + let z_near = aabb.distance(position); let frustum_height = aabb.max().distance(aabb.min()); // TODO: more tight fit let shadow_camera = Camera::new_orthographic( viewport, @@ -100,7 +100,7 @@ impl DirectionalLight { .write::(|| { for geometry in geometries .into_iter() - .filter(|g| shadow_camera.in_frustum(&g.aabb())) + .filter(|g| shadow_camera.in_frustum(g.aabb())) { render_with_material( &self.context, diff --git a/src/renderer/light/environment.rs b/src/renderer/light/environment.rs index b9a7aed07..2b11f1744 100644 --- a/src/renderer/light/environment.rs +++ b/src/renderer/light/environment.rs @@ -47,7 +47,7 @@ impl Environment { irradiance_size, Interpolation::Linear, Interpolation::Linear, - Some(Interpolation::Linear), + Some(Mipmap::default()), Wrapping::ClampToEdge, Wrapping::ClampToEdge, Wrapping::ClampToEdge, @@ -77,7 +77,7 @@ impl Environment { prefilter_size, Interpolation::Linear, Interpolation::Linear, - Some(Interpolation::Linear), + Some(Mipmap::default()), Wrapping::ClampToEdge, Wrapping::ClampToEdge, Wrapping::ClampToEdge, diff --git a/src/renderer/light/point_light.rs b/src/renderer/light/point_light.rs index 5299f4b68..da987c5e6 100644 --- a/src/renderer/light/point_light.rs +++ b/src/renderer/light/point_light.rs @@ -21,13 +21,13 @@ impl PointLight { _context: &Context, intensity: f32, color: Srgba, - position: &Vec3, + position: Vec3, attenuation: Attenuation, ) -> PointLight { PointLight { intensity, color, - position: *position, + position, attenuation, } } diff --git a/src/renderer/light/spot_light.rs b/src/renderer/light/spot_light.rs index deb21f679..06ee03029 100644 --- a/src/renderer/light/spot_light.rs +++ b/src/renderer/light/spot_light.rs @@ -30,8 +30,8 @@ impl SpotLight { context: &Context, intensity: f32, color: Srgba, - position: &Vec3, - direction: &Vec3, + position: Vec3, + direction: Vec3, cutoff: impl Into, attenuation: Attenuation, ) -> SpotLight { @@ -40,8 +40,8 @@ impl SpotLight { shadow_texture: None, intensity, color, - position: *position, - direction: *direction, + position, + direction, cutoff: cutoff.into(), attenuation, shadow_matrix: Mat4::identity(), @@ -78,8 +78,8 @@ impl SpotLight { for geometry in geometries.clone() { let aabb = geometry.aabb(); if !aabb.is_empty() { - z_far = z_far.max(aabb.distance_max(&self.position)); - z_near = z_near.min(aabb.distance(&self.position)); + z_far = z_far.max(aabb.distance_max(self.position)); + z_near = z_near.min(aabb.distance(self.position)); } } @@ -114,7 +114,7 @@ impl SpotLight { .write::(|| { for geometry in geometries .into_iter() - .filter(|g| shadow_camera.in_frustum(&g.aabb())) + .filter(|g| shadow_camera.in_frustum(g.aabb())) { render_with_material( &self.context, diff --git a/src/renderer/object/axes.rs b/src/renderer/object/axes.rs index a2c04272c..5a7d097cc 100644 --- a/src/renderer/object/axes.rs +++ b/src/renderer/object/axes.rs @@ -15,7 +15,7 @@ impl Axes { pub fn new(context: &Context, radius: f32, length: f32) -> Self { let mut cpu_mesh = CpuMesh::arrow(0.9, 0.6, 16); cpu_mesh - .transform(&Mat4::from_nonuniform_scale(length, radius, radius)) + .transform(Mat4::from_nonuniform_scale(length, radius, radius)) .unwrap(); let model = Gm::new( InstancedMesh::new( diff --git a/src/renderer/object/imposters.rs b/src/renderer/object/imposters.rs index ded41af3e..7f04f2e3d 100644 --- a/src/renderer/object/imposters.rs +++ b/src/renderer/object/imposters.rs @@ -32,7 +32,7 @@ impl Imposters { objects .clone() .into_iter() - .for_each(|o| aabb.expand_with_aabb(&o.aabb())); + .for_each(|o| aabb.expand_with_aabb(o.aabb())); let mut sprites = Sprites::new(context, positions, Some(vec3(0.0, 1.0, 0.0))); sprites.set_transformation(get_sprite_transform(aabb)); Imposters { @@ -63,7 +63,7 @@ impl Imposters { objects .clone() .into_iter() - .for_each(|o| aabb.expand_with_aabb(&o.aabb())); + .for_each(|o| aabb.expand_with_aabb(o.aabb())); self.sprites.set_transformation(get_sprite_transform(aabb)); self.material .update(aabb, objects, lights, max_texture_size); diff --git a/src/renderer/object/voxel_grid.rs b/src/renderer/object/voxel_grid.rs index a3b1f6cea..9d2393e13 100644 --- a/src/renderer/object/voxel_grid.rs +++ b/src/renderer/object/voxel_grid.rs @@ -14,7 +14,7 @@ impl VoxelGrid { /// pub fn new(context: &Context, cpu_voxel_grid: &CpuVoxelGrid) -> Self { let mut cube = CpuMesh::cube(); - cube.transform(&Mat4::from_nonuniform_scale( + cube.transform(Mat4::from_nonuniform_scale( 0.5 * cpu_voxel_grid.size.x, 0.5 * cpu_voxel_grid.size.y, 0.5 * cpu_voxel_grid.size.z,