Should I use GL_LUMINANCE for greyscale textures?

I have a number of greyscale texture maps that I’m using for masking, modulation, and as inputs to shaders. I’m wondring if I will see a performance improvement by loading these as GL_LUMINANCE with glTexImage2D instead of GL_RGB or GL_RGBA.

While it seems intuitive that the smaller memory footprint would provide a boost, I’ve found that in Java2D you get the best performance if all your BufferedImages have the same pixel format.

Mark McKay

You’ll save valuable vRAM, but you won’t exactly get better performance.

And in shaders the call to texture2D(…, …) will return a vec4 anyway, whatever the format of the underlaying texture.

Will I get worse performance? Getting performance on par is fine, but I don’t want to degrade performance by mixing different pixxel formats, as happenes with Java2D.

Mark McKay

[quote=“kitfox,post:3,topic:24897”]
No, there’s no such problem with OpenGL. GL_LUMINANCE should be as fast as GL_RGB, if not faster (less data will need to be fetched).

There’s also a neat trick you could use with single channel textures to get even lower memory usage (with lower quality though). Instead of using plain GL_LUMINANCE, you could replicate the greyscale data to fill an RGB texture and use DXT1 compression. You get half the size this way:

512x512 GL_LUMINANCE = 256K
512x512 GL_RGB + DXT1 = 768K / 6 = 128K

Also, sampling from a shader will result in (almost) the same vec4: (L, L, L, 0) for GL_LUMINANCE and (R, G, B, 1) for GL_RGB.

DXT1 (or 3, or 5) is not exactly lossless. Especially gradients will look butt ugly.

Use GL_ALPHA format to get maximum performance for alpha blending operations and input to shaders on nVidia cards.
As long as you don’t share your textures on multiple contexts, having different types will not slow anything.

Sure, but it will be faster as it will be a scalar operation (if stored in the alpha channel)

If you really want to improve, then add your texture to the alpha channel of an already existing RGB texture with the same size, filtering, compression, anisotropy, etc.

SeskaPeel.

Good idea, or pack 4 LUMINANCE textures in a RGBA, so you dont have to worry abot filtering, compression, etc of ‘original’ textures.

I often pack RGB+A textures too. It also allows to take advantage of DXT5’s very good compression of the alpha channel. Actually, that’s what ATI is doing with the new ATI1N format in R5x0. A single channel texture is compressed as if it was the alpha channel of a DXT5 texture, for a very decent 2:1 compression ratio.