Raised This Month: $51 Target: $400
 12% 

Optimization transparency DXT3 DXT5 by utility 'Color Quantizer'


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FishDude
Member
Join Date: Jul 2014
Old 12-10-2014 , 17:27   Optimization transparency DXT3 DXT5 by utility 'Color Quantizer'
Reply With Quote #1

(Sorry for my bad English, I use a machine translator.)

This article describes some compensation for the lack of colors in borders of transparency/opacity zones of textures.

Problem: As you already know, in DXT texture compression, the image is divided into 4x4 pixel squares, and each square there are only 2 fixed color + 2 intermediate between fixed colors (total 4 colors). Therefore, in thin multi-colored elements of image some colors gets distorted. Example:

This is 'D-sprite' from this project, zoom x2.



Looking good, but mipmap #2 looks not so good:



Wrong blue colors. Why? let's turn off trasparent mask:



The picture looks typical for Photoshop. The main thing is that there is a white background, which really does not exist in the texture (because it is hidden transparency mask).
White on mipmaps mixed with true blue (while reducing sprite) and gave this wrong white-blue color.

Now I'll show you how you can avoid the wrong colors.

Load the original sprite using a utility 'CQ'. ( http://kherson.myftp.biz/cq/ )
On toolbar press 'image resize'. Dont touching any controls, press 'ok'.
(In fact, resizing does not occur, we use only a side effect of the built-in CQ's algorithm reduction image: the program fills the fields under invisible colors with colors from boundaries, that we just needed.)

You can check result by press Ctrl + mouse click (and hold your click) on picture:



What happened? CQ painted over all transparent areas with color, taken from opaque border area, in this case, black.

This strategy is make easy picture for DXT compression algorithm. Let us save our sprite.
(Achtung!) Do not use .png format: built in CQ png-optimizer will erase "filled transparency" for the sake of improving compression.
(Achtung!) You need ONLY .tga and ONLY in true-color-mode: before saving, select 'TrueColor' in number-of-colors CQ's combo-box.

Then look at the finished VTF:


As you can see, the colors and even the shape of the object is much better preserved.

Probably, I chose not the best example for the sprite. I assure you, I described method is used not only for the salvation of mipmaps, but even for the main picture and very often helps save the color on the edges of the transparent areas.

Just a few another examples. These examples show how "spread out" colors of opaque areas to transparent areas.





Attached Thumbnails
Click image for larger version

Name:	01-d-sprite.png
Views:	1103
Size:	691 Bytes
ID:	140643   Click image for larger version

Name:	02-mipmap2.png
Views:	1028
Size:	585 Bytes
ID:	140644   Click image for larger version

Name:	08-example-forum-v2.png
Views:	1060
Size:	56.1 KB
ID:	140655   Click image for larger version

Name:	d-without-a.png
Views:	827
Size:	975 Bytes
ID:	149445   Click image for larger version

Name:	before-after.png
Views:	1061
Size:	15.9 KB
ID:	149446  

Click image for larger version

Name:	fixedmipmap2v2.png
Views:	869
Size:	1.3 KB
ID:	149448   Click image for larger version

Name:	21-example.png
Views:	1617
Size:	14.6 KB
ID:	149449   Click image for larger version

Name:	24-examples.png
Views:	999
Size:	81.8 KB
ID:	149450  

Last edited by FishDude; 11-03-2015 at 22:38.
FishDude is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 12-11-2014 , 01:30   Re: Optimization transparency DXT3 DXT5 by utility 'Color Quantizer'
Reply With Quote #2

I do not understand the purpose of this thread.
__________________
Kia is offline
FishDude
Member
Join Date: Jul 2014
Old 12-11-2014 , 01:46   Re: Optimization transparency DXT3 DXT5 by utility 'Color Quantizer'
Reply With Quote #3

It may be useful to those who make textures for server / games, as well as sprays, and sprites.
Obviously you, mr. veteran member, not one of those people...

P.S. I wrote this topic because my eyes hurt already come across anywhere on the bugs of textures that could be avoided by following a similar procedure.

Last edited by FishDude; 12-11-2014 at 01:48.
FishDude is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 12-11-2014 , 11:27   Re: Optimization transparency DXT3 DXT5 by utility 'Color Quantizer'
Reply With Quote #4

Clever technique, very handy for a game I'm working on atm.
__________________
asherkin is offline
FishDude
Member
Join Date: Jul 2014
Old 10-02-2015 , 20:19   Re: Optimization transparency DXT3 DXT5 by utility 'Color Quantizer'
Reply With Quote #5

As it turned out, Valve recommends a similar technique - developer.valvesoftware.com/wiki/$translucent;
however, they do it by hand, but here we have a program that does it automatically.


Last edited by FishDude; 10-02-2015 at 20:23.
FishDude is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 10-02-2015 , 21:34   Re: Optimization transparency DXT3 DXT5 by utility 'Color Quantizer'
Reply With Quote #6

Hi, nice post, but the image after this bellow, is off/not loading, and some others too, could you fix it?

Quote:
Wrong blue colors. Why? let's turn off transparent mask:

Last edited by addons_zz; 10-02-2015 at 22:31.
addons_zz is offline
FishDude
Member
Join Date: Jul 2014
Old 11-03-2015 , 22:51   Re: Optimization transparency DXT3 DXT5 by utility 'Color Quantizer'
Reply With Quote #7

Fixed. Excuse me it took so long.

Last edited by FishDude; 11-03-2015 at 22:53.
FishDude is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 11-04-2015 , 05:14   Re: Optimization transparency DXT3 DXT5 by utility 'Color Quantizer'
Reply With Quote #8

Really nice sharing, Fish. Certainly, I'll start using this. ;)
zmd94 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:58.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode