unity3d - Changing the compression format of multiple textures -


i'm using following method compress bunch of textures:

public void onpostprocesstexture (texture2d t) {         editorutility.compresstexture(t, textureformat.dxt5, 2);  }  

the idea try compress texture when importing it. have project many textures not using optimal format.

the problem these changes not saved anywhere, if check editor you'll see format remains same. can leave script there , reimport in build server, i'd way save these changes.

the way can think of create texture using format want , copying/replace texture. there better way this?


edit

doing more tests, noticed strange: editorutility.compresstexture somehow compressing npot textures. before running script:

before

and after running editorutility.compresstexture:

after

how work? while sergey's answer helps me change format, won't compress npot textures , need save these bytes.

you have 2 problems here.

problem 1

you trying inside onpostprocesstexture method, late. need inside onpreprocesstexture method instead.

problem 2

editorutility.compresstexture compresses texture object (an object resides in ram), not corresponding asset (an object resides on disk).

the correct way of doing want using textureimporter.textureformat.

solution

here working example:

public void onpreprocesstexture() {     textureimporter textureimporter = assetimporter textureimporter;     textureimporter.textureformat = textureimporterformat.dxt5; } 

answer comment

another detail: don't agree compresstexture creates object in ram instead of disk, think creates file inside library folder (that @ point loaded ram).

no, doesn't create inside library folder. it's quite easy check:

  1. start minimal unity3d project: 1 texture , 1 editor script (a descendant of assetpostprocessor onpostprocesstexture method.
  2. open library folder , write down number of files , size.
  3. reimport texture unity editor (it result in execution of onpostprocesstexture method).
  4. open library folder , see no files added , total size of files remains same (at least how works on machine).

answer edited question

doing more tests, noticed strange: editorutility.compresstexture somehow compressing npot textures.

  1. if try reproduce it, unity outputs error line console: "!haserror".
  2. despite unity editor says texture compressed dxt5 after such manipulations, actual texture format d3dfmt_a8r8g8b8 when check in plugin.

one thing note here. actually, dxt compression doesn't require textures of power of 2 size. requires them of size of multiple of 4. hope helps :)


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -