Skip to content

[Materials] Add a shared energy-conserving layered PBR model #134

Description

@proggeramlug

Parent: #126
Inventory: #11 material/BRDF section

Problem

The current PBR path covers core metallic/roughness rendering, but UE-class look development needs composable, energy-conserving material lobes rather than one-off shader forks. glTF extensions such as clearcoat, sheen, anisotropy, iridescence, specular, and IOR are also common interoperability requirements.

Outcome

A versioned layered-PBR material model shared by deferred/visibility, forward transparent, path-traced, and reference-render validation paths.

Minimum first release:

  • base metallic/roughness dielectric/conductor;
  • clearcoat with independent normal/roughness;
  • sheen;
  • tangent-space anisotropy;
  • specular/IOR controls;
  • iridescence/thin-film lobe;
  • emissive energy represented consistently for exposure and GI.

Screen-space subsurface profiles may be added as a separate milestone only after the core lobe ABI is stable.

Material ABI

  • Version the GPU material record; declare exact alignment/packing once for Rust and WGSL.
  • Use a lobe/feature bitmask plus indices into texture/resource tables.
  • Centralize BRDF functions in shared WGSL included by every relevant pipeline.
  • Preserve a compact fast path for common base-only materials; do not branch every pixel through all lobes if no lobe is active.
  • Translate glTF extensions without losing texture transforms, factors, color spaces, or tangent requirements.
  • Invalid/missing tangent data must select a documented fallback or emit an actionable import warning.

Physical correctness rules

  • Enforce energy compensation between base specular/diffuse and added lobes.
  • Use consistent normal orientation, geometric normal safeguards, and roughness floors.
  • Filter normal variance for minification; do not let added lobes reintroduce sparkle/aliasing.
  • Match Fresnel/IOR conventions across realtime and reference/path-traced implementations.
  • Explicitly define multiple-scattering approximation and reciprocity assumptions.

Implementation sequence

  1. Write a CPU/reference evaluation and sphere-matrix corpus for the base model.
  2. Introduce versioned lobe ABI without visual change.
  3. Land clearcoat + IOR/specular and validate energy.
  4. Land sheen and anisotropy with correct tangent handling.
  5. Land iridescence with bounded parameter ranges.
  6. Wire import, serialization, authoring API, debug views, and path-tracer parity.

Each lobe should be a reviewable commit/PR slice with its own tests even if one agent owns the whole issue.

Acceptance criteria

  • A generated parameter matrix compares each lobe against tools/bloom-reference or Cycles at multiple view/light angles; thresholds and known model differences are recorded.
  • White-furnace tests show no unexplained energy gain across roughness, metallic, IOR, and lobe-weight sweeps.
  • Deferred/visibility, forward, and path-traced versions agree within the approved model tolerance.
  • Canonical glTF extension assets import with correct factors/textures and no silent fallback.
  • Anisotropy orientation follows mesh tangents and survives negative scale/mirrored UV cases.
  • Normal-map minification does not create temporal sparkle in the motion corpus.
  • Base-only material cost does not regress by more than an approved measured budget; attach shader stats and pass timings.
  • Public APIs remain simple: useful defaults and one material descriptor, not a required sequence of low-level FFI calls.

Likely files

  • native/shared/src/renderer/material_pipeline.rs, material_system.rs, shaders/
  • native/shared/shaders/material_abi.wgsl
  • native/shared/src/models_gltf.rs
  • tools/bloom-reference/src/tracer.rs
  • path-tracer shaders under native/shared/src/renderer/shaders/pt.rs
  • src/models/ public material types

Non-goals

  • A node-based material editor.
  • Strand hair, eye geometry, or a full BSSRDF in the first release.
  • Maintaining two mathematically unrelated BRDF implementations.

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions