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:
@@ -11,8 +11,8 @@ README (description + how to run): [`meshes/`](../../lib/examples/meshes/README.
|
||||
| Example | Folder | What it shows | How to run | Corresponding page |
|
||||
|---------|--------|---------------|------------|--------------------|
|
||||
| `simple` | meshes | A 2D quad with vertex colors, unlit mode (~30 lines) | `cargo run -p wsg-lib --example simple` | [Quickstart](quickstart.md), [Materials](meshes/materials.md) |
|
||||
| `cube` | meshes | A rotating cube: point + spot light, checkerboard texture, procedural normal map, orbit/zoom | `cargo run -p wsg-lib --example cube` | [Meshes](meshes/meshes.md), [Materials](meshes/materials.md), [Lights](lights/lights.md) |
|
||||
| `pbr` | meshes | A procedural PBR material (metal/roughness) + a checker diffuse | `cargo run -p wsg-lib --example pbr` | [Materials](meshes/materials.md) |
|
||||
| `cube` | meshes | A rotating cube: point + spot light, `uv_texture.jpg` UV-atlas texture | `cargo run -p wsg-lib --example cube` | [Meshes](meshes/meshes.md), [Materials](meshes/materials.md), [Lights](lights/lights.md) |
|
||||
| `pbr` | meshes | PBR materials (metal/roughness) + real textures: `cave.jpg` albedo, `caveNormal.jpg` normal map, `ground.jpeg` floor | `cargo run -p wsg-lib --example pbr` | [Materials](meshes/materials.md) |
|
||||
| `import` | meshes | Wavefront **OBJ** import (CLI: file path as argument, procedural cube as fallback) | `cargo run -p wsg-lib --example import --features import-obj -- model.obj` | [Geometry sources](meshes/sources.md) |
|
||||
| `manual` | meshes | **Advanced**: the full manual workflow — buffers, pipelines, command encoding, no helpers | `cargo run -p wsg-lib --example manual` | [ARCHI_APP](../tech/ARCHI_APP.md), [FRAME_LOOP](../tech/FRAME_LOOP.md) |
|
||||
| `shadow` | lights | Shadow mapping: the classic pitfall — the packed-index shadow caster | `cargo run -p wsg-lib --example shadow` | [Shadows](lights/shadows.md) |
|
||||
@@ -27,6 +27,13 @@ README (description + how to run): [`meshes/`](../../lib/examples/meshes/README.
|
||||
| `fog` | effects | Distance fog, 3 modes switchable at runtime (linear / exponential / exp²) | `cargo run -p wsg-lib --example fog` | [Fog](effects/fog.md) |
|
||||
| `dof` | effects | Depth of field: Gaussian blur scaled by defocus distance, cinematic bokeh; focus presets 1-4 + continuous zoom | `cargo run -p wsg-lib --example dof` | [DoF](effects/dof.md) |
|
||||
|
||||
> **Texture assets**: the multi-mesh examples use real image files from
|
||||
> [`lib/examples/assets/textures/`](../../lib/examples/assets/textures/) (see the
|
||||
> [Texture assets](../../lib/examples/README.md#texture-assets) section there for the full
|
||||
> table): `uv_texture.jpg` (UV atlas visualization), `ground.jpeg` (tiled floor albedo),
|
||||
> `stonewall.jpg`, and the `cave.jpg` + `caveNormal.jpg` albedo/normal pair. Paths are
|
||||
> resolved against `CARGO_MANIFEST_DIR`, so the examples run from any working directory.
|
||||
|
||||
## The `manual` example: bypassing the helpers
|
||||
|
||||
[`manual.rs`](../../lib/examples/meshes/manual.rs) renders a rotating cube with **no
|
||||
|
||||
@@ -57,7 +57,8 @@ Four constructors:
|
||||
| `Texture::from_file(device, queue, label, path)` | image file on disk |
|
||||
| `Texture::white_placeholder(device, queue)` | 1×1 white — used internally when a material has no texture |
|
||||
|
||||
You get `device`/`queue` in `setup()` via `app.context()`:
|
||||
You get `device`/`queue` in `setup()` via `app.context()` (clone them out of the
|
||||
borrow before touching `app.scene` again — see the pattern in every textured example):
|
||||
|
||||
```rust
|
||||
let (device, queue) = {
|
||||
@@ -70,7 +71,30 @@ app.scene.add_material_texture("ground_mat", "standard", "checker_texture").unwr
|
||||
```
|
||||
|
||||
The exact snippet (8×8 checkerboard + stripes generation) is in
|
||||
[`demo.rs`](../../../lib/examples/effects/demo.rs) and [`cube.rs`](../../../lib/examples/meshes/cube.rs).
|
||||
[`demo.rs`](../../../lib/examples/effects/demo.rs).
|
||||
|
||||
For **file textures** (the pattern used by `cube`, `demo`, `shadow`, `fog`, `dof`,
|
||||
`culling` and `pbr`), load from `assets/textures/` and resolve the path against
|
||||
`CARGO_MANIFEST_DIR` so the example works from any working directory:
|
||||
|
||||
```rust
|
||||
const TEXTURES: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/assets/textures");
|
||||
let texture = Texture::from_file(
|
||||
&device,
|
||||
&queue,
|
||||
"uv_atlas",
|
||||
&format!("{TEXTURES}/uv_texture.jpg"),
|
||||
)
|
||||
.unwrap();
|
||||
```
|
||||
|
||||
The sampler is `Linear` + `Repeat`, so textures tile automatically when UVs exceed
|
||||
[0,1] (e.g. the 80×80 fog floor tiles `ground.jpeg`).
|
||||
|
||||
> **Normal maps**: `Texture` is always `Rgba8UnormSrgb`, so the GPU sRGB-decodes on
|
||||
> sample. A normal map is *linear* data — pre-encode its channels with the sRGB OETF
|
||||
> before upload so the round-trip is the identity. See `load_normal_map` in
|
||||
> [`pbr.rs`](../../../lib/examples/meshes/pbr.rs).
|
||||
|
||||
Two conditions for a texture to show up:
|
||||
1. the material is created via `add_material_texture` (otherwise the 1×1 white placeholder
|
||||
|
||||
Reference in New Issue
Block a user