Skip to main content

primase_core/
light_translucency.rs

1//! Source-stated parameters of a light's transmission/back-light contribution.
2use crate::{Component, Entity, Geometry, JsonError, World};
3use serde::Serialize;
4
5/// A light shader's transmission contribution: an amplitude and a multiplier of its angular exponent.
6/// The source shader defines the angular function and reference exponent. These parameters neither select a
7/// particular lighting model nor change opaque material transmission. Attached to the same entity as [`crate::Light`].
8#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
9pub struct LightTranslucency {
10    pub strength: f32,
11    pub exponent_scale: f32,
12}
13impl Component for LightTranslucency {
14    const NAME: &'static str = "core.light_translucency";
15    const GEOMETRY: Geometry = Geometry::None;
16    fn to_json(&self) -> Result<Option<serde_json::Value>, JsonError> {
17        crate::json::to_value(self).map(Some)
18    }
19    fn verify(&self, _e: Entity, _w: &World) -> Result<(), String> {
20        if !self.strength.is_finite()
21            || self.strength < 0.
22            || !self.exponent_scale.is_finite()
23            || self.exponent_scale <= 0.
24        {
25            return Err(
26                "light translucency requires finite nonnegative strength and positive exponent scale".into(),
27            );
28        }
29        Ok(())
30    }
31}