examples: apply real texture assets to multi-mesh examples
- meshes/cube: procedural checkerboard -> uv_texture.jpg (8x8 UV grid) - meshes/pbr: floor -> ground.jpeg, bump cube -> cave.jpg + caveNormal.jpg (normal map pre-encoded via sRGB OETF to cancel the GPU sRGB decode) - lights/shadow: ground -> ground.jpeg, cube -> uv_texture.jpg - effects/demo: ground -> ground.jpeg, cube -> uv_texture.jpg - effects/fog: ground -> ground.jpeg (tiled 80x80), cubes -> stonewall.jpg - effects/dof: ground -> ground.jpeg, cubes -> uv_texture.jpg - cameras/culling: shared cube mesh -> uv_texture.jpg - add lib/examples/assets/textures/ (19 assets, 6.5 MB) - document assets + usage in examples READMEs, docs/user/examples.md, docs/user/meshes/materials.md (CARGO_MANIFEST_DIR pattern, sRGB caveat)
This commit is contained in:
@@ -19,7 +19,8 @@ the full showcase that combines everything.
|
||||
|
||||
## `demo` — Full Showcase
|
||||
|
||||
Combines **all** effects: LOD primitives, procedural textures, lights
|
||||
Combines **all** effects: LOD primitives, file + procedural textures
|
||||
(`ground.jpeg` floor, `uv_texture.jpg` cube, checker/stripe grids), lights
|
||||
(directional + point + spot), shadows, HDR/ACES, exposure, emissive, bloom, culling.
|
||||
|
||||
```sh
|
||||
@@ -144,8 +145,11 @@ identical, only the edges differ (stair-stepped vs smooth).
|
||||
|
||||
Demonstrates the 3 fog modes: **linear**, **exponential**, **exponential²**.
|
||||
The scene contains a row of cubes receding into the distance and scattered
|
||||
spheres on a large floor plane. Fog blends objects toward a background color,
|
||||
creating the illusion of an infinite world.
|
||||
spheres on a large floor plane. The floor is textured with `ground.jpeg`
|
||||
(tiled across 80×80 units via the `Repeat` sampler) and the cubes with
|
||||
`stonewall.jpg` — the fog falloff reads clearly on the textured surfaces.
|
||||
Fog blends objects toward a background color, creating the illusion of an
|
||||
infinite world.
|
||||
|
||||
```sh
|
||||
cargo run -p wsg-lib --example fog --features "all-prims"
|
||||
@@ -165,7 +169,9 @@ while foreground and background blur according to their distance from the
|
||||
focus plane. Creates a natural attention effect (cinematic style).
|
||||
|
||||
The scene contains 20 cubes in a row along Z (z=3 to z=-25.5) and 5 spheres to
|
||||
the sides, on a floor plane. Focus presets at 3 m / 8 m / 15 m.
|
||||
the sides, on a floor plane. The floor is textured with `ground.jpeg` (tiled)
|
||||
and the cubes with the `uv_texture.jpg` atlas — bokeh blur reads much better
|
||||
on textured surfaces. Focus presets at 3 m / 8 m / 15 m.
|
||||
|
||||
```sh
|
||||
cargo run -p wsg-lib --example dof --features "all-prims"
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
//!
|
||||
//! * a **ground plane** plus one of each procedural primitive from `math::primitives`
|
||||
//! (`cube`, `uv_sphere`, `icosphere`, `cylinder`, `cone`, `torus`) placed around it,
|
||||
//! * a **procedural texture** per mesh (checker / stripe grids, no assets on disk),
|
||||
//! * **textures per mesh**: the ground is a **file asset** (`ground.jpeg`) and the cube a
|
||||
//! **UV atlas asset** (`uv_texture.jpg`), the rest stay procedural (checker / stripe grids),
|
||||
//! * the **standard** Phong material wired to those textures,
|
||||
//! * an **orbital camera** driven live by the unified input state:
|
||||
//! hold the **left mouse button** and drag to orbit (yaw/pitch), the wheel zooms (distance),
|
||||
@@ -43,6 +44,9 @@ use wsg_lib::camera::CameraController;
|
||||
use wsg_lib::resources::Texture;
|
||||
use wsg_lib::utils::WsgError;
|
||||
|
||||
/// Texture asset directory, resolved against the crate root so the example works from any CWD.
|
||||
const TEXTURES: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/assets/textures");
|
||||
|
||||
/// Generates an 8×8 RGBA checkerboard (white / brick) as raw bytes for `Texture::from_rgba8`.
|
||||
fn checkerboard_rgba() -> Vec<u8> {
|
||||
const SIZE: u32 = 8;
|
||||
@@ -109,13 +113,36 @@ impl AppHandler for Demo {
|
||||
(ctx.device.clone(), ctx.queue.clone())
|
||||
};
|
||||
|
||||
// 2. Procedural textures, one material per pattern.
|
||||
// 2. Textures: two **file assets** (ground + UV atlas) plus two procedural patterns.
|
||||
// File paths are resolved against the crate root (`CARGO_MANIFEST_DIR`) so the
|
||||
// example works from any CWD.
|
||||
let ground_tex = Texture::from_file(
|
||||
&device,
|
||||
&queue,
|
||||
"ground",
|
||||
&format!("{TEXTURES}/ground.jpeg"),
|
||||
)
|
||||
.unwrap();
|
||||
app.scene.add_texture("ground_texture", ground_tex).unwrap();
|
||||
app.scene
|
||||
.add_material_texture("ground_mat", "standard", "ground_texture")
|
||||
.unwrap();
|
||||
|
||||
let uv_tex = Texture::from_file(
|
||||
&device,
|
||||
&queue,
|
||||
"uv_atlas",
|
||||
&format!("{TEXTURES}/uv_texture.jpg"),
|
||||
)
|
||||
.unwrap();
|
||||
app.scene.add_texture("uv_texture", uv_tex).unwrap();
|
||||
app.scene
|
||||
.add_material_texture("uv_mat", "standard", "uv_texture")
|
||||
.unwrap();
|
||||
|
||||
let checker =
|
||||
Texture::from_rgba8(&device, &queue, 8, 8, &checkerboard_rgba(), "checker").unwrap();
|
||||
app.scene.add_texture("checker_texture", checker).unwrap();
|
||||
app.scene
|
||||
.add_material_texture("ground_mat", "standard", "checker_texture")
|
||||
.unwrap();
|
||||
app.scene
|
||||
.add_material_texture("solid_mat", "standard", "checker_texture")
|
||||
.unwrap();
|
||||
@@ -140,7 +167,7 @@ impl AppHandler for Demo {
|
||||
// packed into the mesh's single vertex/index buffers (D7). Zooming with the wheel
|
||||
// switches levels on the fly (asymmetric hysteresis, D4).
|
||||
app.scene
|
||||
.create_mesh("cube_mesh", cube(0.8), Some("solid_mat"))
|
||||
.create_mesh("cube_mesh", cube(0.8), Some("uv_mat"))
|
||||
.unwrap();
|
||||
app.scene
|
||||
.create_mesh_with_lod(
|
||||
|
||||
@@ -35,9 +35,13 @@ use wsg_lib::app::AppBuilder;
|
||||
use wsg_lib::camera::CameraController;
|
||||
use wsg_lib::core::{DoFConfig, ToneMapper, Transform};
|
||||
use wsg_lib::mesh::{cube, icosphere, plane};
|
||||
use wsg_lib::resources::Texture;
|
||||
use wsg_lib::AppHandler;
|
||||
use wsg_lib::utils::WsgError;
|
||||
|
||||
/// Texture asset directory, resolved against the crate root so the example works from any CWD.
|
||||
const TEXTURES: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/assets/textures");
|
||||
|
||||
struct DoFDemo {
|
||||
camera: CameraController,
|
||||
}
|
||||
@@ -48,9 +52,33 @@ impl AppHandler for DoFDemo {
|
||||
.register_shader("standard", wsg_lib::utils::STANDARD_SHADER_PATH)
|
||||
.unwrap();
|
||||
|
||||
// Textured ground + cubes: bokeh blur reads much better on textured surfaces.
|
||||
// ground.jpeg tiles across the 80×80 floor (Repeat sampler); uv_texture.jpg on the cubes.
|
||||
let (device, queue) = {
|
||||
let ctx = app.context();
|
||||
(ctx.device.clone(), ctx.queue.clone())
|
||||
};
|
||||
let ground_tex =
|
||||
Texture::from_file(&device, &queue, "ground", &format!("{TEXTURES}/ground.jpeg")).unwrap();
|
||||
app.scene.add_texture("ground_texture", ground_tex).unwrap();
|
||||
app.scene
|
||||
.add_material_texture("ground_mat", "standard", "ground_texture")
|
||||
.unwrap();
|
||||
let uv_tex = Texture::from_file(
|
||||
&device,
|
||||
&queue,
|
||||
"uv_atlas",
|
||||
&format!("{TEXTURES}/uv_texture.jpg"),
|
||||
)
|
||||
.unwrap();
|
||||
app.scene.add_texture("uv_texture", uv_tex).unwrap();
|
||||
app.scene
|
||||
.add_material_texture("cube_mat", "standard", "uv_texture")
|
||||
.unwrap();
|
||||
|
||||
// Ground plane.
|
||||
app.scene
|
||||
.create_mesh("ground_mesh", plane(80.0, 80.0, 1, 1), None)
|
||||
.create_mesh("ground_mesh", plane(80.0, 80.0, 1, 1), Some("ground_mat"))
|
||||
.unwrap();
|
||||
app.scene
|
||||
.add_entity_with_transform(
|
||||
@@ -62,7 +90,7 @@ impl AppHandler for DoFDemo {
|
||||
|
||||
// Row of cubes receding along -Z (distance ≈ 2 to 25 from camera at dist=8).
|
||||
app.scene
|
||||
.create_mesh("cube_mesh", cube(1.0), None)
|
||||
.create_mesh("cube_mesh", cube(1.0), Some("cube_mat"))
|
||||
.unwrap();
|
||||
|
||||
for i in 0..20 {
|
||||
|
||||
@@ -35,9 +35,13 @@ use wsg_lib::app::AppBuilder;
|
||||
use wsg_lib::camera::CameraController;
|
||||
use wsg_lib::core::{FogConfig, ToneMapper, Transform};
|
||||
use wsg_lib::mesh::{cube, icosphere, plane};
|
||||
use wsg_lib::resources::Texture;
|
||||
use wsg_lib::AppHandler;
|
||||
use wsg_lib::utils::WsgError;
|
||||
|
||||
/// Texture asset directory, resolved against the crate root so the example works from any CWD.
|
||||
const TEXTURES: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/assets/textures");
|
||||
|
||||
struct FogDemo {
|
||||
camera: CameraController,
|
||||
}
|
||||
@@ -48,15 +52,34 @@ impl AppHandler for FogDemo {
|
||||
.register_shader("standard", wsg_lib::utils::STANDARD_SHADER_PATH)
|
||||
.unwrap();
|
||||
|
||||
// Textured ground + cubes: the fog falloff reads much better on textured surfaces.
|
||||
// ground.jpeg tiles across the 80×80 floor (Repeat sampler); stonewall.jpg on the cubes.
|
||||
let (device, queue) = {
|
||||
let ctx = app.context();
|
||||
(ctx.device.clone(), ctx.queue.clone())
|
||||
};
|
||||
let ground_tex =
|
||||
Texture::from_file(&device, &queue, "ground", &format!("{TEXTURES}/ground.jpeg")).unwrap();
|
||||
app.scene.add_texture("ground_texture", ground_tex).unwrap();
|
||||
app.scene
|
||||
.add_material_texture("ground_mat", "standard", "ground_texture")
|
||||
.unwrap();
|
||||
let wall_tex =
|
||||
Texture::from_file(&device, &queue, "wall", &format!("{TEXTURES}/stonewall.jpg")).unwrap();
|
||||
app.scene.add_texture("wall_texture", wall_tex).unwrap();
|
||||
app.scene
|
||||
.add_material_texture("wall_mat", "standard", "wall_texture")
|
||||
.unwrap();
|
||||
|
||||
// Large ground plane — will fade into fog at distance.
|
||||
app.scene
|
||||
.create_mesh("ground_mesh", plane(80.0, 80.0, 1, 1), None)
|
||||
.create_mesh("ground_mesh", plane(80.0, 80.0, 1, 1), Some("ground_mat"))
|
||||
.unwrap();
|
||||
app.scene.add_entity("ground", "ground_mesh").unwrap();
|
||||
|
||||
// Row of cubes receding into the distance.
|
||||
app.scene
|
||||
.create_mesh("cube_mesh", cube(1.0), None)
|
||||
.create_mesh("cube_mesh", cube(1.0), Some("wall_mat"))
|
||||
.unwrap();
|
||||
for i in 0..15 {
|
||||
let z = -2.0 - i as f32 * 2.5;
|
||||
|
||||
Reference in New Issue
Block a user