Skip to main content

RectLight

Struct RectLight 

Source
pub struct RectLight {
    pub position: Vec3,
    pub radius: f32,
    pub color: Vec3,
    pub direction: Vec3,
    pub tangent: Vec3,
    pub half_width: f32,
    pub half_height: f32,
    pub fill: bool,
}
Expand description

A rectangle that radiates from one of its faces — topic 44’s rung 5, shaded through the linearly transformed cosine fit in crcbl_shaders::ltc.

§What a rectangle is here

A centre, a plane, two half-extents and a side. The plane is direction — the way the panel faces, so a surface behind it is not lit at all — and tangent, which names the u axis inside it; the v axis is their cross product and is not stored. Neither vector has to arrive unit or perpendicular: Light::row normalises and orthogonalises them on the way into the row, because a row that broke either would be a rectangle that is not one and no picture would say so.

§The winding, which is what makes it one-sided

v is cross(tangent, direction), and the shader walks the corners -u-v, +u-v, +u+v, -u+v. That order makes the spherical polygon’s integral positive for a receiver on the side direction points at and negative behind it, and the shader takes the positive half. So a panel lights the room it faces and nothing on the other side of its own wall — which is what a window is, and what saves the far half of a scene from being lit through the floor.

Fields§

§position: Vec3

The centre of the rectangle, in render space.

§radius: f32

How far its influence reaches from that centre, in world units.

PointLight::radius’s terms, and the same hard bound: the shading window reaches exactly zero here and light_cluster.slang culls against this same sphere, so there is no radius at which the two disagree. Measured from the centre rather than from the nearest corner, which is what makes those two the same number — so a large panel wants a radius comfortably past its own half-diagonal or it will fade out before its own edge does.

§color: Vec3

Colour premultiplied by intensity — the radiance leaving the face.

A radiance rather than a power, which is what makes a rectangle behave: doubling its extent doubles the light in the room, because it is twice the emitter. A caller holding a lumen figure divides by the area.

§direction: Vec3

The direction the face radiates along, away from the panel.

SpotLight::direction’s convention — a fixture points at something — and normalised on the way into the row.

§tangent: Vec3

The u axis of the rectangle’s plane, which fixes how it is turned about its own normal.

Orthogonalised against direction and normalised on the way into the row, so a caller may hand over any vector that is not parallel to the normal — a world axis, usually. One exactly parallel to it leaves the rectangle without a plane, and Light::row picks a perpendicular rather than emitting a row of nothings.

§half_width: f32

Half the rectangle’s extent along u, in world units.

§half_height: f32

Half its extent along v, which is cross(tangent, direction).

§fill: bool

Whether this is a fill light, on PointLight::fill’s terms exactly: it lights, casts no shadow and adds no specular.

A rectangle is refused a shadow map for a second reason as well — it radiates from a surface, so there is no centre of projection to render one from — and on this kind the flag is the specular half alone.

Implementations§

Source§

impl RectLight

Source

pub fn frame(&self) -> (Vec3, Vec3)

The rectangle’s plane, as a unit normal and a unit u axis inside it.

The whole of the orthogonalisation the row needs, in one place because Light::row and Light::sphere would otherwise each have an opinion about a degenerate rectangle. A normal that is not a direction at all becomes +Z, and a tangent parallel to the normal becomes whichever world axis is least like it — both of which are arbitrary, and both of which are a rectangle rather than a row of NaNs.

Trait Implementations§

Source§

impl Clone for RectLight

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for RectLight

Source§

impl Debug for RectLight

Source§

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

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

impl PartialEq for RectLight

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RectLight

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HalThreadSafe for T
where T: Send + Sync,

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> ToOwned for T
where T: Clone,

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.