DXT1 encoding

Started by
6 comments, last by Tordin 12 years, 2 months ago
Hello!

im working on a dxt1 encodre, and i have some questions reguarding this.

1 : is this the correct way dxt1 do the encoding.
-1 break down texture into 4x4 tiles.
-2 for each tile, find the brihtest and darkest color.
-3 encode these to into 5.6.5 bit values.
-4 interpolate the texels with the brightest/darkest colors
-5 save the texels in 2bit

2 : Is there any one sitting on some good psudo code or papers on
how dxt1 works in detail?

3 : is it supposed to have the 2 colors in big endian format or litle endian format?

Thanks in advance!
"There will be major features. none to be thought of yet"
Advertisement

-2 for each tile, find the brihtest and darkest color.

it's not always a good choice using brightness for that purpose, but it's ok for the beginning.

-5 save the texels in 2bit[/quote]be careful, bepending on the color0<color1 or color0>color1 one bit combination means it's the transparent color and RGB will be 0.


2 : Is there any one sitting on some good psudo code or papers on
how dxt1 works in detail?[/quote]
http://origin-develo...ompression.html

[quote name='Tordin' timestamp='1327344188' post='4905510']
-2 for each tile, find the brihtest and darkest color.

it's not always a good choice using brightness for that purpose, but it's ok for the beginning.

-5 save the texels in 2bit[/quote]be careful, bepending on the color0<color1 or color0>color1 one bit combination means it's the transparent color and RGB will be 0.


2 : Is there any one sitting on some good psudo code or papers on
how dxt1 works in detail?[/quote]
http://origin-develo...ompression.html
[/quote]

-5 :
Well, how then is the smartest way to calculate the correct value?
im only going to use this compression when i have a diffuse with no alpha.
"There will be major features. none to be thought of yet"

2 : Is there any one sitting on some good psudo code or papers on
how dxt1 works in detail?


Check this out.

The author posts here occasionally, might chime in.

[quote name='Krypt0n' timestamp='1327349110' post='4905542']
[quote name='Tordin' timestamp='1327344188' post='4905510']
-2 for each tile, find the brihtest and darkest color.

it's not always a good choice using brightness for that purpose, but it's ok for the beginning.

-5 save the texels in 2bit[/quote]be careful, bepending on the color0<color1 or color0>color1 one bit combination means it's the transparent color and RGB will be 0.


2 : Is there any one sitting on some good psudo code or papers on
how dxt1 works in detail?[/quote]
http://origin-develo...ompression.html
[/quote]

-5 :
Well, how then is the smartest way to calculate the correct value?
im only going to use this compression when i have a diffuse with no alpha.
[/quote]
imagin your block consist of 255 127 0 luminance values, using just the 4 color version would give you 255, 170, 85, 0 to choose from, so even if you don't have transparency, it's sometimes wise to use the 3color+alpha mode, then you'd have 255, 127, 0, A to choose from ;)
2 : Is there any one sitting on some good psudo code or papers on
how dxt1 works in detail?

Here's some simple and readable code: http://nothings.org/stb/stb_dxt.h

[quote name='Tordin' timestamp='1327344188' post='4905510']
2 : Is there any one sitting on some good psudo code or papers on
how dxt1 works in detail?


Check this out.

The author posts here occasionally, might chime in.
[/quote]
Chime.

There are many concepts you could follow to determine the 2 end colors for the block.
Picking the minimum and maximum of each of the RGB channels is one common way.

The method I described in that article uses 2 layers of linear regression. If big words scare you, don’t be frightened; what linear regression means and does is actually very simple.
http://en.wikipedia.org/wiki/Linear_regression

Look at the graph.
400px-Linear_regression.svg.png

It just takes scattered points and finds the line that best fits all of those points.

It is easy to see how this could be useful in finding the best end colors for DXT.
Work with R, G, and B separately.
For each of them in the 4×4 block, you could sort them from low to high and then plot them on a graph and get something similar to above (except that the values would only be increasing, not jumping up and down as above).
Linear regression would then give you the best match for that set of points.


The second layer of linear regression accounts for the fact that only 4 points along that line can be sampled, and acts to adjust the line towards values that are strongly neglected by the first line or are more important (because they occur more frequently).


The full explanation is in the link above, with lots of code.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Big thanks to all! got it working now after a while! but got some stuff that i need to fix to make it look better.

YogurtEmperor, That is a cleaver way you describe there. maybe il check it out!
"There will be major features. none to be thought of yet"

This topic is closed to new replies.

Advertisement