Jump to content
  • Advertisement
Sign in to follow this  
Tordin

DXT1 encoding

This topic is 2509 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

[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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

[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 ;)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

[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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!