Recommended Posts

I'm loading a jpg and having GL compress it instead of passing in a DDS texture.

On the left is the compressed, the right uncompressed. Somehow the left image gets some color in it even though the original is 100% grayscale. If I desaturate the compressed one back to grayscale it comes out to look just fine.

Share this post

Link to post

Share on other sites

Just guessing here without knowing the excat format and compression algorithm. I.e. the DXT4/5 compression compress RGB to 16 bit, where ,as far as I know, the green channel got one more bit, that is 16bit = 5 (red),6(green),5(blue).
Compressing a gray scaled picture will leave the green channel with higher resolution which can result in a different green channel value when decompressing. This could be the reason that you got a green tint(higher green channel) and violet tint (lower green channel) in an otherwise grey image.

PS: when you need a grey channel, just use one channel (alpha or green) and expand it to RGB in the shaders.
Edited July 12, 2012 by Ashaman73

0

Share this post

Link to post

Share on other sites

There's a lot of different algorithms for DXT compressing an image. The best ones will take a long time (seconds) to run, so I would guess that the one provided by your GL driver is optimised for speed over quality.
And as above, the colour palette for each block will be in 16-bit format, which is not so good for grey-scale - the green/purple tint is a tell-tale artefact of the 565 colour format.
Edited July 12, 2012 by Hodgman

Share this post

Link to post

Share on other sites

You're better off compressing offline and then using glCompressedTexImage rather than compressing at load time. That way you get at least some measure of control over the quality of compression used, and you get to avoid the slow-downs inherent in compressing RGB/RGBA data at load time. With DDS files you also get to include all miplevels in the file, so you get faster texture loading too, as well as the potential for exploiting higher quality reduction algorithms.

Worth noting that the old GL_ARB_texture_compression, when used in this way, makes no promises about the compression algorithm used (or even if the texture is going to be compressed at all) so you can rely on nothing. The best you have is a glHint (GL_TEXTURE_COMPRESSION_HINT, ....) but that's just a hint, of course, and the driver is under no obligation to honour it.

For better instant greyscale in a shader you can use vec4 (dot (color.rgb, vec3 (0.3, 0.59, 0.11)), color.a) by the way.