nightshade-api 0.53.0

Procedural high level API for the nightshade game engine
Documentation
//! Advanced PBR material features: anisotropy, iridescence, specular, clearcoat,
//! sheen, texture and normal maps, UV transforms, alpha cutout, and the runtime
//! material registry with its inspection readers.

use nightshade_api::prelude::*;

fn main() {
    run_scene(|world| {
        set_background(world, Background::Color([0.02, 0.02, 0.05, 1.0]));
        show_grid(world, false);
        set_bloom(world, true);
        spawn_floor(world, 14.0);

        load_texture(
            world,
            "face",
            include_bytes!("../../../assets/textures/awesomeface.png"),
        );
        load_texture_linear(
            world,
            "face_normal",
            include_bytes!("../../../assets/textures/awesomeface.png"),
        );

        let spacing = 1.6;
        let column = |index: i32| vec3(-6.4 + index as f32 * spacing, 0.6, 0.0);

        let anisotropic = spawn_sphere(world, column(0));
        set_metallic_roughness(world, anisotropic, 1.0, 0.4);
        set_anisotropy(world, anisotropic, 0.9, 0.0);

        let iridescent = spawn_sphere(world, column(1));
        set_iridescence(world, iridescent, 1.0, 1.3);

        let specular = spawn_sphere(world, column(2));
        set_specular(world, specular, 1.0, [1.0, 0.7, 0.4]);

        let clearcoated = spawn_sphere(world, column(3));
        set_color(world, clearcoated, RED);
        set_clearcoat(world, clearcoated, 1.0, 0.1);

        let sheened = spawn_sphere(world, column(4));
        set_color(world, sheened, PURPLE);
        set_sheen(world, sheened, [1.0, 0.4, 0.8], 1.0);

        let textured = spawn_sphere(world, column(5));
        set_texture(world, textured, "face");
        set_uv_transform(world, textured, [0.0, 0.0], [2.0, 2.0], 0.5);

        let cutout = spawn_sphere(world, column(6));
        set_texture(world, cutout, "face");
        set_alpha_cutoff(world, cutout, 0.5);
        set_double_sided(world, cutout, true);

        let mapped = spawn_sphere(world, column(7));
        set_texture(world, mapped, "face");
        set_normal_texture(world, mapped, "face_normal");
        set_normal_scale(world, mapped, 1.0);
        set_occlusion_strength(world, mapped, 1.0);

        let glass = register_material(
            world,
            "glass",
            Material {
                base_color: [0.6, 0.8, 1.0, 1.0],
                metallic: 0.0,
                roughness: 0.05,
                ..Default::default()
            },
        );
        update_material(
            world,
            &glass,
            Material {
                base_color: [0.7, 0.9, 1.0, 1.0],
                metallic: 0.0,
                roughness: 0.02,
                ..Default::default()
            },
        );
        let variants = set_material_variant(world, Some(glass.as_str()));
        let registered = material(world, &glass).is_some();
        let material_count = list_materials(world).len();

        let color = color(world, clearcoated).unwrap_or([0.0; 4]);
        let (metallic, roughness) = metallic_roughness(world, anisotropic).unwrap_or((0.0, 0.0));
        let (emissive, strength) = emissive(world, sheened).unwrap_or(([0.0; 3], 0.0));
        let textured_has_material = material_of(world, textured).is_some();

        spawn_text(
            world,
            &format!("registry: {material_count} materials  registered: {registered}  variants: {variants}"),
            ScreenAnchor::TopLeft,
        );
        spawn_text(
            world,
            &format!(
                "clearcoat color {color:?}  aniso mr {metallic:.2}/{roughness:.2}  sheen emissive {emissive:?} {strength:.1}  textured material {textured_has_material}"
            ),
            ScreenAnchor::BottomLeft,
        );

        orbit_camera(world, vec3(0.0, 0.6, 0.0), 14.0);
    })
    .unwrap();
}