Struct Material

Source
pub struct Material(pub NonNull<_MaterialT>);
Expand description

A Material describes the surface of anything drawn on the graphics card! It is typically composed of a Shader, and shader properties like colors, textures, transparency info, etc.

Items drawn with the same Material can be batched together into a single, fast operation on the graphics card, so re-using materials can be extremely beneficial for performance! https://stereokit.net/Pages/StereoKit/Material.html

§Examples

use stereokit_rust::{maths::Matrix, util::Color128, mesh::Mesh, material::{*}};

let cube = Mesh::cube();
// Create a material with default properties
let mut material_cube = Material::default();

// Set some shader properties
material_cube.color_tint   (Color128::new(1.0, 0.5, 0.3, 1.0))
             .transparency (Transparency::MSAA)
             .depth_test   (DepthTest::LessOrEq)
             .face_cull    (Cull::Front);

filename_scr = "screenshots/materials.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
    cube.draw(token, &material_cube, Matrix::IDENTITY, None, None);
);
screenshot

Tuple Fields§

§0: NonNull<_MaterialT>

Implementations§

Source§

impl Material

Source

pub fn new(shader: impl AsRef<Shader>, id: Option<&str>) -> Material

Creates a material from a shader, and uses the shader’s default settings. https://stereokit.net/Pages/StereoKit/Material/Material.html

  • shader - Any valid shader.
  • id - If None the id will be set to a default value “auto/asset_???”

see also material_create material_set_id

§Examples
use stereokit_rust::{maths::{Vec2, Matrix, Vec3}, mesh::Mesh, material::Material, shader::Shader};

// Create Mesh and its material
let plane = Mesh::generate_plane(Vec2::ONE, Vec3::NEG_Z, Vec3::X, None,  true);
let mut material_plane = Material::new(Shader::unlit(), Some("my_material_plane"));

test_steps!( // !!!! Get a proper main loop !!!!
    plane.draw(token, &material_plane,  Matrix::IDENTITY, None, None);
);
Source

pub fn from_file( shader_file_name: impl AsRef<Path>, id: Option<&str>, ) -> Result<Material, StereoKitError>

Loads a Shader asset and creates a Material using it. If the shader fails to load, an error will be returned, if so you can use unwrap_or_default() to get the default. https://stereokit.net/Pages/StereoKit/Material/Material.html

  • id - If None the id will be set to a default value “auto/asset_???”
  • shader_file_name - The filename of a Shader asset.

see also material_create material_set_id

§Examples
use stereokit_rust::{maths::{Matrix, Vec3}, mesh::Mesh, material::Material};

// Create Mesh and its material
let circle = Mesh::generate_circle(1.0, Vec3::NEG_Z, Vec3::X, None,  true);
let material_circle =
    Material::from_file("shaders/blinker.hlsl.sks", Some("my_material_circle")).unwrap();

test_steps!( // !!!! Get a proper main loop !!!!
    circle.draw(token, &material_circle,  Matrix::IDENTITY, None, None);
);
Source

pub fn default_copy() -> Material

Creates a new Material asset with the default Material and its properties! https://stereokit.net/Pages/StereoKit/Material/Copy.html

see also material_copy

Source

pub fn copy(&self) -> Material

Creates a new Material asset with the same shader and properties! Draw calls with the new Material will not batch together with this one. https://stereokit.net/Pages/StereoKit/Material/Copy.html

see also material_copy()

§Examples
use stereokit_rust::{maths::Matrix, util::named_colors, material::Material};

let mut material_blue = Material::default_copy();
material_blue.metallic_amount(0.63);
material_blue.color_tint(named_colors::BLUE);
let mut material_red = material_blue.copy();
material_red.id("my_red_material").color_tint(named_colors::RED);

assert_eq!(&material_blue.get_all_param_info().get_float("metal"),
           &material_red.get_all_param_info().get_float("metal"));
assert_ne!(&material_blue.get_id(), &material_red.get_id());
assert_ne!(&material_blue.get_all_param_info().get_color("color"),
           &material_red.get_all_param_info().get_color("color"));
Source

pub fn copy_id<S: AsRef<str>>(id: S) -> Result<Material, StereoKitError>

Creates a new Material asset with the same shader and properties! Draw calls with the new Material will not batch together with this one. https://stereokit.net/Pages/StereoKit/Material/Copy.html

  • id - Which material are you looking for?

Returns a new Material asset with the same shader and properties if the id is found. see also material_copy_id

§Examples
use stereokit_rust::{util::named_colors, material::Material, shader::Shader};

let mut material = Material::new(Shader::pbr(), Some("my_material"));
material.roughness_amount(0.42);
let mut material_red = Material::copy_id("my_material").unwrap();
material_red.id("my_red_material").color_tint(named_colors::RED);

assert_eq!(&material.get_all_param_info().get_float("roughness"),
           &material_red.get_all_param_info().get_float("roughness"));
assert_ne!(&material.get_all_param_info().get_color("color"),
           &material_red.get_all_param_info().get_color("color"));
assert_ne!(&material.get_id(), &material_red.get_id());
Source

pub fn find<S: AsRef<str>>(id: S) -> Result<Material, StereoKitError>

Looks for a Material asset that’s already loaded, matching the given id! https://stereokit.net/Pages/StereoKit/Material/Find.html

  • id - Which material are you looking for ?

see also material_find

§Examples
use stereokit_rust::{util::named_colors,material::Material, shader::Shader};

let mut material = Material::new(Shader::pbr(), Some("my_material"));
let mut material_red = Material::find("my_material").unwrap();
material_red.id("my_red_material").color_tint(named_colors::RED);

assert_eq!(&material.get_all_param_info().get_color("color"),
           &material_red.get_all_param_info().get_color("color"));
assert_eq!(&material.get_id(),&"my_red_material");
Source

pub fn clone_ref(&self) -> Material

Creates a clone of the same reference. Basically, the new variable is the same asset. This is what you get by calling find() method. https://stereokit.net/Pages/StereoKit/Material/Find.html

see also material_find()

§Examples
use stereokit_rust::{util::named_colors,material::Material, shader::Shader};

let mut material = Material::new(Shader::pbr(), Some("my_material"));
let mut material_red = material.clone_ref();
material_red.id("my_red_material").color_tint(named_colors::RED);

assert_eq!(&material.get_all_param_info().get_color("color"),
           &material_red.get_all_param_info().get_color("color"));
assert_eq!(&material.get_id(),&"my_red_material");
Source

pub fn tex_file_copy( &mut self, tex_file_name: impl AsRef<Path>, srgb_data: bool, priority: Option<i32>, ) -> Result<Material, StereoKitError>

Non-canonical function of convenience!! Use this for Icons and other Ui Images Copy a Material and set a Tex image to its diffuse_tex. If the Tex fails to load, an error will be returned, if so you can use unwrap_or_default() to get the default. https://stereokit.net/Pages/StereoKit/Tex/FromFile.html

  • tex_file_name - The file name of the texture to load.
  • srgb_data - If true, the texture will be loaded as sRGB data.
  • priority - The priority sort order for this asset in the async loading system. Lower values mean loading sooner.

see also Material::diffuse_tex material_create material_set_id

§Examples
use stereokit_rust::material::Material;

let material1 = Material::unlit().copy();
let material2 = Material::unlit().copy();
let mut material3 = Material::unlit().tex_file_copy("textures/open_gltf.jpeg", true, None)
                   .expect("open_gltf.jpeg should load");

assert_eq!(&material1.get_all_param_info().get_texture("diffuse").unwrap().get_id(),
           &material2.get_all_param_info().get_texture("diffuse").unwrap().get_id());
assert_ne!(&material2.get_all_param_info().get_texture("diffuse").unwrap().get_id(),
           &material3.get_all_param_info().get_texture("diffuse").unwrap().get_id());
Source

pub fn tex_copy(&mut self, tex: impl AsRef<Tex>) -> Material

Non-canonical function of convenience!! Use this for Icons and other Ui Images Copy a Material and set a Tex image to its diffuse_tex. If the Tex fails to load, an error will be returned, if so you can use unwrap_or_default() to get the default. https://stereokit.net/Pages/StereoKit/Tex/FromFile.html

  • tex_file_name - The file name of the texture to load.
  • srgb_data - If true, the texture will be loaded as sRGB data.
  • priority - The priority sort order for this asset in the async loading system. Lower values mean loading sooner.

see also Material::diffuse_tex material_create material_set_id

§Examples
use stereokit_rust::{material::Material, tex::Tex};

let material1 = Material::unlit().copy();
let material2 = Material::unlit().copy();
let tex = Tex::from_file("textures/open_gltf.jpeg", true, None)
                   .expect("tex should be created");
let mut material3 = Material::unlit().tex_copy(tex);

assert_eq!(&material1.get_all_param_info().get_texture("diffuse").unwrap().get_id(),
           &material2.get_all_param_info().get_texture("diffuse").unwrap().get_id());
assert_ne!(&material2.get_all_param_info().get_texture("diffuse").unwrap().get_id(),
           &material3.get_all_param_info().get_texture("diffuse").unwrap().get_id());
Source

pub fn id<S: AsRef<str>>(&mut self, id: S) -> &mut Self

Set a new id to the material. https://stereokit.net/Pages/StereoKit/Material/Id.html

see also material_set_id

§Examples
use stereokit_rust::{material::Material, shader::Shader};

let mut material = Material::new(Shader::pbr(), Some("my_material"));
assert_eq!(material.get_id(), "my_material");

material.id("my_new_material");
assert_eq!(material.get_id(), "my_new_material");
Source

pub fn shader(&mut self, shader: impl AsRef<Shader>) -> &mut Self

Overrides the Shader this material uses. https://stereokit.net/Pages/StereoKit/Material/Shader.html

see also material_set_shader

§Examples
use stereokit_rust::{material::Material, shader::Shader};

let mut material = Material::new(Shader::pbr(), Some("my_material"));
assert_eq!(material.get_shader().get_id(), Shader::pbr().get_id());

material.shader(Shader::unlit());
assert_eq!(material.get_shader().get_id(), Shader::unlit().get_id());
Source

pub fn border_size(&mut self, time: f32) -> &mut Self

Non canonical shader parameter to indicate a border size if the shader have one (especially for Material::ui_box) https://stereokit.net/Pages/StereoKit/MatParamName.html

see also material_set_param_id

§Examples
use stereokit_rust::material::Material;

let mut material = Material::ui_box();
material.border_size(0.0428);

assert_eq!(material.get_all_param_info().get_float("border_size"), 0.0428);
Source

pub fn clip_cutoff(&mut self, cutoff: f32) -> &mut Self

In clip shaders, this is the cutoff value below which pixels are discarded. Typically, the diffuse/albedo’s alpha component is sampled for comparison here. This represents the float param ‘cutoff’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also material_set_param_id

§Examples
use stereokit_rust::{material::Material};

let mut material = Material::pbr_clip().copy();
material.clip_cutoff(0.53);
assert_eq!(material.get_all_param_info().get_float("cutoff"), 0.53);
Source

pub fn color_tint(&mut self, color: impl Into<Color128>) -> &mut Self

A per-material color tint, behavior could vary from shader to shader, but often this is just multiplied against the diffuse texture right at the start. This represents the Color param ‘color’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also material_set_param_id

§Examples
use stereokit_rust::{material::Material, util::named_colors};

let mut material = Material::unlit().copy();
material.color_tint(named_colors::RED);
assert_eq!(material.get_all_param_info().get_color("color"), named_colors::RED.into());
Source

pub fn diffuse_tex(&mut self, texture: impl AsRef<Tex>) -> &mut Self

The primary color texture for the shader! Diffuse, Albedo, ‘The Texture’, or whatever you want to call it, this is usually the base color that the shader works with. This represents the texture param ‘diffuse’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also Material::tex_file_copy see also material_set_param_id

§Examples
use stereokit_rust::{material::Material, tex::Tex};

let mut material = Material::unlit().copy();
let default_tex = material.get_all_param_info().get_texture("diffuse").unwrap();

let tex = Tex::from_file("textures/open_gltf.jpeg", true, None)
                   .expect("tex should be created");
material.diffuse_tex(&tex);

assert_eq!(&material.get_all_param_info().get_texture("diffuse").unwrap().get_id(),
           &tex.get_id());
assert_ne!(&default_tex.get_id(),
           &tex.get_id());
Source

pub fn emission_factor(&mut self, color: impl Into<Color128>) -> &mut Self

A multiplier for emission values sampled from the emission texture. The default emission texture in SK shaders is white, and the default value for this parameter is 0,0,0,0. This represents the Color param ‘emission_factor’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also Material::emission_tex see also material_set_param_id

§Examples
use stereokit_rust::{material::Material, util::named_colors};

let mut material = Material::pbr().copy();
material.emission_factor(named_colors::RED);
assert_eq!(material.get_all_param_info().get_color("emission_factor"), named_colors::RED.into());
Source

pub fn emission_tex(&mut self, texture: impl AsRef<Tex>) -> &mut Self

This texture is unaffected by lighting, and is frequently just added in on top of the material’s final color! Tends to look really glowy. This represents the texture param ‘emission’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also Material::emission_factor see also material_set_param_id

§Examples
use stereokit_rust::{util::named_colors, material::Material, tex::Tex};

let mut material = Material::pbr_clip().tex_file_copy("textures/water/bump_large.ktx2", true, Some(0)).unwrap();

let tex = Tex::from_file("textures/water/bump_large_inverse.ktx2", true, None)
                   .expect("tex should be created");
material.emission_tex(&tex).emission_factor(named_colors::RED);

assert_eq!(&material.get_all_param_info().get_texture("emission").unwrap().get_id(),
           &tex.get_id());
Source

pub fn metallic_amount(&mut self, amount: f32) -> &mut Self

For physically based shader, this is a multiplier to scale the metallic properties of the material. This represents the float param ‘metallic’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also Material::metal_tex see also material_set_param_id

§Examples
use stereokit_rust::{material::Material, util::named_colors};

let mut material = Material::pbr().copy();
material.metallic_amount(0.68);
assert_eq!(material.get_all_param_info().get_float("metallic"), 0.68);
Source

pub fn metal_tex(&mut self, texture: impl AsRef<Tex>) -> &mut Self

For physically based shaders, metal is a texture that encodes metallic and roughness data into the ‘B’ and ‘G’ channels, respectively. This represents the texture param ‘metal’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also Material::metallic_amount see also material_set_param_id

§Examples
use stereokit_rust::{material::Material, tex::Tex};

let mut material = Material::pbr_clip().tex_file_copy("textures/parquet2/parquet2.ktx2", true, Some(0)).unwrap();

let tex = Tex::from_file("textures/parquet2/parquet2metal.ktx2", true, None)
                   .expect("tex should be created");
material.metal_tex(&tex).metallic_amount(0.68);

assert_eq!(&material.get_all_param_info().get_texture("metal").unwrap().get_id(),
           &tex.get_id());
Source

pub fn normal_tex(&mut self, texture: impl AsRef<Tex>) -> &mut Self

The ‘normal map’ texture for the material! This texture contains information about the direction of the material’s surface, which is used to calculate lighting, and make surfaces look like they have more detail than they actually do. Normals are in Tangent Coordinate Space, and the RGB values map to XYZ values. This represents the texture param ‘normal’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also material_set_param_id

§Examples
use stereokit_rust::{material::Material, tex::Tex};

let mut material = Material::from_file("shaders/water_pbr2.hlsl.sks", None).unwrap();

let tex = Tex::from_file("textures/water/bump_large.ktx2", true, None)
                   .expect("tex should be created");
material.normal_tex(&tex);

assert_eq!(&material.get_all_param_info().get_texture("normal").unwrap().get_id(),
           &tex.get_id());
Source

pub fn occlusion_tex(&mut self, texture: impl AsRef<Tex>) -> &mut Self

Used by physically based shaders, this can be used for baked ambient occlusion lighting, or to remove specular reflections from areas that are surrounded by geometry that would likely block reflections. This represents the texture param ‘occlusion’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also material_set_param_id

§Examples
use stereokit_rust::{material::Material, tex::Tex};

let mut material = Material::pbr().tex_file_copy("textures/parquet2/parquet2.ktx2", true, None).unwrap();

let tex = Tex::from_file("textures/parquet2/parquet2ao.ktx2", true, None)
                   .expect("tex should be created");
material.occlusion_tex(&tex);

assert_eq!(&material.get_all_param_info().get_texture("occlusion").unwrap().get_id(),
           &tex.get_id());
Source

pub fn roughness_amount(&mut self, amount: f32) -> &mut Self

For physically based shader, this is a multiplier to scale the roughness properties of the material. This represents the float param ‘roughness’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also material_set_param_id

§Examples
use stereokit_rust::material::Material;

let mut material = Material::pbr().copy();
material.roughness_amount(0.78);

assert_eq!(material.get_all_param_info().get_float("roughness"), 0.78);
Source

pub fn tex_scale(&mut self, scale: f32) -> &mut Self

👎Deprecated since 0.40.0: please use tex_transform instead

Not necessarily present in all shaders, this multiplies the UV coordinates of the mesh, so that the texture will repeat. This is great for tiling textures! This represents the float param ‘tex_scale’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also material_set_param

Source

pub fn time(&mut self, time: f32) -> &mut Self

Non canonical shader parameter to indicate a time multiplier if the shader have one (water, blinker …) https://stereokit.net/Pages/StereoKit/MatParamName.html

see also material_set_param_id

§Examples
use stereokit_rust::material::Material;

let mut material = Material::from_file("shaders/water_pbr2.hlsl.sks", None).unwrap();
material.time(0.38);

assert_eq!(material.get_all_param_info().get_float("time"), 0.38);
Source

pub fn tex_transform(&mut self, transform: impl Into<Vec4>) -> &mut Self

Not necessarily present in all shaders, this transforms the UV coordinates of the mesh, so that the texture can repeat and scroll. XY components are offset, and ZW components are scale.

This represents the float param ‘tex_trans’. https://stereokit.net/Pages/StereoKit/MatParamName.html

see also material_set_param_id

§Examples
use stereokit_rust::{maths::Vec4, material::Material};

let mut material = Material::unlit().copy();
material.tex_transform(Vec4::ONE * 5.5);

assert_eq!(material.get_all_param_info().get_vector4("tex_trans"), Vec4::ONE * 5.5);
Source

pub fn transparency(&mut self, mode: Transparency) -> &mut Self

What type of transparency does this Material use? Default is None. Transparency has an impact on performance, and draw order. Check the Transparency enum for details. https://stereokit.net/Pages/StereoKit/Material/Transparency.html

see also material_set_transparency

§Examples
use stereokit_rust::{maths::{Vec3, Matrix, Quat}, util::{named_colors,Color32},
                     mesh::Mesh, material::{Material, Transparency}};

// Creating Meshes and their materials
let cube = Mesh::generate_cube(Vec3::ONE * 0.8, None);
let sphere = Mesh::generate_sphere(1.4, None);

let mut material_sphere = Material::pbr().copy();
material_sphere.color_tint(named_colors::BLUE).transparency(Transparency::Add);

let material_cube = Material::pbr().copy();
let cube_transform = Matrix::r(Quat::from_angles(40.0, 50.0, 20.0));

assert_eq!(material_sphere.get_transparency(), Transparency::Add);
assert_eq!(material_cube.get_transparency(), Transparency::None);
filename_scr = "screenshots/material_transparency.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
    cube.draw(token, &material_cube, cube_transform, None, None);
    sphere.draw(token, &material_sphere, Matrix::IDENTITY, None, None);
);
screenshot
Source

pub fn face_cull(&mut self, mode: Cull) -> &mut Self

How should this material cull faces? https://stereokit.net/Pages/StereoKit/Material/FaceCull.html

see also material_set_cull

§Examples
use stereokit_rust::{maths::{Vec3, Matrix}, util::{named_colors,Color32},
                     mesh::Mesh, material::{Material, Cull}};

// Creating Meshes and their materials
let cube1 = Mesh::generate_cube(Vec3::ONE * 1.0, None);
let cube2 = Mesh::generate_cube(Vec3::ONE * 0.4, None);

let mut material_cube1 = Material::pbr().copy();
material_cube1.face_cull(Cull::Front).color_tint(named_colors::RED);

let mut material_cube2 = Material::pbr().copy();
assert_eq!(material_cube2.get_face_cull(), Cull::Back);
material_cube2.face_cull(Cull::None).color_tint(named_colors::GREEN);

assert_eq!(material_cube1.get_face_cull(), Cull::Front);
assert_eq!(material_cube2.get_face_cull(), Cull::None);

filename_scr = "screenshots/material_face_cull.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
    cube1.draw(token, &material_cube1,  Matrix::IDENTITY, None, None);
    cube2.draw(token, &material_cube2,  Matrix::IDENTITY, None, None);
);
screenshot
Source

pub fn wireframe(&mut self, wireframe: bool) -> &mut Self

Should this material draw only the edges/wires of the mesh? This can be useful for debugging, and even some kinds of visualization work.

Note that this may not work on some mobile OpenGL systems like Quest. https://stereokit.net/Pages/StereoKit/Material/Wireframe.html

see also material_set_wireframe

§Examples
use stereokit_rust::{util::{named_colors,Color32},material::Material};

let mut material_cube = Material::pbr().copy();
assert_eq!(material_cube.get_wireframe(), false);
material_cube.wireframe(true).color_tint(named_colors::CYAN);
assert_eq!(material_cube.get_wireframe(), true);
Source

pub fn depth_test(&mut self, depth_test_mode: DepthTest) -> &mut Self

How does this material interact with the ZBuffer? Generally DepthTest::Less would be normal behavior: don’t draw objects that are occluded. But this can also be used to achieve some interesting effects, like you could use DepthTest::Greater to draw a glow that indicates an object is behind something. https://stereokit.net/Pages/StereoKit/Material/DepthTest.html

see also material_set_depth_test

§Examples
use stereokit_rust::{ util::{named_colors,Color32}, material::{Material, DepthTest}};

let mut material_cube = Material::pbr().copy();
assert_eq!(material_cube.get_depth_test(), DepthTest::Less);
material_cube.depth_test(DepthTest::Greater).color_tint(named_colors::CYAN);
assert_eq!(material_cube.get_depth_test(), DepthTest::Greater);
Source

pub fn depth_write(&mut self, write_enabled: bool) -> &mut Self

Should this material write to the ZBuffer? For opaque objects, this generally should be true. But transparent objects writing to the ZBuffer can be problematic and cause draw order issues. Note that turning this off can mean that this material won’t get properly accounted for when the MR system is performing late stage reprojection. Not writing to the buffer can also be faster! :) https://stereokit.net/Pages/StereoKit/Material/DepthWrite.html

see also material_set_depth_write

§Examples
use stereokit_rust::{util::{named_colors,Color32},material::Material};

let mut material_cube = Material::pbr().copy();
assert_eq!(material_cube.get_depth_write(), true);
material_cube.depth_write(false).color_tint(named_colors::CYAN);
assert_eq!(material_cube.get_depth_write(), false);
Source

pub fn queue_offset(&mut self, offset: i32) -> &mut Self

This property will force this material to draw earlier or later in the draw queue. Positive values make it draw later, negative makes it earlier. This can be helpful for tweaking performance! If you know an object is always going to be close to the user and likely to obscure lots of objects (like hands), drawing it earlier can mean objects behind it get discarded much faster! Similarly, objects that are far away (skybox!) can be pushed towards the back of the queue, so they’re more likely to be discarded early. https://stereokit.net/Pages/StereoKit/Material/QueueOffset.html

see also material_set_queue_offset

§Examples
use stereokit_rust::{util::{named_colors,Color32},material::Material};

let mut material_cube = Material::pbr().copy();
assert_eq!(material_cube.get_queue_offset(), 0);
material_cube.queue_offset(8).color_tint(named_colors::CYAN);
assert_eq!(material_cube.get_queue_offset(), 8);
Source

pub fn chain(&mut self, chained_material: &Material) -> &mut Self

Allows you to chain Materials together in a form of multi-pass rendering! Any time the Material is used, the chained Materials will also be used to draw the same item. https://stereokit.net/Pages/StereoKit/Material/Chain.html

see also material_set_chain

§Examples
use stereokit_rust::material::Material;

let mut material_cube = Material::pbr().copy();
assert!(material_cube.get_chain().is_none());

let mut material_to_chain = Material::ui_quadrant().copy();
material_to_chain.id("material_to_chain");
material_cube.chain(&material_to_chain);
assert_eq!(material_cube.get_chain().unwrap().get_id(), material_to_chain.get_id());
Source

pub fn get_id(&self) -> &str

Source

pub fn get_shader(&self) -> Shader

Source

pub fn get_transparency(&self) -> Transparency

Source

pub fn get_face_cull(&self) -> Cull

Source

pub fn get_wireframe(&self) -> bool

Source

pub fn get_depth_test(&self) -> DepthTest

Source

pub fn get_depth_write(&self) -> bool

Source

pub fn get_queue_offset(&self) -> i32

Source

pub fn get_chain(&self) -> Option<Material>

Source

pub fn get_all_param_info(&self) -> ParamInfos<'_>

Get All param infos. https://stereokit.net/Pages/StereoKit/Material/GetAllParamInfo.html

see also ParamInfos ParamInfo

§Examples
use stereokit_rust::{material::{Material, MaterialParam}, shader::Shader};

let material = Material::new(Shader::pbr(), Some("my_material"));
let param_infos = material.get_all_param_info();
assert_ne!(param_infos.get_count(), 0);
for param in param_infos {
   match param.name.as_str()  {
       "diffuse" | "emission" | "metal" | "occlusion"  
            => assert_eq!(param.type_info, MaterialParam::Texture),
       "color" | "emission_factor"  
            => assert_eq!(param.type_info, MaterialParam::Color128),
       "metallic" | "roughness"  
            => assert_eq!(param.type_info, MaterialParam::Float),
       "tex_trans"  
            => assert_eq!(param.type_info, MaterialParam::Vec4),
       _ => {}
   }
}
Source

pub fn pbr() -> Self

The default Physically Based Rendering material! This is used by StereoKit anytime a mesh or model has metallic or roughness properties, or needs to look more realistic. Its shader may change based on system performance characteristics, so it can be great to copy this one when creating your own materials! Or if you want to override StereoKit’s default PBR behavior, here’s where you do it! Note that the shader used by default here is much more costly than Default.Material. https://stereokit.net/Pages/StereoKit/Material/PBR.html

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::pbr();
assert_eq!(material.get_id(), "default/material_pbr");
Source

pub fn pbr_clip() -> Self

Same as MaterialPBR, but it uses a discard clip for transparency. https://stereokit.net/Pages/StereoKit/Material/PBRClip.html

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::pbr_clip();
assert_eq!(material.get_id(), "default/material_pbr_clip");
Source

pub fn unlit() -> Self

The default unlit material! This is used by StereoKit any time a mesh or model needs to be rendered with an unlit surface. Its shader may change based on system performance characteristics, so it can be great to copy this one when creating your own materials! Or if you want to override StereoKit’s default unlit behavior, here’s where you do it! https://stereokit.net/Pages/StereoKit/Material/Unlit.html

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::unlit();
assert_eq!(material.get_id(), "default/material_unlit");
Source

pub fn unlit_clip() -> Self

The default unlit material with alpha clipping! This is used by StereoKit for unlit content with transparency, where completely transparent pixels are discarded. This means less alpha blending, and fewer visible alpha blending issues! In particular, this is how Sprites are drawn. Its shader may change based on system performance characteristics, so it can be great to copy this one when creating your own materials! Or if you want to override StereoKit’s default unlit clipped behavior, here’s where you do it! https://stereokit.net/Pages/StereoKit/Material/UnlitClip.html

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::unlit_clip();
assert_eq!(material.get_id(), "default/material_unlit_clip");
Source

pub fn equirect() -> Self

The material used by cubemap https://stereokit.net/Pages/StereoKit/Material.html

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::equirect();
assert_eq!(material.get_id(), "default/equirect_convert");
Source

pub fn font() -> Self

The material used by font https://stereokit.net/Pages/StereoKit/Material.html

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::font();
assert_eq!(material.get_id(), "default/material_font");
Source

pub fn hand() -> Self

The material used for hands https://stereokit.net/Pages/StereoKit/Material.html

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::hand();
assert_eq!(material.get_id(), "default/material_hand");
Source

pub fn ui() -> Self

The material used by the UI! By default, it uses a shader that creates a ‘finger shadow’ that shows how close the finger is to the UI. https://stereokit.net/Pages/StereoKit/Material/UI.html

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::ui();
assert_eq!(material.get_id(), "default/material_ui");
Source

pub fn ui_box() -> Self

A material for indicating interaction volumes! It renders a border around the edges of the UV coordinates that will ‘grow’ on proximity to the user’s finger. It will discard pixels outside of that border, but will also show the finger shadow. This is meant to be an opaque material, so it works well for depth LSR. This material works best on cube-like meshes where each face has UV coordinates from 0-1. Shader Parameters: color - color border_size - meters border_size_grow - meters border_affect_radius - meters https://stereokit.net/Pages/StereoKit/Material/UIBox.html

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::ui_box();
assert_eq!(material.get_id(), "default/material_ui_box");
Source

pub fn ui_quadrant() -> Self

The material used by the UI for Quadrant Sized UI elements. See UI.QuadrantSizeMesh for additional details. By default, it uses a shader that creates a ‘finger shadow’ that shows how close the finger is to the UI. https://stereokit.net/Pages/StereoKit/Material.html

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::ui_quadrant();
assert_eq!(material.get_id(), "default/material_ui_quadrant");
Source

pub fn ui_aura() -> Self

The material used by the UI for Aura, an extra space and visual element that goes around Window elements to make them easier to grab https://stereokit.net/Pages/StereoKit/Material.html

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::ui_aura();
assert_eq!(material.get_id(), "default/material_ui_aura");

Trait Implementations§

Source§

impl AsRef<Material> for Material

Source§

fn as_ref(&self) -> &Material

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for Material

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Material

Source§

fn default() -> Self

The default material! This is used by many models and meshes rendered from within StereoKit. Its shader is tuned for high performance, and may change based on system performance characteristics, so it can be great to copy this one when creating your own materials! Or if you want to override StereoKit’s default material, here’s where you do it! https://stereokit.net/Pages/StereoKit/Material/Default.html

see also crate::font::font_find

§Examples
use stereokit_rust::{material::Material};
let mut material = Material::default();
assert_eq!(material.get_id(), "default/material");
Source§

impl Drop for Material

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl IAsset for Material

Source§

fn get_id(&self) -> &str

gets the unique identifier of this asset resource! This can be helpful for debugging, managing your assets, or finding them later on! https://stereokit.net/Pages/StereoKit/IAsset/Id.html
Source§

impl PartialEq for Material

Source§

fn eq(&self, other: &Material) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Material

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more