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:
@@ -39,9 +39,13 @@ use wsg_lib::app::AppBuilder;
|
||||
use wsg_lib::camera::CameraController;
|
||||
use wsg_lib::core::Transform;
|
||||
use wsg_lib::mesh::{cube, 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");
|
||||
|
||||
/// Grid dimensions (15×15 = 225 cubes, fits within MAX_ENTITIES=256).
|
||||
const GRID: usize = 15;
|
||||
/// Spacing between cubes (world units).
|
||||
@@ -67,9 +71,26 @@ impl AppHandler for CullingDemo {
|
||||
.unwrap();
|
||||
app.scene.add_entity("ground", "ground_mesh").unwrap();
|
||||
|
||||
// One shared cube mesh (all entities reference the same GPU buffers).
|
||||
// One shared cube mesh (all entities reference the same GPU buffers), textured with
|
||||
// the uv_texture.jpg atlas — the colourful labelled cells make it obvious exactly
|
||||
// which cubes the GPU draws and which it culls.
|
||||
let (device, queue) = {
|
||||
let ctx = app.context();
|
||||
(ctx.device.clone(), ctx.queue.clone())
|
||||
};
|
||||
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
|
||||
.create_mesh("cube_mesh", cube(0.5), None)
|
||||
.add_material_texture("cube_mat", "standard", "uv_texture")
|
||||
.unwrap();
|
||||
app.scene
|
||||
.create_mesh("cube_mesh", cube(0.5), Some("cube_mat"))
|
||||
.unwrap();
|
||||
|
||||
// Place the grid of cubes.
|
||||
|
||||
Reference in New Issue
Block a user