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

Fields§
§sh: SphericalHarmonics
§tex: Tex
Implementations§
Source§impl SHCubemap
impl SHCubemap
Sourcepub 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
pub fn from_cubemap_equirectangular( equirectangular_file_utf8: impl AsRef<Path>, srgb_data: bool, priority: i32, ) -> Result<SHCubemap, StereoKitError>
from_cubemap
insteadCreates 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
Sourcepub fn from_cubemap(
cubemap_file: impl AsRef<Path>,
srgb_data: bool,
load_priority: i32,
) -> Result<SHCubemap, StereoKitError>
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);
Sourcepub fn from_cubemap_files<P: AsRef<Path>>(
files_utf8: &[P; 6],
srgb_data: bool,
load_priority: i32,
) -> Result<SHCubemap, StereoKitError>
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);
Sourcepub fn gen_cubemap_gradient(
gradient: impl AsRef<Gradient>,
gradient_dir: impl Into<Vec3>,
resolution: i32,
) -> SHCubemap
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 !!!!
);
Sourcepub fn gen_cubemap_sh(
lighting: SphericalHarmonics,
resolution: i32,
light_spot_size_pct: f32,
light_spot_intensity: f32,
) -> SHCubemap
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 !!!!
);
Sourcepub fn get_cubemap_lighting(cubemap_texture: impl AsRef<Tex>) -> SHCubemap
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);
Sourcepub fn get_rendered_sky() -> SHCubemap
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");
Sourcepub fn render_as_sky(&self)
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);
Sourcepub fn get(&self) -> (SphericalHarmonics, Tex)
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§
Auto Trait Implementations§
impl Freeze for SHCubemap
impl RefUnwindSafe for SHCubemap
impl Send for SHCubemap
impl Sync for SHCubemap
impl Unpin for SHCubemap
impl UnwindSafe for SHCubemap
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.