#[repr(C)]pub struct Shader(pub NonNull<_ShaderT>);
Expand description
A shader is a piece of code that runs on the GPU, and determines how model data gets transformed into pixels on screen! It’s more likely that you’ll work more directly with Materials, which shaders are a subset of.
With this particular class, you can mostly just look at it. It doesn’t do a whole lot. Maybe you can swap out the shader code or something sometimes! https://stereokit.net/Pages/StereoKit/Shader.html
see also crate::material::Material
§Examples
use stereokit_rust::{shader::Shader, material::Material,
mesh::Mesh, maths::{Matrix, Vec2, Vec3, Vec4}};
let plane = Mesh::generate_plane( Vec2::ONE*2.0, Vec3::NEG_Z, Vec3::X, None, true);
let shader = Shader::from_file("shaders/brick_pbr.hlsl.sks").unwrap();
let mut material = Material::new(shader,Some("my_material"));
material.tex_transform(Vec4::new(0.0, 0.0, 0.03, 0.03));
filename_scr = "screenshots/shaders.jpeg";
test_screenshot!(
plane.draw(token, &material, Matrix::IDENTITY, None, None);
);

Tuple Fields§
§0: NonNull<_ShaderT>
Implementations§
Source§impl Shader
impl Shader
Sourcepub fn from_memory(data: &[u8]) -> Result<Shader, StereoKitError>
pub fn from_memory(data: &[u8]) -> Result<Shader, StereoKitError>
Loads an image file stored in memory directly into a texture! Supported formats are: jpg, png, tga, bmp, psd, gif, hdr, pic. Asset Id will be the same as the filename. https://stereokit.net/Pages/StereoKit/Shader/FromMemory.html
data
- A precompiled StereoKit Shader file as bytes.
see also shader_create_mem
§Examples
use stereokit_rust::{shader::Shader};
let shader_data = std::include_bytes!("../assets/shaders/brick_pbr.hlsl.sks");
let mut shader = Shader::from_memory(shader_data).unwrap();
assert_eq!(shader.get_name(), "the_name_of_brick_pbr");
Sourcepub fn from_file(file_utf8: impl AsRef<Path>) -> Result<Shader, StereoKitError>
pub fn from_file(file_utf8: impl AsRef<Path>) -> Result<Shader, StereoKitError>
Loads a shader from a precompiled StereoKit Shader (.sks) file! HLSL files can be compiled using the skshaderc
tool called with cargo compile_sks
or cargo build_sk_rs
.
https://stereokit.net/Pages/StereoKit/Shader/FromFile.html
file_utf8
- Path to a precompiled StereoKit Shader file! If no .sks extension is part of this path, StereoKit will automatically add it and check that first.
see also crate::material::Material::new
shader_create_file
see example in Shader
Sourcepub fn find<S: AsRef<str>>(id: S) -> Result<Shader, StereoKitError>
pub fn find<S: AsRef<str>>(id: S) -> Result<Shader, StereoKitError>
Looks for a shader asset that’s already loaded, matching the given id! https://stereokit.net/Pages/StereoKit/Shader/Find.html
id
- For shaders loaded from file, this’ll be the shader’s metadata name!
see also shader_find
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::from_file("shaders/brick_pbr.hlsl.sks")
.expect("Brick shader should be there");
shader.id("my_brick_shader");
let mut shader_again = Shader::find("my_brick_shader");
assert!(shader_again.is_ok(), "Failed to find shader");
assert_eq!(shader_again.unwrap().get_id(), shader.get_id());
Sourcepub fn clone_ref(&self) -> Shader
pub fn clone_ref(&self) -> Shader
Creates a clone of the same reference. Basically, the new variable is the same asset. This is what you get by calling Shader::find method. https://stereokit.net/Pages/StereoKit/Shader/Find.html
see also shader_find()
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::from_file("shaders/brick_pbr.hlsl.sks")
.expect("Brick shader should be there");
shader.id("my_brick_shader");
let mut shader_again = shader.clone_ref();
assert_eq!(shader_again.get_id(), "my_brick_shader");
assert_eq!(shader_again, shader);
Sourcepub fn id<S: AsRef<str>>(&mut self, id: S) -> &mut Self
pub fn id<S: AsRef<str>>(&mut self, id: S) -> &mut Self
Gets or sets 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/Shader/Id.html
see also shader_set_id
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::from_file("shaders/brick_pbr.hlsl.sks")
.expect("Brick shader should be there");
shader.id("my_brick_shader");
assert_eq!(shader.get_id(), "my_brick_shader");
Sourcepub fn get_id(&self) -> &str
pub fn get_id(&self) -> &str
The id of this shader https://stereokit.net/Pages/StereoKit/Shader/Id.html
see also shader_get_id
see example in Shader::id
Sourcepub fn get_name(&self) -> &str
pub fn get_name(&self) -> &str
The name of the shader, provided in the shader file itself. Not the filename or id. https://stereokit.net/Pages/StereoKit/Shader/Name.html
see also shader_get_name
§Examples
use stereokit_rust::{shader::Shader};
let shader = Shader::from_file("shaders/brick_pbr.hlsl.sks")
.expect("Brick shader should be there");
assert_eq!(shader.get_name(), "the_name_of_brick_pbr");
Sourcepub fn blit() -> Self
pub fn blit() -> Self
https://stereokit.net/Pages/StereoKit/Shader/Blit.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::blit();
assert_eq!(shader.get_id(), "default/shader_blit");
Sourcepub fn light_map() -> Self
pub fn light_map() -> Self
https://stereokit.net/Pages/StereoKit/Shader/LightMap.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::light_map();
assert_eq!(shader.get_id(), "default/shader_lightmap");
Sourcepub fn unlit() -> Self
pub fn unlit() -> Self
Sometimes lighting just gets in the way! This is an extremely simple and fast shader that uses a ‘diffuse’ texture and a ‘color’ tint property to draw a model without any lighting at all! https://stereokit.net/Pages/StereoKit/Shader/Unlit.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::unlit();
assert_eq!(shader.get_id(), "default/shader_unlit");
Sourcepub fn unlit_clip() -> Self
pub fn unlit_clip() -> Self
Sometimes lighting just gets in the way! This is an extremely simple and fast shader that uses a ‘diffuse’ texture and a ‘color’ tint property to draw a model without any lighting at all! This shader will also discard pixels with an alpha of zero. https://stereokit.net/Pages/StereoKit/Shader/UnlitClip.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::unlit_clip();
assert_eq!(shader.get_id(), "default/shader_unlit_clip");
Sourcepub fn font() -> Self
pub fn font() -> Self
https://stereokit.net/Pages/StereoKit/Shader/Font.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::font();
assert_eq!(shader.get_id(), "default/shader_font");
Sourcepub fn equirect() -> Self
pub fn equirect() -> Self
https://stereokit.net/Pages/StereoKit/Shader/equirect.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::equirect();
assert_eq!(shader.get_id(), "default/shader_equirect");
Sourcepub fn ui() -> Self
pub fn ui() -> Self
A shader for UI or interactable elements, this’ll be the same as the Shader, but with an additional finger ‘shadow’ and distance circle effect that helps indicate finger distance from the surface of the object. https://stereokit.net/Pages/StereoKit/Shader/UI.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::ui();
assert_eq!(shader.get_id(), "default/shader_ui");
Sourcepub fn ui_box() -> Self
pub fn ui_box() -> Self
A shader 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 shader, so it works well for depth LSR. This shader 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/Shader/UIBox.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::ui_box();
assert_eq!(shader.get_id(), "default/shader_ui_box");
Sourcepub fn ui_quadrant() -> Self
pub fn ui_quadrant() -> Self
https://stereokit.net/Pages/StereoKit/Shader.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::ui_quadrant();
assert_eq!(shader.get_id(), "default/shader_ui_quadrant");
Sourcepub fn sky() -> Self
pub fn sky() -> Self
https://stereokit.net/Pages/StereoKit/Shader.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::sky();
assert_eq!(shader.get_id(), "default/shader_sky");
Sourcepub fn pbr() -> Self
pub fn pbr() -> Self
A physically based shader. https://stereokit.net/Pages/StereoKit/Shader/PBR.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::pbr();
assert_eq!(shader.get_id(), "default/shader_pbr");
Sourcepub fn pbr_clip() -> Self
pub fn pbr_clip() -> Self
Same as ShaderPBR, but with a discard clip for transparency. https://stereokit.net/Pages/StereoKit/Shader/PBRClip.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::pbr_clip();
assert_eq!(shader.get_id(), "default/shader_pbr_clip");
Trait Implementations§
Source§impl Default for Shader
impl Default for Shader
Source§fn default() -> Self
fn default() -> Self
This is a fast, general purpose shader. It uses a texture for ‘diffuse’, a ‘color’ property for tinting the material, and a ‘tex_scale’ for scaling the UV coordinates. For lighting, it just uses a lookup from the current cubemap. https://stereokit.net/Pages/StereoKit/Shader/Default.html
§Examples
use stereokit_rust::{shader::Shader};
let mut shader = Shader::default();
assert_eq!(shader.get_id(), "default/shader");
Source§impl IAsset for Shader
impl IAsset for Shader
Source§fn get_id(&self) -> &str
fn get_id(&self) -> &str
impl StructuralPartialEq for Shader
Auto Trait Implementations§
impl Freeze for Shader
impl RefUnwindSafe for Shader
impl !Send for Shader
impl !Sync for Shader
impl Unpin for Shader
impl UnwindSafe for Shader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.