Fix M2 white shell artifact from missing textures, add opacity track support

Batches whose named texture fails to load now render invisible instead of
white (the swampreeds01a.blp case causing a white shell around aquatic plants).

Also implements proper M2 opacity plumbing:
- Parse texture weight tracks (M2Track<fixed16>) and color animation alpha
  tracks (M2Color.alpha) to resolve per-batch opacity at load time
- Skip batches with batchOpacity < 0.01 in the render loop
- Apply M2Texture.flags (bit0=WrapS, bit1=WrapT) to GL sampler wrap mode
- Upload both UV sets (texCoords[0] and texCoords[1]) and select via
  textureUnit uniform, so batches referencing UV set 1 render correctly
This commit is contained in:
Kelsi 2026-02-17 23:52:44 -08:00
parent 4ba10e772b
commit 9a950ce09f
4 changed files with 141 additions and 15 deletions

View file

@ -196,6 +196,16 @@ struct M2Model {
std::vector<M2TextureTransform> textureTransforms;
std::vector<uint16_t> textureTransformLookup;
// Texture weights (per-batch opacity, from M2Track<fixed16>)
// Each entry is the "at-rest" opacity value (0=transparent, 1=opaque).
// batch.transparencyIndex → textureTransformLookup[idx] → textureWeights[trackIdx]
std::vector<float> textureWeights;
// Color animation alpha values (from M2Color.alpha M2Track<fixed16>)
// One entry per color animation slot; batch.colorIndex indexes directly into this.
// Value 0=transparent, 1=opaque. Independent from textureWeights.
std::vector<float> colorAlphas;
// Attachment points (for weapon/effect anchoring)
std::vector<M2Attachment> attachments;
std::vector<uint16_t> attachmentLookup; // attachment ID → index