Panda3D/Manual/Compressão de Texturas: diferenças entre revisões

Conteúdo apagado Conteúdo adicionado
Criou nova página com 'Voce deve estar familiar com formatos de imagem como JPEG, que pode comprimir dados de imagem dramaticamente e fazer arquivos de imagem muito menores do que eles seriam, em ...'
(Sem diferenças)

Revisão das 21h15min de 8 de novembro de 2009

Voce deve estar familiar com formatos de imagem como JPEG, que pode comprimir dados de imagem dramaticamente e fazer arquivos de imagem muito menores do que eles seriam, em troca de sacrificar um pouco da qualidade da imagem original.

Compressão JPEG apenas é aplicavel ao tamanho da imagem em disco, contudo, assim que que vice carregar uma imagem de textura na memoria, seja ela vindo em JPEG, PNG ou TGA, elas sempre ocupam a mesma quantidade de memoria na sua placa de video ( baseada no tamanho de suas texturas).

Porem existe uma opção diferente, para comprimir imagens de textura dentro da memoria. A maioria das placas de video pode usar varios algoritmos de compressao durante o momento de execução para renderizar diretamente a textura que estava comprimida dentro da memoria. Isso é chamado redução DXT. Não é muti como a compressao JPEG internalmente, mas voce pode pensar nela da mesma forma. Elas possuem algumas coisas em comum: elas reduzem o tamanho da imagem drasticamente ( 4 ou ate 8 vezes menor ), e elas sacrificam parte da qualidade da imagem.

Compressao da textura durante a execução

A forma mais facil de habilitar a compressao de imagens de textura é colocar o seguinte no seu arquivo Config.prc:

compressed-textures 1

Isso falará ao seu driver de graficos para comprimir cada textura assim que ela o carregar. Isso significa que demorará um pouco mais para carregar a textura, mas a textura resultante ocupara muito menos espaço na memoria.

There's one important advantage to compressing the textures at runtime this way: the graphics driver will be able to compress all the textures using whatever texture compression algorithm it understands, DXT or otherwise. Not all graphics cards support all compression algorithms, so using this option allows the driver to choose the best algorithm it supports. If the graphics driver doesn't support any compression algorithms at all, it will simply load the textures uncompressed. Either way, your application will still run and all of your textures will be visible. TXO file format

Panda has a native file format for storing texture images, called TXO (the abbreviation is for "texture object"). This is similar to BAM files. A TXO file contains all of the texture image data in a format very similar to Panda's internal representation, so it loads into memory very quickly.

More importantly, perhaps, TXO files can optionally store pre-compressed texture images. You can use the command:

egg2bam -txo -ctex model.egg -o model.bam

to convert your model to a BAM file, and all of its textures to TXO files, with the image data pre-compressed within the TXO file so that it will not need to be compressed at runtime later. (You may need to specify "pandagl" instead of "pandadx9" as your rendering engine while you run the egg2bam command--at the time of this writing, there were issues with using Panda's DirectX driver in an offline mode like this. However, the resulting TXO files will load on either OpenGL or DirectX at runtime.)

TXO files have the same drawbacks as BAM files: they are tied to a particular version of Panda, so you may need to regenerate them when you next upgrade your Panda version.

A bigger drawback to storing pre-compressed texture images this way is that your application might no longer run on all graphics cards. Not all graphics cards support all kinds of DXT compression, and if you try to load a TXO file that a graphics card doesn't understand, it simply won't load. Thus, pre-compressing all of your textures may make your application less portable. DDS file format

In addition to Panda's native TXO file format, there is a fairly standard format called DDS, which has some of the same properties of TXO. Like TXO, you can store pre-compressed images in a DDS file. The biggest advantage of the DDS file format is that there are already several tools available on the internet to generate DDS files, including GIMP and Photoshop plugins. (Note, however, that loading DDS files is a new feature of Panda, and these files are not supported in Panda versions before 1.6.)

Generating your own DDS files has several advantages; chief among them is that you have complete control over the compression artifacts of your texture. However, it has the same portability issues as storing pre-compressed texture images in TXO files: there is a possibility some graphics cards don't support the texture compression you have used, in which case it simply won't load. Texture cache

There is a compromise between dynamic compression and pre-compressed textures: you can ask Panda to compress textures on the fly, and then save the resulting compressed image to a TXO file on disk. The next time you load that particular texture, it will load quickly from its TXO file. Since the TXO file was generated by the user's graphics driver, it will presumably use a supported compression algorithm.

To enable this feature, simply insert the following lines in your Config.prc file:

compressed-textures 1 model-cache-dir /c/temp/panda-cache model-cache-compressed-textures 1

Where model-cache-dir specifies any folder on the disk (it will be created if it doesn't already exist). Note that the model-cache-dir may already be specified; the default distribution of Panda specifies a model-cache to speed up loading bam files.

Like DDS file format, the model-cache-compressed-textures variable is a new feature in Panda, and isn't available in versions prior to 1.6.