« Dart Experiment | Main | GAMESTORM »

Enabling a 32bit backbuffer on Android devices using Unity 3.4

When developing games for Android devices using Unity 3.4, Unity seems to default to a 16bit backbuffer format and there is no easy way for developers to use a 32bit format. Most 16bit formats do not include alpha channels and the low bit depth may cause color banding issues. Here is a short guide (based on this post) on how to create a plugin that enables a 32bit RGBA backbuffer on devices that support it. Note that the file paths are not exact, just indicators, and that everything is case sensitive!

  1. Create a temporary working folder
  2. Inside the working folder, create folders in series to match your package name in the Unity Android build settings. The tree should look like this: /workingfolder/com/companyname/productname/
  3. Copy the UnityPlayerActivity.java file located in /Unity/.../PlaybackEngines/AndroidPlayer/src/com/unity3d/player/ to /workingfolder/com/companyname/productname/
  4. Rename the copy in the working folder to MyUnityPlayerActivity.java
  5. Open MyUnityPlayerActivity.java
    1. Change the class name to "MyUnityPlayerActivity"
    2. Remove the line starting with "package" if present and add the following lines at the top of the file:
      1. package com.companyname.productname;
      2. import com.unity3d.player.*;
    3. In the onCreate() method, change the "boolean trueColor8888 = false;" line to "boolean trueColor8888 = true;"
  6. Compile the MyUnityPlayerActivity.java file using the javac command line tool and the following options:
    1. Use the Unity classes as classpath: "-classpath /.../Unity/.../PlaybackEngines/AndroidPlayer/bin/classes.jar"
    2. Use the Android SDK as bootclasspath: "-bootclasspath /.../Android SDK/platforms/android-11/android.jar"
  7. Package the new MyUnityPlayerActivity.class using the jar command line tool: "jar cf classes.jar com/companyname/productname/MyUnityPlayerActivity.class"
  8. Copy and paste the new classes.jar file to /Plugins/Android/ in your Unity project
  9. Also add this AndroidManifest.xml file to /Plugins/Android/ and modify it to fit your build settings
  10. Build & Run your Unity project

If you follow this guide in order to use the Shadow Volumes Toolkit on Android devices, remember that Unity does not force the backbuffer format and it may revert to a 16bit format on lower-end devices, causing shadow artifacts.

Reader Comments (2)

Thank you so much for this! Your a godsend

November 15, 2011 | Unregistered CommenterRuss

Thanks for these steps. I'm glad that I found your blog. Keep it up.

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>