Followup:
I added poppy_good and poppy_bad to make the comparison easier. If you comment out "map_d" in poppy_bad, it works, but that's the wrong behavior: viewer.exe should get the A channel from map_d's texture.
And, I figured out a fix! Here it is, in Texture.cpp
shared_ptr<Texture> Texture::loadTextureFromSpec(const Texture::Specification& s) {
shared_ptr<Texture> t;
if (s.alphaFilename.empty()
// Eric's fix: if filename == alphaFilename, just call here - then the alpha is properly taken from the file.
// This should also be faster, since only one image file is read.
|| s.filename == s.alphaFilename) {
t = Texture::fromFile(s.filename, s.encoding, s.dimension, s.generateMipMaps, s.preprocess, s.assumeSRGBSpaceForAuto);
} else {
t = Texture::fromTwoFiles(s.filename, s.alphaFilename, s.encoding, s.dimension, s.generateMipMaps, s.preprocess, s.assumeSRGBSpaceForAuto, false);
}
if ((s.filename == "<white>" || s.filename.empty()) && (! s.encoding.readMultiplyFirst.isOne() || ! s.encoding.readAddSecond.isZero())) {
t->m_name = String("Color4") + (s.encoding.readMultiplyFirst + s.encoding.readAddSecond).toString();
t->m_appearsInTextureBrowserWindow = false;
}
if (! s.name.empty()) {
}
return t;
}
I highly recommend this change. It says "if the RGB texture and Alpha texture are the same texture, open that and assume alpha is meant as alpha."
Note that this is not an entirely robust fix: if someone (goofily) feeds in an RGB texture for map_Kd and then an RGBA texture for map_d, expecting G3D to use the alpha channel from this texture, then it will fail. Where you want to check for 4 channels in RGBA is in fromTwoFiles().
Basically:
t = Texture::fromTwoFiles(s.filename, s.alphaFilename, s.encoding, s.dimension, s.generateMipMaps, s.preprocess, s.assumeSRGBSpaceForAuto, false);
says "false" at the end. If it said "true" it would work. I suspect a better fix would be to, in fromTwoFiles(), do something like:
bool hasAlpha = useAlpha;
...
if (alphaStride == 4) {
hasAlpha = true;
}
and then test hasAlpha instead of useAlpha in the remaining code.
Basically, if there are 4 channels in the alpha map, use the alpha channel. It seems hard to argue that you really want the red channel when RGBA is available.
Anyway, I've put my fixed Texture.cpp here:
http://www.realtimerendering.com/erich/minecraft/public/mineways/downloads/Texture.cpp - I hope you'll consider adding this second change to G3D, making it compatible with Blender, Cinema 4D, and Sketchfab, to name a few. The "match the name" fix I give first is optional, though the code for it should be faster. The "set hasAlpha" fix is more solid, I think, though a tad slower, I would guess.
Eric Haines