RGBAFormat with jpg

Background: I’ve been looking into upgrading from r111 and I’ve figured out how to get around a lot of concerns (will look a little different but seems ok). However, something that has been a showstopper is the removal of RGBFormat. I’m using sRGBEncoding.

Issue: It seems that some jpeg’s aren’t happy using RGBAFormat. I can see some obj’s load with white meshes instead of colored meshes. I also see that looking through a transparent window that some meshes become invisible, which happened once the jpg code was updated. This is what I had in texture loading:

// JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
texture.format = isJPEG ? RGBFormat : RGBAFormat;
texture.needsUpdate = true;

I had to update the texture.format so that it only assigned RGBAFormat (although I noticed the same effect without assigning it). This is when the textures started acted up. I can go to older versions where RGBFormat is supported and it acts the same. I’m thinking this is because transparency data isn’t being handled correctly. How should we load jpeg’s in these cases, now that RGBFormat is not a thing?

Edit: I found out that while this broke in r137, it appears to have been reintroduced in r139, with a boatload of warnings to not use it in the console. So while I’m not stopped, the warnings are annoying so what’s the right way to handle this case?

JPEG textures should use RGBAFormat, even though they have no alpha channel. There are underlying hardware and WebGL reasons for this — many GPUs are going to represent the texture as RGBA even if you use RGB, so RGBFormat is not a practical way to save memory. If you’re seeing unexpected results with RGBAFormat I’d recommend creating a Codepen or JSFiddle to illustrate the issue, and others can debug.


Thanks, @donmccurdy! In working through the example, I figured out the problem was my code had if checks based on RGBAFormat and applying a special shader. I’ve updated code to add userData to mark a JPEG texture so that it does not apply said shader and things look good now!