Skip to main content
GameDev.net gamedev.net
🔒 Locked

optimizing textures for low bitdepth

Started by genesys Oct 4, 2006 at 2:14 PM 18 replies 3.7k views
Original Post
genesys
genesys
Hi! Is there a tool to optimize a texture for certain bitdepths? let's say i create a texture with the renderformat RGBA4444 or RGBA5650 from my rgb image file. If the image contains gradients, these gradients will have verry obvious color-borders when rendered with this bitdepth. But if i could use techniques like diffusion, pattern and noise (as you would use when you create GIFs with small bitdepths in Photosohp or when you change the bitdepth to 8-bit palletized) on the images respecting the target bitdepth, I could improve the visual quality of the gradients at lower bitdepths. So... Any ideas? Thanks!
jollyjeffers
jollyjeffers
I'm going to move this over to GP&T - whilst you might be using D3D the algorithms you're describing tend to be fairly generalised. I'm not aware of specific characteristics of D3D that would affect any general computer graphics algorithms.

If you're using pixel shaders you might be able to use some more complex methods and unpack/decode the data on the fly...

Cheers,
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
genesys
genesys
It's not about Algorithm. I'm searching for a tool to preprocess my textures.
mikiex
mikiex
Why do you want to generate 16bit images with dithering etc.?
How about using dxt compression? Give more info what you are trying
to do.
genesys
genesys
exactly what i told.

i can't use dxt compression since the graphicsengine i'm using doesn't support it.
The only way to diminish VRAM usage is to use lower bitdepths for the Textures, so I try to get the best texturequality at a low bitdepth and this could be achieved with dithering.
Mastaba
Mastaba
Then how about using Photoshop to optimize the images? Or Paint Shop Pro? They should both be able to optimize an image with respect to a given palette. In this case, your palette would be the entire range of colors available in the given format. Though Paint Shop Pro is limited to 256 color palettes so a compromise would have to be made. I have no clue of Photoshop's abilities, though generally perceive them to be better.
genesys
genesys
no - unfortunately photoshop is restricted too to 256 colors - at least by default... maybe there are som plugins?
mikiex
mikiex
Quote:
Original post by genesys
exactly what i told.

i can't use dxt compression since the graphicsengine i'm using doesn't support it.
The only way to diminish VRAM usage is to use lower bitdepths for the Textures, so I try to get the best texturequality at a low bitdepth and this could be achieved with dithering.


There are plugins you could find within seconds using google
You would save a lot of time looking yourself.

If you need any more advice then Explain what hardware or graphics engine restrictions you have.
genesys
genesys
Of course I already googled for it - but actually i don't really know what keywords i could use to find what i'm searching for.

I'm using Shockwave3D which bases on DirectX 7
mikiex
mikiex
There is a 565/555 filter for photoshop that uses error diffusion,
I've not tried it. - http://www.telegraphics.com.au/sw/

noisecrime
noisecrime
If you’re talking about doing this via exporting in the w3d format, then use the Photoshop plugins mentioned and use those textures in your modelling program. Although there is no gaurantee that the exporter wont convert the format, it does so strange things at the best of times and of course you’ll need to remember to set the render format in sw3d as the loaded w3d will revert to a default value which may not be what you need for the texture.

If you want to do this by using bitmap members, then the Intel sw3d downsampling routines are pretty awful for anything with a gradient going from 32 to 16 bit, in fact it doesn't even look like they bother to dither it. So its better to provide a 16 bit bitmap if the texture is going to be 16bits. However you don’t really need an external tool to do this, although you might get slightly better results in a few specific cases. Director already has its own down sampling ability via the ‘Transform bitmap’ command ( modify menu ), but even better it can also be done via imaging lingo and the copy pixels command.

Using the copy pixel command has the added benefit that you can supply your project with 32 bit bitmaps and downsample them depending on memory requirements or user preference. That way you don’t lose the ability for having high quality bit depths. One important quirk to note is that to get good quality 16 bit images via copy pixels is to use the undocumented #dither instruction with a value of 1969. This forces copy pixels to use the slower but better quality method, the same one that the ‘Transform bitmap’ uses from the menu.

dstImage.copypixels(srcImage, destrect, srcrect, [#dither1969])

I seriously doubt you’ll ever get rgba4444 to work as a source bitmap, as Director doesn’t support this as a native format and so it can’t store the data. I think it would end up either converted to 565 or just end up corrupted. Your stuck with letting sw3d sample to this format.

I was intrigued by the Photoshop plugins mentioned, so I tried the 555 plugin (565 didn’t work) and it produced excellent 16 bit bitmaps, but only in a few cases, in those that I tested, did it actually produce something that was noticeably better than Director. Of course this will vary depending upon the content of the bitmaps you are converting.

I wrote a test program to compare the various methods of resulting quality of the textures. My conclusion (albeit based on a very small sample of 4 bitmaps) was that for 16 bit textures the most efficient approaching is to import them as 32 bit into Director (allowing for runtime decision over 32 or 16 bit usage), use copypixels to convert them to 16 bit, transfer them to textures in sw3d and set the render format to rgba5550.

The worse thing to do (as you’ve discovered) was to send a 32 bit bitmap and let the Intel engine convert it to 16bit. Using 16 bit bitmaps created via the Photoshop plugin only produced better results in 1 case (a horizontal gradient from white to purple). Whilst converting in Director in nearly all cases produced acceptable results that couldn’t be bettered by the Photoshop plugin.

As I said, these conclusions are only based on a small sample, it may be that your specific bitmaps will require going the photoshop route, or it may be that using Directors copy pixels gives good enough quality. You’ll only find out by testing your actual assets.

PM me your email address if you want a copy of the test movie source, to try on your own bitmaps.

Also you may want to consider joining dir3d-l or dirgames-l mailing lists, friendly and helpful community that focuses focus purely on Director and SW3D.
genesys
genesys
hey noisecrime, hey anonymous poster.
thanks a lot for your help! i will check this and write again when i have some results or more troubles :)
Charles B
Charles B
Dithering and 3D projection + bilinear filtering + lighting usually gives pretty ugly results. If you still choose this option I assume, either your textures are rather noisy, which can hide a lack of component depth and dither patterns, and rendering is rather static (for instance no dynamic lighting).

Else I try an "out of the box" suggestion. Your are apparently mem limited, but are you GPU limited ?

Instead of dithering couldn't you possibly decrease resolution for colors (1/4 of ref resolution) modulated by a detail map (8bits in ref resolution). This way you keep the same compression ratio, and for most natural textures, quality should be infinitely superior.
"Coding math tricks in asm is more fun than Java"
mikiex
mikiex
I agree with Charles, if this is for 3d, it could look more ugly with dither.
than a drop in resolution for lower spec cards.

mikiex
mikiex
Nils, code looks interesting, when will you post a plugin for it :)
genesys
genesys
I don't use dynamic lighting but lightmaps - so this is no problem. The problem is the mipmapping cause for shockwave i can't create the mipmaps myself but only with the built-in algorithm (as far as i know)
mikiex
mikiex
btw the somewhat expensive Optpix imagestudio (yet one of the best for reducing to palletised images)will also dither to 15bit. The latest version for xbox/pc may also support 16bit, I've not tested it before though.

mikiex
mikiex
Nils there are a few photoshop plugin frameworks,
filter factory
filtermeister
Im sure there is an opensource one somewhere

Maybe Paint.net would be good to write a plugin for
it uses C#
It already has support for dxt and 32/24/16bit dds files
not sure it dithers... might be worth looking at.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.