Struct SHCubemap

Source
pub struct SHCubemap {
    pub sh: SphericalHarmonics,
    pub tex: Tex,
}
Expand description

fluent syntax for Texture cubemap https://stereokit.net/Pages/StereoKit/Tex.html

see also Tex crate::util::SphericalHarmonics

§Examples

use stereokit_rust::{maths::Vec3, tex::SHCubemap, system::AssetState};

let sh_cubemap = SHCubemap::from_cubemap("hdri/sky_dawn.hdr", true, 9999)
                               .expect("Cubemap should be created");

sh_cubemap.render_as_sky();
assert_eq!(sh_cubemap.tex.get_asset_state(), AssetState::Loaded);

let tex = sh_cubemap.tex;

filename_scr = "screenshots/sh_cubemap.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
    if tex.get_asset_state() != AssetState::Loaded {iter -= 1}
);
screenshot

Fields§

§sh: SphericalHarmonics§tex: Tex

Implementations§

Source§

impl SHCubemap

Source

pub fn from_cubemap_equirectangular( equirectangular_file_utf8: impl AsRef<Path>, srgb_data: bool, priority: i32, ) -> Result<SHCubemap, StereoKitError>

👎Deprecated since 0.40.0: please use from_cubemap instead

Creates a cubemap texture from a single equirectangular image! You know, the ones that look like an unwrapped globe with the poles all stretched out. It uses some fancy shaders and texture blitting to create 6 faces from the equirectangular image. https://stereokit.net/Pages/StereoKit/Tex/FromCubemapEquirectangular.html

see also tex_create_cubemap_file

Source

pub fn from_cubemap( cubemap_file: impl AsRef<Path>, srgb_data: bool, load_priority: i32, ) -> Result<SHCubemap, StereoKitError>

Creates a cubemap texture from a single file! This will load KTX2 files with 6 surfaces, or convert equirectangular images into cubemap images. KTX2 files are the fastest way to load a cubemap, but equirectangular images can be acquired quite easily!

Equirectangular images look like an unwrapped globe with the poles all stretched out, and are sometimes referred to as HDRIs. https://stereokit.net/Pages/StereoKit/Tex/FromCubemap.html

  • cubemap_file - Filename of the cubemap image.
  • srgb_data - Is this image color data in sRGB format, or is it normal/metal/rough/data that’s not for direct display? sRGB colors get converted to linear color space on the graphics card, so getting this right can have a big impact on visuals.
  • load_priority - The priority sort order for this asset in the async loading system. Lower values mean loading sooner.

see also tex_create_cubemap_file

§Examples
use stereokit_rust::{maths::Vec3, tex::SHCubemap, system::AssetState};

let sh_cubemap = SHCubemap::from_cubemap("hdri/sky_dawn.hdr", true, 9999)
                               .expect("Cubemap should be created");
sh_cubemap.render_as_sky();

assert_ne!(sh_cubemap.sh.coefficients[0], Vec3::ZERO);
assert_ne!(sh_cubemap.sh.coefficients[8], Vec3::ZERO);

let tex = sh_cubemap.tex;

test_steps!( // !!!! Get a proper main loop !!!!
    if tex.get_asset_state() != AssetState::Loaded {iter -= 1}
);
assert_eq!(tex.get_asset_state(), AssetState::Loaded);
Source

pub fn from_cubemap_files<P: AsRef<Path>>( files_utf8: &[P; 6], srgb_data: bool, load_priority: i32, ) -> Result<SHCubemap, StereoKitError>

Creates a cubemap texture from 6 different image files! If you have a single equirectangular image, use Tex.FromEquirectangular instead. Asset Id will be the first filename. order of the file names is +X -X +Y -Y +Z -Z https://stereokit.net/Pages/StereoKit/Tex/FromCubemapFile.html

  • files_utf8 - 6 image filenames, in order of/ +X, -X, +Y, -Y, +Z, -Z.
  • srgb_data - Is this image color data in sRGB format, or is it normal/metal/rough/data that’s not for direct display? sRGB colors get converted to linear color space on the graphics card, so getting this right can have a big impact on visuals.
  • load_priority - The priority sort order for this asset in the async loading system. Lower values mean loading sooner.

see also tex_create_cubemap_files

§Examples
use stereokit_rust::{system::AssetState, tex::SHCubemap};

let cubemap_files = [
    "hdri/giza/right.png",
    "hdri/giza/left.png",
    "hdri/giza/top.png",
    "hdri/giza/bottom.png",
    "hdri/giza/front.png",
    "hdri/giza/back.png",
];
let sh_cubemap = SHCubemap::from_cubemap_files(&cubemap_files, true, 9999)
                                .expect("Cubemap should be created");
sh_cubemap.render_as_sky();

let tex = sh_cubemap.tex;

test_steps!( // !!!! Get a proper main loop !!!!
    if tex.get_asset_state() != AssetState::Loaded {iter -= 1}
);
assert_eq!(tex.get_asset_state(), AssetState::Loaded);
Source

pub fn gen_cubemap_gradient( gradient: impl AsRef<Gradient>, gradient_dir: impl Into<Vec3>, resolution: i32, ) -> SHCubemap

Generates a cubemap texture from a gradient and a direction! These are entirely suitable for skyboxes, which you can set via Renderer.SkyTex. https://stereokit.net/Pages/StereoKit/Tex/GenCubemap.html

  • gradient - A color gradient the generator will sample from! This looks at the 0-1 range of the gradient.
  • gradient_dir - This vector points to where the ‘top’ of the color gradient will go. Conversely, the ‘bottom’ of the gradient will be opposite, and it’ll blend along that axis.
  • resolution - The square size in pixels of each cubemap face! This generally doesn’t need to be large, unless you have a really complicated gradient. 16 is a good default value.

see also tex_gen_cubemap

§Examples
use stereokit_rust::{maths::Vec3, tex::SHCubemap, system::AssetState,
                     util::{named_colors, Gradient, GradientKey, Color128}};

let mut keys = [
    GradientKey::new(Color128::BLACK_TRANSPARENT, 0.0),
    GradientKey::new(named_colors::RED, 0.1),
    GradientKey::new(named_colors::CYAN, 0.4),
    GradientKey::new(named_colors::YELLOW, 0.5),
    GradientKey::new(Color128::BLACK, 0.7)];

let sh_cubemap = SHCubemap::gen_cubemap_gradient(Gradient::new(Some(&keys)),
                                                 Vec3::UP, 128);
sh_cubemap.render_as_sky();

let tex = sh_cubemap.tex;
assert_eq!(tex.get_asset_state(), AssetState::Loaded);
assert_ne!(sh_cubemap.sh.coefficients[0], Vec3::ZERO);
assert_ne!(sh_cubemap.sh.coefficients[8], Vec3::ZERO);
test_steps!( // !!!! Get a proper main loop !!!!
);
Source

pub fn gen_cubemap_sh( lighting: SphericalHarmonics, resolution: i32, light_spot_size_pct: f32, light_spot_intensity: f32, ) -> SHCubemap

Create the associated cubemap texture with the light spot. warning ! The SphericalHarmonics is moved to the result struct. https://stereokit.net/Pages/StereoKit/Tex/GenCubemap.html

  • lighting - Lighting information stored in a SphericalHarmonics.
  • resolution - The square size in pixels of each cubemap face! This generally doesn’t need to be large, as SphericalHarmonics typically contain pretty low frequency information.
  • light_spot_size_pct - The size of the glowing spot added in the primary light direction. You can kinda think of the unit as a percentage of the cubemap face’s size, but it’s technically a Chebyshev distance from the light’s point on a 2m cube.
  • light_spot_intensity - The glowing spot’s color is the primary light direction’s color, but multiplied by this value. Since this method generates a 128bpp texture, this is not clamped between 0-1, so feel free to go nuts here! Remember that reflections will often cut down some reflection intensity.

see also tex_gen_cubemap_sh

§Examples
use stereokit_rust::{maths::Vec3, tex::SHCubemap, system::AssetState,
                     util::{named_colors, SHLight, SphericalHarmonics}};

let lights: [SHLight; 1] = [SHLight::new(Vec3::ONE, named_colors::WHITE); 1];
let sh = SphericalHarmonics::from_lights(&lights);
let sh_cubemap = SHCubemap::gen_cubemap_sh(sh, 128, 0.5, 1.0);
sh_cubemap.render_as_sky();

let tex = sh_cubemap.tex;
assert_eq!(tex.get_asset_state(), AssetState::Loaded);
assert_eq!(sh_cubemap.sh.get_dominent_light_direction(), -Vec3::ONE.get_normalized());
assert_ne!(sh_cubemap.sh.coefficients[0], Vec3::ZERO);
assert_ne!(sh_cubemap.sh.coefficients[1], Vec3::ZERO);
assert_eq!(sh_cubemap.sh.coefficients[8], Vec3::ZERO);
test_steps!( // !!!! Get a proper main loop !!!!
);
Source

pub fn get_cubemap_lighting(cubemap_texture: impl AsRef<Tex>) -> SHCubemap

Get the associated lighting extracted from the cubemap. https://stereokit.net/Pages/StereoKit/Tex/CubemapLighting.html

see also tex_gen_cubemap_sh

§Examples
use stereokit_rust::{maths::Vec3, tex::SHCubemap, system::AssetState,
                     util::{named_colors, SHLight, SphericalHarmonics}};

let lights: [SHLight; 1] = [SHLight::new(Vec3::ONE, named_colors::WHITE); 1];
let sh = SphericalHarmonics::from_lights(&lights);
let sh_cubemap = SHCubemap::gen_cubemap_sh(sh, 128, 0.5, 1.0);
let tex = sh_cubemap.tex;

let sh_cubemap2 = SHCubemap::get_cubemap_lighting(tex);
let tex2 = sh_cubemap2.tex;
assert_eq!(tex2.get_asset_state(), AssetState::Loaded);
assert_eq!(sh_cubemap2.sh.get_dominent_light_direction(), -Vec3::ONE.get_normalized());
assert_ne!(sh_cubemap2.sh.coefficients[0], Vec3::ZERO);
assert_ne!(sh_cubemap2.sh.coefficients[1], Vec3::ZERO);
assert_eq!(sh_cubemap2.sh.coefficients[8], Vec3::ZERO);
Source

pub fn get_rendered_sky() -> SHCubemap

Get the cubemap texture and SH light of the the current skylight https://stereokit.net/Pages/StereoKit/Renderer/SkyLight.html https://stereokit.net/Pages/StereoKit/Renderer/SkyTex.html

see also crate::system::Renderer

§Examples
use stereokit_rust::tex::SHCubemap;

let sh_cubemap = SHCubemap::get_rendered_sky();

let tex = sh_cubemap.tex;
assert_eq!(tex.get_id(), "default/cubemap");
Source

pub fn render_as_sky(&self)

set the spherical harmonics as skylight and the the cubemap texture as skytex https://stereokit.net/Pages/StereoKit/Renderer/SkyLight.html https://stereokit.net/Pages/StereoKit/Renderer/SkyTex.html

see also see also crate::system::Renderer

§Examples
use stereokit_rust::{maths::Vec3, tex::SHCubemap, system::{AssetState, Renderer}};

let mut sh_cubemap = SHCubemap::from_cubemap("hdri/sky_dawn.hdr", true, 9999)
                               .expect("Cubemap should be created");
assert_eq!(Renderer::get_enable_sky(), true);

sh_cubemap.render_as_sky();

Renderer::enable_sky(false);
assert_eq!(Renderer::get_enable_sky(), false);
Source

pub fn get(&self) -> (SphericalHarmonics, Tex)

Get the cubemap tuple

see also Tex crate::util::SphericalHarmonics

§Examples
use stereokit_rust::{tex::SHCubemap, maths::Vec3};

let sh_cubemap = SHCubemap::get_rendered_sky();

let (sh, tex) = sh_cubemap.get();
assert_eq!(tex.get_id(), "default/cubemap");
assert_eq!(sh.get_dominent_light_direction(), Vec3 { x: -0.20119436, y: -0.92318374, z: -0.32749438 });

Trait Implementations§

Source§

impl Debug for SHCubemap

Source§

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

Formats the value using the given formatter. Read more

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> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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