Skip to content

Decode .texture and carry PBR materials through to both exports #4

Description

@Darithos

Exports currently go out untextured. data/hd holds roughly 3,800 .texture files and there is no public byte-level spec for the format.

Working out the format

The method that cracked Diablo III's .tex, which is the same shape of problem:

  1. Hexdump the first 128 bytes of a few hundred files and histogram them — a fixed magic and version fall out immediately.
  2. Find width and height by looking for plausible power-of-two pairs, cross-checked against file size: a BC surface with a full mip chain is roughly w*h*bpp/8 * 4/3.
  3. Identify the format enum by correlating the byte that varies with the implied bytes per pixel.
  4. Validate by decoding to PNG and looking at it. A wrong stride is instantly visible; a wrong format is a plausible-but-wrong palette.

Expect BC7 and BC5 where D3 only needed BC1/BC2/BC3. BC7 decode is fiddly (8 modes) but well documented, and no re-encoding is needed for .dds export — block data passes through losslessly. D3's split component streams are a Blizzard-ism unlikely to recur in another studio's pipeline.

Acceptance: 200 random .texture files decode with zero exceptions, and twenty of them look right.

Materials

D2R materials are PBR triples — alb / nrm / orm — referenced from texture_desc_casche.json under data/hd. Two payoffs:

  • glTF: ORM is already glTF's own channel packing (occlusion R, roughness G, metallic B), so albedo/normal/ORM map onto baseColorTexture / normalTexture / metallicRoughnessTexture with no conversion at all.
  • .m3: SC2's MAT_ V20 has real normal and specular layer slots. Wiring them up would make these exports look markedly better in the SC2 editor than the D3 tool's diffuse-only ones.

Alpha cutout

D2R art is full of alpha-tested cloth, hair, capes and foliage, so the alpha-mask path in M3Writer matters here. D3ModelViewer/docs/SC2-ALPHA-MASK-LAYER-BUG.md explains why SC2 samples the material's Alpha Mask layer slot rather than the diffuse alpha — that finding is expensive to re-derive and applies unchanged.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions