Sunday, January 8, 2012

Texture mapping in DirectX, oh and I suck.


Did I mention I'm learning? So here's a good way of learning from my mistakes. So I've been pouring over the DirectX tutorials the past week and finally came to the section on texture mapping. Texture mapping is of course the process of taking a texture or image and applying it to a surface or object. Granted this may or may not be how game engines do it, it was a good thing to learn. Here's the DirectX tutorial's example of applying a single texture to each surface of a cube.

The texture to be applied to the cube surface

The texture applied to the cube (each surface is the same texture)

In the DirectX tutorials they show loading textures via a DirectX function called: D3DX10CreateShaderResourceViewFromFile where the input takes a DDS file. DDS files are also what I found the Havok engine using. I assume other engines would probably use them well. Going back to my ASS.exe I looked for but couldn't find any references to DEDX10CreateShaderResourceViewFromFile, and in fact I couldn't find any references to any D3DX10 functions at all.

It appears that this game was built using DX9, which of course changes things. I flipped directly to the DX9 tutorial on texture mapping and found in Tutorial 5 - Using Texture Maps; Step 2 - Initializing Screen Geometry that they reference the function D3DXCreateTextureFromFile. Going back to IDA of the ASS.exe, I noticed the following functions:

DirectX9 function listing

You'll notice the D3DXCreateTextureFromFileInMemory is probably the most likely candidiate for getting their textures mapped to the game objects. My next step will be to modify these DDS textures and try to re-insert the asset back into the game's archive files. To do this, I need to load the game and find an Non-Playing Character (NPC) model that I can find easily in the game, then I need to find the model's assets on disk and modify them. The first NPC I encounter is this:

The NPC model i'm going to modify

So after looking through the 'character' asset archive I find I need to load the models using Havok's modeling tool. I figure once I find the correct character, I can try to find it's textures and modify them. I find one that I think is correct, something the game calls 'birds'. 

The model I believe I need to modify

There exists a directory called 'textures' which includes the models' DDS texture files. I, unfortunately, have no idea how to create or edit DDS files. I figure either photoshop or GIMP can do it. Since I don't have buckets of money laying around, I decided to try GIMP first; so I download it. It requires a DDS plugin which I found here or here. So I download that and extract the dds.exe plugin into the C:\Program Files (x86)\GIMP-2.0\lib\gimp\2.0\plug-ins directory and reloaded gimp. As you can see, I can now load DDS files. Don't mind the Japanese menu, I was too lazy to change them from the default.

The 'bird' texture, I think.

So, just for fun I make a back up of the original zip's contents and change the whole bloody texture to bright red.

Yehp, it's friggen red.

I re-create the zip file with the password I cracked earlier and change the name back to .bin after backing up the original. I start up the game and find the same NPC model... and nothing changed. OK, maybe I got the texture wrong? There were two files for the 'bigger_birds' object so I tried making that one red too. Reload the game, same thing, no change what so ever. Now I have no idea what is wrong. So to test if these files are even being used, I end up deleting the entire textures directory for it, re-zip without the files and try again. I figure it should totally crash because it won't be able to find the files. So I load it up and low and behold.... Nothing friggen happens. 

Now I can only assume it is not even using these DDS files. Maybe they're debug files? Included by accident? I clearly don't know enough about texture mapping. I guess it's back to the books. 



1 comment: