Skip to content

[Materials] Implement correct glTF alpha blending, transmission, volume, and refraction #133

Description

@proggeramlug

Parent: #126

Problem

Bloom's glTF import currently cannot represent standard physically based translucent content faithfully. In particular, alphaMode: BLEND is treated as cutout/mask behavior and transmission is approximated as a mirror-like material. This breaks glass, decals, foliage edges, smoke-like surfaces, and canonical glTF assets before lighting quality is even evaluated.

Outcome

Spec-correct glTF alpha modes plus a production translucent/refractive path:

  • OPAQUE, MASK, and BLEND preserve their distinct semantics;
  • KHR_materials_transmission, KHR_materials_volume, and IOR produce thickness-aware refraction and Beer-Lambert absorption;
  • transparent ordering/composition has a documented high-quality path and constrained fallback;
  • asset import never silently changes a blend material into a cutout or chrome substitute.

Import contract

Update native/shared/src/models_gltf.rs and cooked material metadata to preserve:

  • alpha mode, cutoff, base-color alpha, double-sided flag, and texture transforms;
  • transmission factor/texture, thickness factor/texture, attenuation distance/color, and IOR;
  • whether thickness is authored, approximated, or unavailable;
  • unsupported extension diagnostics with asset/material names.

Round-trip these values through scene/world serialization where applicable.

Render architecture

Buckets

  • Opaque: existing deferred/visibility path.
  • Masked: opaque depth/shadow semantics with coverage preservation through mip levels; alpha-to-coverage where MSAA supports it.
  • Transparent: forward shading after opaque lighting with depth test/no opaque-depth write.
  • Refractive: forward pass with explicit scene-color/depth input supplied by the render graph.

Composition

Implement one production baseline:

  • depth-sort conventional alpha for small/simple sets; and
  • weighted blended OIT (or a better documented bounded alternative) for intersecting/high-count surfaces.

Expose the selected mode/capability. Sorting keys must be deterministic and account for material bucket, depth, and stable object ID.

Refraction/transmission

  • Reconstruct entry/exit distance from authored thickness, backface/depth information, or a clearly labeled approximation.
  • Apply Snell refraction using material IOR and Beer-Lambert absorption using attenuation color/distance.
  • Sample the correct pre-translucency scene-color snapshot; prevent read/write feedback.
  • Use SSR/planar/ray-query/env fallback hierarchy for reflection without treating missing reflection data as full mirror energy.
  • Conserve energy between reflection, transmission, absorption, and diffuse lobes.

GI, shadows, temporal

  • Transparent objects receive direct/IBL lighting.
  • Masked objects participate in shadows, velocity, depth, and GI surface representation.
  • Transparent motion/reactive data is provided to temporal reconstruction where possible; otherwise mark reactive regions to prevent history smearing.
  • Define whether/how refractive objects cast shadows; unsupported colored transmission is explicit.

Acceptance criteria

  • Khronos-style alpha/transmission/volume validation assets render with correct bucket selection and no import warnings for supported fields.
  • BLEND produces fractional coverage, never binary cutoff.
  • Two intersecting transparent surfaces remain stable during camera motion under the selected OIT path.
  • Glass shows view-dependent Fresnel reflection, background refraction, thickness-dependent absorption, and plausible total energy versus tools/bloom-reference/Cycles.
  • Masked foliage preserves silhouette coverage across mip/LOD changes and appears correctly in shadows and motion vectors.
  • Refractive scene-color access is declared in the render graph; no same-resource read/write validation errors or backend-specific black frames.
  • Web/mobile fallback behavior is visually correct within its documented limits and never silently changes material type.
  • Import, serialization, and golden tests cover all alpha modes plus missing/invalid extension data.

Likely files

  • native/shared/src/models_gltf.rs, models.rs
  • native/shared/src/renderer/material_pipeline.rs, material_system.rs, scene_pass.rs, graph.rs
  • native/shared/shaders/material_abi.wgsl and shared shader modules
  • src/models/, world material serialization, quality/capability APIs

Verification

Attach stills and motion captures against approved glTF reference renders, plus GPU timings and overdraw statistics for sorted and OIT modes.

Non-goals

  • Strand hair rendering.
  • Spectral dispersion.
  • Order-independent refraction of arbitrarily deep nested dielectrics.

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