Home Technical Talk

Photoshop complex actions/batch

Greetings,

Hopefully you guys can help me out on this one - pretty complex and unique situation I've got going on. Long story short, I've started helping out a few friends on an Indie game project that they've been working on for a long time, and they made a few rookie mistakes early on that need some fixin' (I think).

Problem:
I've got an entire game's worth of images/textures that are all;
- .PNG's with a transparent background (ie, no alpha channel)
- random sizes (not multiples of 4 - 64, 128, 256, etc..)
- lots of 'dead' space on the edges of the assets (not cropped)

So my brutal task is to sort all of this out, in the name of optimization.

Now before I ask how to fix these issues (not sure if it's even possible actually), I want to make sure it's going to be worth the time and effort.

Info:
So, some key details;
- the game is being developed with XNA
- it's a 2D side scrolling platformer game
- the images/textures don't have Normals, Spec, Ambient, etc.. only Alpha

What I'd like to do is;
- convert them all to .DDS (DXT5 (I think?) since the images have fades on the edges)
- make all images multiples of 4
- crop out as much dead space as possible, while realizing that these assets can't be scaled, and as a result of making them ^2 there may be added dead space

Questions:
I'm not a programmer, so my first question is, will those changes I'd like to make actually reduce file sizes, and increase performance in game? I have no idea how robust XNA is, so if my changes won't affect performance, I won't bother with the changes. Maybe only some changes are necessary?

My next question, assuming this is worthwhile, how can I automate this process? There are easily 500+ Assets and there is no way I'm doing this manually, no matter how big the performance boost. :poly124:

I can imagine how the process would go, but I'm lacking the knowledge[FONT=&quot] [/FONT]on how to do them. How would I get an Alpha channel out of an image thats just on a transparent background? How would I resize the canvas of the image to the closest multiple of 4?

Thanks in advance, sorry for the long post.
NoisyMonk

Replies

  • leechdemon
    Options
    Offline / Send Message
    leechdemon polycounter lvl 11
    Question 1 - I'm not a programmer either, but from what I've gathered ^2 textures are going to be used one way or another; making them ^2 before runtime will let you optimize the texture at the size it'll be used, and hopefully pack things more intelligently (IE, no wasted space). So while it won't make things faster, it'll allow you to optimize them. Or so I'm told... it's work doing, regardless.

    Question 2 - There's probably a ton of ways to do this. What I'd recommend is probably breaking the process into a couple of steps. First, you can do a Batch of all opened files. This will let you tailor your Actions to more specific tasks. So, I'd make an action that converts to 128x128, an action for 256x256, 512x512, etc. You make them all individual, and then open up all images of a relative size. Like, when you're doing a pass for 256x256, open up anything that should become that size, and run the action on the entire library. You should be able to sort by dimensions, but File Size is also a good indicator.

    You can make the action do a few different things. For example, adjust the Image Size to the correct proportions, Save As a DDS file, and then close the open document. That way you make a selection, have it save it out, then open the next set.

    I'm not sure if DDS saves opacity as Alpha... you'd have to test it out. If not, you could probably write an action to transfer the opacity to the Alpha Channel though. Something like...
    Make New Layer
    Fill Background Color (White by Default)
    Create Clipping Mask
    Make New Layer
    Fill Foreground Color (Black by Default)
    Send Layer Backward
    Send Layer Backward
    Flatten
    Select All
    Copy
    Undo ___ times (to get to the initial history state)
    Make New Channel
    Paste
    There's probably an easier way to do that, but something like that should work. You may have to mess around with it a bit. Anyways, you can make an Action to do that, and then call THAT Action in your 128^2, 256^2, 512^2, etc Resize Actions. That way you wire it up once, then all you have to do by hand is manually select which 50 images are going to be one size, which 100 images are going to be the next size, etc. It's a few batches instead of 1 "smart" batch, but it's fairly easy to manage.

    Hope that helps.
  • NoisyMonk
    Options
    Offline / Send Message
    Cool beans.

    I'll try out that action list you've got there and see if I can get it working, thanks for that.

    The problem with the whole ^2 thing is that I believe its okay to have a texture of size, 1024x256, or 512x128, etc... so basically not a square. I could be wrong on that though - but if I'm not, then I get into the problem of just having so many different possibilities that it would take forever to just set them all up. In that case, I really would need someway of automating the process.

    After some searching, I found this on CGTalk;
    function resize()
    {
    var docRef = app.activeDocument;
    var w = docRef.width;
    var h = docRef.height;

    while ((h%4) != 0)
    { h++ }
    while ((w%4) != 0)
    { w++ }
    docRef.resizeImage(w,h)
    }
    resize();

    I haven't tried it out, but I think something like that might work with some tweaking. Any thoughts on that?
  • leechdemon
    Options
    Offline / Send Message
    leechdemon polycounter lvl 11
    Don't know about that script you linked... never tried it, really. The only actions I've ever made are from recording things and using the playback to do what I need. What you're listing sounds like more of a Script than an Action, but I honestly couldn't tell you if that's true or not. Give it a shot, and keep me posted!

    Never heard of that as being referred to as multiples of 4, but I know what you're talking about. I get confused about which is a bigger deal; ^2 or Squared (W=H). I'd say that unless you have an image with extreme proportions (128x1024), it may not make a huge difference. Also, if you're scaling up then you're not losing resolution. For example, an image that's 100 x 200 could be scale up to 128x256, as well as 256x256. The latter is much less efficient, but you wouldn't lose anything in quality since you're going up. You might want to try doing everything to ^2 first, and then see how many images you have that are by themselves. Like, if you only have one image that's an odd size, scale it up to the next largest. It's a loss of efficiency, unless you only have one or two images out of 500 that are that odd size. At some point, consistency wins out. Not sure of the point, though.

    Also, depending on what type of assets you're using, you could try mixing a few together. Like, pasting together a pair of 128x256 textures to fit a 256x256 texture. Again, this would involve affecting the UV's, and is probably only best if you end up with only a couple of images at that size. Depending on how in-depth your textures are, you can use Max's Render-to-Texture to get the UV's and Mapping to line up together relatively easily. You'd have to do it by hand though, so it depends on how your assets shape up.
  • NoisyMonk
    Options
    Offline / Send Message
    So I tested out that Action list you posted, and it works great - thanks again!

    You're correct, that is a script that I posted. I've never used scripts before in PS, if fact I never even knew you could make scripts for PS until just recently. I guess I'm going to have to do some reseach on it and try and figure it out.

    If anyone has any experience with PS Scripts, could you point me in the right direction? I'll do some googleing and hopefully I can find some simple examples and tutorials. I'll let you know how my search goes.
  • CodeFather
    Options
    Offline / Send Message
    CodeFather polycounter lvl 15
    NoisyMonk wrote: »
    Greetings,
    What I'd like to do is;

    - crop out as much dead space as possible, while realizing that these assets can't be scaled, and as a result of making them ^2 there may be added dead space

    If I understood you correctly, cropping is not something you would want because it will mess up with the already unwraped UVs of the assests.

    As for really advance batch processors, I like to use "ah-nextimage" written by Andrew from ps-scripts.com. I recommend you to visit ps-scripts.com, and the adobe forums (photoshop script section), and post you request there. There are always guys willing to help.

    For basic batching you could check vBee actions how they are created.They come with great set of little .jsx scripts, you can change a bit to suit your needs .Check them here:

    http://www.polycount.com/forum/showthread.php?t=75814
Sign In or Register to comment.