Skip to content

MTL: material fidelity — specular (Ks/Ns), PBR extensions (Pr/Pm), alpha maps (map_d) #1575

Description

@obiot

Summary

The MTL parser consumes five fields — Kd, Ke, d, Tr, map_Kd — out of the ~20 it recognises. This groups the remaining ones that are worth having, in descending value. Each is independent; split one out when it is picked up.

Depends on #1572 (authored normals) for anything that shades.

1. Specular — Ks, Ns

The lit mesh shader is half-Lambert diffuse plus an ambient floor; there is no specular term at all, so every material reads as chalk. MTL already carries specular colour (Ks) and shininess (Ns), and both are in the file for essentially every exported model.

A Blinn-Phong term driven by those two is a shader change plus two per-mesh uniforms — small, and the largest step in material range for the effort. It also composes with #1574: a normal map plus a specular highlight is what makes a low-poly surface read as a material rather than a colour.

2. PBR extensions — Pr (roughness), Pm (metallic), map_Pr, map_Pm

Blender's OBJ exporter writes these, so they are already present in assets people bring to the engine. More importantly the destination already exists: glTF loading carries metallic/roughness into the engine, so this is mapping a second source onto an existing material concept rather than inventing a parallel model.

Worth deciding deliberately whether the lit mesh path grows a genuine PBR shading model or whether Pr/Pm are approximated onto the existing terms. The former is a much larger piece of work and probably wants its own design ticket; the latter is cheap and honest if documented as an approximation.

3. Alpha maps — map_d

The mesh path already has alphaCutoff (glTF alphaMode: MASK), driven per-material. map_d would drive it per-texel, which is what foliage, fences and decals actually need — currently an OBJ can only cut out at a uniform threshold across a whole material.

Cheap, self-contained, and it makes an existing feature usable from OBJ rather than only from glTF.

4. Ka (ambient) and illum

Lowest value, listed for completeness. Ka is largely redundant against the engine's ambient light, and illum is vestigial in modern pipelines — most exporters emit a constant. Probably worth parsing into the material for completeness and not wiring into shading, unless a concrete need appears.

Acceptance (per item)

  • The parsed value reaches the material and is observable from user code.
  • Shading changes are verified on both GPU backends and produce identical output.
  • A model that supplies none of these renders byte-identically to today.

References

src/loader/parsers/mtl.js (the recognised-but-unconsumed tokens), src/renderable/mesh.js (material resolution), src/video/webgl/shaders/mesh-lit.frag, src/video/webgpu/shaders/mesh-lit.wgsl.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions