Shader

Struct Shader 

Source
#[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);
);
screenshot

Tuple Fields§

§0: NonNull<_ShaderT>

Implementations§

Source§

impl Shader

Source

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");
Source

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

Source

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());
Source

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);
Source

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");
Source

pub fn get_id(&self) -> &str

Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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 AsRef<Shader> for Shader

Source§

fn as_ref(&self) -> &Shader

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

impl Debug for Shader

Source§

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

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

impl Default for Shader

Source§

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 Drop for Shader

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl IAsset for Shader

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 Shader

Source§

fn eq(&self, other: &Shader) -> 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 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> 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