in Graphics

Environment Mapping Demo With OpenGL ES 1.1

CarI just finished creating a graphics demo for a chapter I’m writing for the book iPhone Advanced Projects edited by Dave Mark. In the chapter I go over a few different lighting techniques and go in detail on how to do masked environment mapping on an iPhone 3G with OpenGL ES 1.1.

The demo ended up looking pretty good, so I decided to upload a quick video showing the different lighting modes:

  • Diffuse texture only
  • Diffuse texture plus ambient and diffuse lighting
  • Diffuse texture plus ambient, diffuse, and specular lighting (as usually, per-vertex lighting looks pretty bad, even though this is a relatively high-poly model)
  • Fully reflective environment map (using the normal environment map technique)
  • Environment map added to the diffuse texture and lighting
  • Environment map with a reflection mask plus diffuse texture and lighting (two passes on an iPhone 3G–or one pass if you’re not using the diffuse alpha channel)

The chapter in the book will go in detail into each of those techniques, building up to the last one. Full source code will be included as well.

Some of these techniques will also be covered in my upcoming Two Day iPhone OpenGL Class organized in collaboration with Mobile Orchard.

  • gpyles

    Very cool. Did you design the original model? How do you export the model data from the design app and import it to the iPhone SDK?

    Are these types of questions covered in the book/class? 😉

    -Greg

  • Greg, I didn’t make the model. My Maya skillz aren’t quite up to that. I used a free model from Turbosquid. As far as importing it, I went the quickest, easiest way, which was to do a quick-and-dirty parsing of the OBJ file I exported (included in the sample code in the chapter). You really would want to set up a better asset pipeline than that though, but it’ a start.

    These type of questions aren’t covered in the chapter I wrote. It’s just a chapter and it deals with environment mapping. I think there’s another chapter in the same book that cover some of that. As for the class, I’ll provide some simple mesh and texture loaders, but that won’t be the emphasis of the class. Learning OpenGL (and graphics programming) from scratch in two days is a tall order, so I need to concentrate on that.

  • Pingback: This Week in iPhone News - August 7/2009()

  • Pingback: This Week in iPhone News – August 7/2009 | Oh Wow ... a Blog()

  • Anika

    Hello Noel,

    did you implement the mapping in software? As far as I know there are limitations in ES 1.1. A.e. cube- and sphere-mapping is not supported.

    If so, did you solve performance issues and how?

    regards, Anika

  • Hi Anika,

    You’re right. The iPhone hardware doesn’t support environment mapping, but you can “fake” it. The chapter I wrote for the book goes in detail exactly how I did it for Flower Garden (and it includes full source code). But you can get the overall technique from this article. The technique is usually called normal environment mapping, and it relies on transforming the normals by the view matrix to get fake-y uv coordinates. Works pretty well! 🙂

  • Anika

    Thanks a lot for the fast answer, will try the idea.

  • Anika

    Wow this technique is a performance problem because the uv for every vertex of all the meshes, used with environment mapping, is calculated in software. For realtime animation this is not really suitable. But anyways an interesting idea.

  • Anika,

    If you use the normal environment mapping technique, the uvs should be updated in the hardware. You set up the uvs once to be the same as the normals, and then, every frame, change the texture matrix to the view matrix. That way you’re not touching each vertex each frame, and the hardware takes care of doing the transforms for you (unless the OpenGL drive on the iPhone is silently updating them uvs in software, but I hope that’s not happening).

  • Pingback: Tweets that mention Games from Within | Environment Mapping Demo With OpenGL ES 1.1 -- Topsy.com()

  • Pingback: This Week in iPhone News - November 20/2009()

  • I like to use models from http://www.cgtrader.com.

  • Layla

    Here you can find a good 3d models – http://www.cgtrader.com/Buy-3D-models.html.

  • Related Content by Tag