Teapot for Android

For CS148 assignment 8 (programmable shading), I wrote an OpenGL ES 2.0 application for Android. It includes animated water and the Utah teapot with Phong shading and environment mapping.

Teapot Demo

The most difficult part was simply getting the geometry onto the GPU. I found a .obj file of the Utah teapot and wrote a parser in java to convert it into an interleaved vertex-normal buffer. I then copied it onto the GPU using OpenGL ES calls. For the water, I made a tessellated plane in Blender and similarly pushed it to the GPU.

Teapot Geometry

Once the geometry was in place, I could start writing shaders. I started with a simple Phong lighting model for the teapot, then added environment mapping to a light probe. By combining the two approaches, I ended up with a material that looks fairly metal-like.

Environment Mapping

For the water, I wrote a simple sinusoidal function based on time and distance from the center, and applied displacement mapping. I computed the surface normals by approximation, as shown below. I reapplied the environment mapping code, and made it partially transparent.

Surface Normals

Overall, I'm quite happy that the rendering looks reasonably nice, and runs at 30+ FPS on both my Nexus 7 and Droid Incredible 2. I'm definitely looking forward to writing more OpenGL ES apps for Android in the future.




Home