Struct rustic_zen::scene::Light

source ·
pub struct Light<R: Rng> {
    pub location: SamplerPoint<R>,
    pub power: Sampler<f64, R>,
    pub polar_distance: Sampler<f64, R>,
    pub polar_angle: Sampler<f64, R>,
    pub ray_angle: Sampler<f64, R>,
    pub wavelength: Sampler<f64, R>,
}
Expand description

Definition of a Light Source in for a scene.

§Examples

Manually make a warm white small round light:

use rustic_zen::prelude::*;

let l = Light {
    power: Sampler::new_const(1.0),
    location: (512.0, 512.0).into(),
    polar_angle: Sampler::new_const(0.0),
    polar_distance: Sampler::new_const(0.0),
    ray_angle: Sampler::new_range(360.0, 0.0),
    wavelength: Sampler::new_blackbody(5800.0),
};

let scene = Scene::new(1920,1080).with_light(l);

Fields§

§location: SamplerPoint<R>

coordinates of the light in the scene.

§power: Sampler<f64, R>

Brightness of this light relative to other lights in the scene. This is a proportion of the total power of all lights of the scene. So if you have 50 lights of power 1 each light has a 1 in 50 chance of being selected to spawn a ray. However adding 1 more light with power 10 will lower the existing lights to 1 in 60 and the new light will have 1 in 6. once used this is quite intuitive, the power will change the relative brightness of the lights, without changing the overall brightness of the scene.

§polar_distance: Sampler<f64, R>

distance from location that the light ray will spawn, this can be used to create lights that are larger than a single pixel Fixing this to a single value will create a ring where the rays spawn, using a range of 0 - size will create a filled circle of spawn points.

§polar_angle: Sampler<f64, R>

combined with polar_distance this creates a vector that is added to location to generate the final point the light ray will spawn. Using a range of 360 - 0 will create a full circle, constraining this can create an arc.

§ray_angle: Sampler<f64, R>

Angle at which the spawned ray will fly away from the light. This is in absolute screen angle (0 is right). Setting this to a range of 0 - 360 will create an omidirectional light, constraining this range creates a more cone like light. Constraining it all the way to a single fixed value will create a laser. Using a polar_distance > 0 is recomended if the ray_angle is constrained to a single value, as a ray 1 pixel wide can be hard to see.

§wavelength: Sampler<f64, R>

Wavelength of spawned ray in nanometers. Only values of 380.0 - 700.0 are visible. Using a fixed value will create a strongly coloured light of that wavelength. To create natural looking white lights use Sampler::new_blackbody(<temp>). Blackbody tempratures of 1,000 to 10,000 kelvin are visible.

§Warning

Rays are sampled until a visible wavelength is found, this is an optimisation, selecting a fixed value or range of values outside of the visible spectrum can crash the render. So can selecting extreme blackbody tempratures.

Implementations§

source§

impl<R> Light<R>
where R: Rng,

source

pub fn new<A, B, C, D, E, F>( location: A, power: B, polar_distance: C, polar_angle: D, ray_angle: E, wavelength: F ) -> Self
where A: Into<SamplerPoint<R>>, B: Into<Sampler<f64, R>>, C: Into<Sampler<f64, R>>, D: Into<Sampler<f64, R>>, E: Into<Sampler<f64, R>>, F: Into<Sampler<f64, R>>,

Helper function to create a Light quickly, using common casts available in the library.

§Example Usage

Create the same small round light as above using the helper:

use rustic_zen::prelude::*;

let l = Light::new((512.0,512.0), 1.0, 0.0, 0.0, (360.0, 0.0), Sampler::new_blackbody(5800.0));

let scene = Scene::new(1920,1080).with_light(l);

Trait Implementations§

source§

impl<R: Clone + Rng> Clone for Light<R>

source§

fn clone(&self) -> Light<R>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<R> Freeze for Light<R>

§

impl<R> !RefUnwindSafe for Light<R>

§

impl<R> Send for Light<R>

§

impl<R> Sync for Light<R>

§

impl<R> Unpin for Light<R>

§

impl<R> !UnwindSafe for Light<R>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V