Skip to main content

ShadingStrategy

Trait ShadingStrategy 

Source
pub trait ShadingStrategy: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn requirements(&self) -> &Requirements;
    fn fields(&self) -> &[FieldDesc];
    fn resolve(
        &self,
        material: &Material,
    ) -> Result<Vec<MaterialValue>, MaterialError>;

    // Provided method
    fn validate(&self, material: &Material) -> Result<(), MaterialError> { ... }
}
Expand description

Interprets a Material’s properties for a specific way of shading it. A strategy describes what GPU fields it needs (fields) and how to resolve each one from a material (resolve); it does not decide how those fields are laid out in memory - that is the responsibility of a separate packing module (see pack::aos) that consumes both methods.

Custom strategies are ordinary implementations of this trait, registered into a StrategyRegistry - no changes to ursus-materials are needed to add one.

Required Methods§

Source

fn name(&self) -> &'static str

Stable name used for lookup in StrategyRegistry and stored on Material::strategy.

Source

fn requirements(&self) -> &Requirements

What this strategy needs from a material to be able to resolve it.

Source

fn fields(&self) -> &[FieldDesc]

The fields this strategy produces, in a fixed order. resolve() returns one value per field, in this same order.

Source

fn resolve( &self, material: &Material, ) -> Result<Vec<MaterialValue>, MaterialError>

Resolves this material’s value for every field in fields(), applying this strategy’s own fallbacks for missing properties.

Provided Methods§

Source

fn validate(&self, material: &Material) -> Result<(), MaterialError>

Validates a material’s properties against requirements().

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§