This page is dedicated to my GTA:SA-specific mods.

Shader-based lighting and normal map mod, currently in progrss. Progress is documented below, with screenshots to match.

Phase 1: Fixed-Function Funkiness

This is a mod I started working on within the last month or so (Early November 2007 was when the mod in it's current form, was working to any degree). The first step was isolating the area in memory that rendered vehicles. Once i had that done, i experimented with setting different stagestates and renderstates (since my code was being loaded from my own dll, i could set any fixed-function states i wanted, but didn't quite have full access to setting shaders and shader constants - yet). It was soon obvious that this did not provide the level of control or accuracy i wanted. After all, what's the point of releasing a graphics mod for a game that makes it look...exactly the same!? Normal maps could be done at this point, but not properly.

Wireframe rendering and d3dtop_dotproduct3 normal maps (with per-vertex lighting! yeecch!). The first experiments with totally overriding the rendering code.

Phase 2: Per-Pixel Pleasures

The next step provided new challenges; creating and setting vertex declarations (tells the game what kind of data is associated with each vertex - this was necessary to alter so i could add tangents and binormals), writing the actual shaders, getting the game to use them and setting the shader constants to match ingame data. When coding any application from scratch, this is simple stuff to do. When reverse engineering a game, it's a bit trickier. But it is possible!

From left to right, the very first images of phong lighting in SA. The first image is the rear of my caprice, the second image the Previon (and first public image) and the last image is the Merit. At this point i was re-using code from a book i bought. The code served it's purpose as a test shader, but that's it. There is no specular or normal map yet, and the code does not take all the camera info into account. The spec looks ok, but neither it nor the cubemap are reflected back properly.

Now we're cooking. The van on the far left is using exagerrated textures to test the capabilities and make sure the shader is working correctly. It is being rendered with diffuse, specular and normal maps, and a cube map for reflections. In order to make the shader compatible with more stock game assets (cars that came with the game) I changed the specular source from a separate map, into a saturated version of the diffuse texture. While this is not quite as flexible, it produces usable results for the majority of the stock cars. The normal map is still separate, but its color/normal direction is uniform (blue image, rgb 128,128,255) to produce smooth results.

Phase 3: Material Madness

This is the current phase of the mod. I've pretty much decided what kind of shading algorithm I'm going to use, the challenge now is to get the appropriate data from the material to my shader. Although coding-wise, this isn't difficult, there are attributes i need to set that the game does not take into consideration by default. One example of this is specular power. It needs to be set per material, but the default Renderware materials have no provision for it. I need to either add a float to the material, which is a challenge in and of itself (not to mention re-exporting all the vehicles with the new data...), or hardcode it. The plan i have for now is to break the mod into 2 editions; Basic and Developer. Basic will cater to people who just want to upgrade the look of the vehicles without re-exporting everything (and will have more hard-coded attributes). Developer will offer additional options for those who are willing to re-export their assets.

To do Basic:

  • Fix Alpha-related issues
  • Correct Material color on damaged pieces
  • more than one light source (needs additional exe research)
  • ???

To do Developer:

  • Fix Alpha-related issues
  • Correct material color on damaged pieces
  • Use alpha channel of normal map as specular source
  • Additional shading techniques (glass for example, should not be rendered the exact same way as cloth, plastic, steel, rubber, etc. can solve with additional pixel shaders)
  • Implement specular power somehow
  • more than one light source (needs additional exe research)
I have been discussing this on gtaforums.

Last updated: 11/30/07