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: Vec3The centre of the rectangle, in render space.
radius: f32How 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: Vec3Colour 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: Vec3The 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: Vec3The 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: f32Half the rectangle’s extent along u, in world units.
half_height: f32Half its extent along v, which is cross(tangent, direction).
fill: boolWhether 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
impl RectLight
Sourcepub fn frame(&self) -> (Vec3, Vec3)
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.