Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

Texture projection on iPhone (OpenGL ES 1.1)

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
1,502
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Sep 14, 2010

This is a demo of an attempt to do texture projection on OpenGL ES 1.1 HW (iPhone 3GS). In this video, I am just rendering the "lighmap" pass in which I project the spotlight texture, so the other objects in the scene and the "walls" of the room are not rendered with any base texture or color (it's all black). Also, the plane I am using as ground is not dirtectly connected to the two planes I am using as walls (decision taken to show the planar shadows system... with stencil coming in to remove out of plane projections and double blending).

The button you see me clicking is a simple (quickly put together) debugging tool... it enables or disables the code that attempts to remove the backprojection.
At first the demo starts with the backprojection fix turned on and I let the projector rotate a while... then I turn it off and you can see that there is backprojection going on, but you can also see that the forward projection (which we want) is happening correctly even when the projector is pointing in the corner between the two walls). I am not clear why the backprojection fix is removing a "good" projection too.

Backprojection is an issue of the projection math itself (an object behind the camera appears flipped on screen... which is what happens when rendering if you do not perform front plane clipping and you have an object which sits behind the camera... dividing xyz by z, the projection divide, means dividing by a negative quantity and so the objects gets brought back on screen).

Given the fact that the SGX does not implement user clip planes in HW anyway and that it has a lot of texture stages, the clipper texture technique can be used to eliminate backprojection (it should be 1D, but even a 32x32 texture with a 1 pixel wide black strip will do the job... (you only need one black texel).

In theory s,t coordinates have their origin at the bottom left corner of the texture, but to be safe use a row of black pixels instead of only painting a single pixel (this is done in case the PNG is loaded flipped upside down, as is the case with non PVRTC images loaded through Core Graphics, due to the iPhone's inverted y-axis).

http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-part-6...

You can also implement the y-axis flip described there to correct the problem when you load textures.

The trick behind a clipper texture is mainly that we want black to be fetched for s = (-Inf; 0] and white for s= (0; +Inf).
Using GL_CLAMP_TO_EDGE as wrapping mode for both S and T coordinates we allow for such mapping because all negative S coordinates will be "clamped" to 0 (net effect) and all positive non-zero values of s will take the value of the texture at its edge... in our case, with the clipper texture as it was defined (all white beside a single strip of black texels on its left side/border), the mapping will produce the result intended (black fetched for all negative values of s and for s = 0).
Another trick of using the clipper texture is that we need to generate the s coordinate given the vertex of the mesh we are applying the texture on. This is a little different than what has to be done to project a texture onto a mesh. You need a simpler texture matrix though.

Let's step back for a second though. The idea behind the clipper texture approach is that you want to find a way to calculate the distance of a point on a plane.

[...]

If we modify the texture matrix (we want to use the second stage for the clipper texture, btw) we can set an appropriate matrix that will take the vertex position (sent as texture coordinate) and generate the corresponding s coordinate (t and r will be zero, q will be 1).
You need to have the 1st row of the texture matrix set to [N_plane.x N_plane.y N_plane.z D], 2nd and third row set to 0, and the fourth row with its first three elements set to 0 but the last element set to 1. This is the matrix which should compute the equation at every vertex (on the iPhone 3GS the SGX GPU should take care of doing the perspective interpolation for the texture coordinates per pixel).

Category:

Gaming

Tags:

License:

Standard YouTube License

  • likes, 0 dislikes

Link to this comment:

Share to:

Uploader Comments (Panajev)

  • Yes, I have. There should be another video here with a color texture. The fun stuff was using the combiners and textures to 1.) project a texture map, 2.) prevent back-projection 3.) prevent projection on faces that are looking away from the projector.

see all

All Comments (2)

Sign In or Sign Up now to post a comment!
  • Really nice! Have you tried color textures also?

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more