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:
@@ -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