DirectX Not Normal (Mapping)
The last week I’ve been working on making the graphics in CIC a little better than they are. I’ve created a new star field in Photoshop thanks to this tutorial. I wanted to keep the skybox textures to a maximum of 1024×1024 pixels which caused the star field to become quite pixelated. I had a think about possible solutions and the technique I have come up with works quite well without giving a noticeable artefact problem. I’ve tweaked the field of view of the camera when rendering the sky box so it’s now more like a fishbowl which means more of the skybox is on screen at once which in turns reduces the size of each pixel when rendering.
Currently I’m working on adding normal mapping support to my ship models. Surprisingly, the HLSL to get this working was quite simple; the difficulties have been in getting DirectX to play nicely. I had the following problems in order:
1) My first simple shader which lights triangles based on whether their normal was pointing towards the light had issue as the .x file exporter that comes with the DirectX SDK exported my normals incorrectly.
2) I used Panda’s .x file exporter (which actually works) and can be found here. This worked well except for the fact it doesn’t export binormals and tangents (needed for normal map calculation). This was not an issue as DirectX has a function for generating these. Unfortunately the function doesn’t work. D3DXComputeTangentFrame simple fails, giving no reason why. I eventually found that other people were having troubles and they recommended using the older D3DXComputeTangent function, and it worked.
3) Now I had everything I needed I simply needed to add a normal map to my max model and re-export. Unfortunately DirectX materials can have only 1 texture each and so only the diffuse (colour) map was exported with the model and the normal map is ignored. So to keep DirectX happy I thought’ I’d apply two materials to my max model, one with the diffuse map, the other with the normal map. Unfortunately Max doesn’t allow more than one material per object.
So after all that, the solution is the manually specify which textures will be used with each model. I’m going to try that this afternoon and I should hopefully have my normal mapping working in game within my 2 hours of work tonight.