Zaretto / libsquish

Automatically exported from code.google.com/p/libsquish
MIT License
1 stars 1 forks source link

DXT1 compression forces RGB to 0 when alpha bit is 0 #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Convert a R8G8B8A88 texture to DXT1 using squish
2. Look at the compressed texture in your engine with bilinear filtering 
enabled onto the sampler or alpha test turned off

What is the expected output? What do you see instead?
The rgb values of the texture are forced to 0 where alpha < 128
This is a problem since when discarding texels with clip(tex-0.5) then the 
rgb values are bleeding to black.

What version of the product are you using? On what operating system?
I checked the last version the code is always the same.

Please provide any additional information below.
I locally removed theses lines:

// check for transparent pixels when using dxt1
/*if( isDxt1 && rgba[4*i + 3] < 128 )
{
  m_remap[i] = -1;
  m_transparent = true;
  continue;
}*/

and 

check for a match
int oldbit = 1 << j;
bool match = ( ( mask & oldbit ) != 0 )
&& ( rgba[4*i] == rgba[4*j] )
&& ( rgba[4*i + 1] == rgba[4*j + 1] )
&& ( rgba[4*i + 2] == rgba[4*j + 2] )
/*&& ( rgba[4*j + 3] >= 128 || !isDxt1*/ );

in coulourset.cpp

Then it works as expected... So I really wonder if the DXT1 formats 
*needs* that to be done or if this is known bug? 

I tested textures converted with that fix onto a PC with GTX260/dx9 and 
playstation 3 and xbox 360 it worked fine on all platforms.

Original issue reported on code.google.com by benua...@msn.com on 9 Mar 2010 at 9:49

GoogleCodeExporter commented 9 years ago
That is correct DXT1 behaviour. When decoding an dxt1 texture if the pixel is
transparent its rgb is black, it's designed for premultiplied alpha.

Original comment by Frassle on 16 May 2010 at 12:07