[Android Software Development] Chainfire:
Shaders - How to modify them (ADVANCED TECH USERS)

This post assumes you know a little bit about OpenGL and shaders. Not a lot, mind you, the shaders I modified I did with no prior knowledge of shaders.

Getting the original shaders

Chainfire3D will automatically detect shaders that do not properly compile, and dump that shader to "/data/data/eu.chainfire.cf3d/files/shaders/processname_crc32.error_dump" and "...error_log". This will generate quite a bit of output in logcat, so you know it happens. In (for example) DDMS, filter on "Chainfire3D" to see only these messages.

The error_log file contains the error message from the GPU, while the error_dump contains the shader source code. (Note that there may be too many newlines).

If the shaders do compile, but they do not actually work (or link - watch logcat to see this happen), the shaders will NOT be automatically dumped. You have to dump them manually. You can do this by going into Chainfire3D per-app OpenGL configuration and enable the "Dump all shaders" option. Chainfire3D will now dump every shader the target app attempts to compile. The file name is the same, but it's extension is ".dump" instead of ".error_dump".

Modifying the shaders

You can simply ADB pull the files out of the "/data/data/eu.chainfire.cf3d/files/shaders/" directory. Handy tip: if you do not specify a filename, ADB will pull the entire directory.

Now you can simply modify the shader files with a text editor. You may have to convert the files from unix-newline format to windows-newline format. Warning: See the limitations section, you also need to convert the files BACK to unix-newline format!

Testing the shaders

Obviously, you will need to kill the target app first, then you can push the shaders back to the device at the same location. IMPORTANT: replacement shaders need to have the ".shader" extension, instead of ".dump" or ".error_dump". Keep the rest of the filename exactly the same. If you do this correctly, Chainfire3D will replace the apps' shader with the one you just put on the device.

To let Chainfire3D be able to use the shader, note that you must also chmod 666 the file on the device.

Packaging the shaders

So you fixed issues with an app for a certain GPU by modifying a number of shaders. It'd be a shame if you kept it for yourself. Packaging them up is simple: just throw the ".shader" files in a ZIP file, and name the ZIP file as follows:

"shaders_device_targetapp_version.zip"

For example, the SGS2 shader fix for Riptide GP would be something like: "shaders_sgs2_riptide_gp_v1.zip"

Releasing the shaders

Simply post a new post in this thread, attach the shaders (or put them on a file hosting site and link them), and put the details about this shader in that post. Then PM me that you released said shaders (with a link to the post) and I can add them to the list.

Limitations

Please note the following shader limitations:

- Dumps are at most 64 KB. If the shader is larger, it will only be a partial dump

- Shader replacements must be < 64 KB

- Shader replacements must use unix-newlines

- Shader replacements must have < 16384 lines

- Each line in a shader replacement must be < 1024 characters