Skip to main content

ScreenFx

Struct ScreenFx 

Source
pub struct ScreenFx {
Show 15 fields pub lights: Vec<ScreenLight>, pub ambient: Vec3, pub shadow_density: f32, pub shockwaves: Vec<Shockwave>, pub reflection: Option<Reflection>, pub haze: f32, pub auto_shafts: bool, pub flash: Vec3, pub flash_decay: f32, pub shaft_origin: Option<Vec2>, pub shaft_strength: f32, pub shaft_target: f32, pub shaft_ease: f32, pub shaft_tint: Vec3, pub time: f32,
}
Expand description

Transient screen effects. Lives on the engine as engine.fx.

Fields§

§lights: Vec<ScreenLight>

This frame’s lights. Cleared by the engine after every render, so a game pushes the lights it wants every frame.

§ambient: Vec3

The light every pixel gets with no light on it. White is unlit: the scene as drawn. Anything darker turns the light map on.

§shadow_density: f32

How much light one fully covered shadow sample removes. Higher is harder-edged, denser shadow.

§shockwaves: Vec<Shockwave>§reflection: Option<Reflection>

A floor reflection, if the scene has a floor worth reflecting in. Set every frame it should show; cleared with clear_reflection.

§haze: f32

Heat shimmer over the whole frame, 0.0 to about 1.0. Stronger toward the bottom of the frame, where hot air rises from.

§auto_shafts: bool

Let the renderer pick the light-shaft source itself, from whatever is brightest in the bloom, whenever no explicit source is set. Costs one tiny read-back per frame and is a frame late, which no one can see.

§flash: Vec3

Colour added to the whole frame before the tonemap, already scaled by its strength. Decays toward black.

§flash_decay: f32

Fraction of the flash that survives each second.

§shaft_origin: Option<Vec2>

Where light shafts stream from, in screen pixels, if anywhere.

§shaft_strength: f32

How strong the shafts are right now. Eases toward shaft_target.

§shaft_target: f32

Where the shaft strength is heading.

§shaft_ease: f32

How quickly the shafts ease toward the target, per second.

§shaft_tint: Vec3

A colour cast for the shafts. White lets the light’s own colour through.

§time: f32

Seconds accumulated, for anything that wants a clock.

Implementations§

Source§

impl ScreenFx

Source

pub fn new() -> Self

Source

pub fn shockwave(&mut self, x: f32, y: f32, strength: f32)

Fire a shockwave with sensible defaults for a hit: a ring that crosses a 1280-wide frame in about half a second.

strength is the peak displacement in pixels; 6 to 10 reads as a blow, 20 or more as an explosion.

Source

pub fn shockwave_with(&mut self, wave: Shockwave)

Fire a fully specified shockwave. If the cap is reached the oldest one is dropped, so the newest blow always shows.

Source

pub fn flash(&mut self, color: Vec3, strength: f32)

Flash the frame. strength of 1.0 is a full-colour hit before the tonemap rolls it off; 0.2 is a noticeable pulse.

Source

pub fn light_shaft_at(&mut self, x: f32, y: f32, strength: f32)

Stream light shafts from a screen point at the given strength. Call every frame the source is on screen; the strength eases in and out.

Source

pub fn clear_light_shaft(&mut self)

Let the shafts fade out. The origin is kept until they are gone so the fade happens in place.

Source

pub fn light( &mut self, x: f32, y: f32, radius: f32, color: Vec3, intensity: f32, )

Add a shadow-casting light for this frame.

Source

pub fn light_unshadowed( &mut self, x: f32, y: f32, radius: f32, color: Vec3, intensity: f32, )

Add a light nothing shadows, for a glow rather than a lamp.

Source

pub fn push_light(&mut self, light: ScreenLight)

Source

pub fn lighting_active(&self) -> bool

Whether the light map has anything to do this frame.

Source

pub fn pack_lights( &self, screen_w: f32, screen_h: f32, ) -> (Vec<f32>, Vec<f32>, usize)

Pack the lights for the shader: (u, v, radius_px, shadows) and (r, g, b, intensity), v flipped to texture space.

Source

pub fn reflect_at(&mut self, y: f32, strength: f32, fade: f32)

Reflect the picture about the line y pixels from the top, for fade pixels below it, at the given strength. A still, lightly blurred mirror; set the fields on Reflection for a wet one.

Source

pub fn clear_reflection(&mut self)

Source

pub fn pack_reflection(&self, screen_w: f32, screen_h: f32) -> ([f32; 4], f32)

The reflection for the shader: (line_v, strength, fade_v, ripple_px) and the blur, in texture space with v = 0 at the bottom.

Source

pub fn tick(&mut self, dt: f32)

Advance every effect by dt seconds.

Source

pub fn is_idle(&self) -> bool

Whether anything at all is active, so the renderer can skip uploads.

Source

pub fn pack_shockwaves( &self, screen_w: f32, screen_h: f32, ) -> ([[f32; 4]; 12], [f32; 12], usize)

Pack the shockwaves for the composite shader.

Returns (data, strengths, count). Each data entry is (u, v, radius_px, width_px) with u, v in texture space, which has v = 0 at the bottom, so y is flipped here from the UI’s y-down.

Source

pub fn pack_shaft(&self, screen_w: f32, screen_h: f32) -> [f32; 3]

The light-shaft source for the shader: (u, v, strength), or zero strength when there is none.

Trait Implementations§

Source§

impl Clone for ScreenFx

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 Debug for ScreenFx

Source§

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

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

impl Default for ScreenFx

Source§

fn default() -> Self

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> 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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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