Does OpenGL ES support environment shaders? - iphone

I want to make metallic 3d object that appears to be reflective. I want to accomplish this using an environment shader that uses either a sphere or cube map that I can assign an image or texture as the "reflection" source.
Does OpenGL ES on the iPhone support this in any versions?

OpenGL ES 2.0 provides shader support. However, it isn't available in many mobile devices that are on the market today. It would be important for you to code both ES 1.1 and ES 2.0 versions of the graphics.
Apple Dev Center has tons of information on the transition:
The fixed-function pipeline of OpenGL
ES 1.1 provides good baseline behavior
for a 3D graphics pipeline, from
transforming and lighting vertices to
blending the final pixels with the
framebuffer. If you choose to
implement an OpenGL ES 2.0
application, you will need to
duplicate this functionality. On the
other hand, OpenGL ES 2.0 is more
flexible than OpenGL ES 1.1. Custom
vertex and fragment operations that
would be difficult or impossible to
implement using OpenGL ES 1.1 can be
trivially implemented with an OpenGL
ES 2.0 shader. Implementing a custom
operation in an OpenGL ES 1.1
application often requires multiple
rendering passes and complex changes
to OpenGL ES state that obscure the
intent of the code. As your algorithms
grow in complexity, shaders convey
those operations more clearly and
concisely and with better performance.
http://developer.apple.com/iphone/library/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/DeterminingOpenGLESCapabilities/DeterminingOpenGLESCapabilities.html#//apple_ref/doc/uid/TP40008793-CH102-SW1

In the old days "metallic" look was achieved using technique called "environment mapping" or "reflection mapping".
Since no programmable shaders are available for OpenGL ES 1.1, simple reflection mapping can be done with software. Just transform vertex normals according to reflection source/camera and get texture UV-coordinates from transformed normal vector. iPhone has horsepower to do this easily, at least with decent vertex counts.

OpenGL ES Supports most of the features of OpenGL (and some extra features for mobile devices). If I recall correctly the iPhone 3Gs supports fragment shaders, while the older iPhone 3G just supports a fixed pipeline.

Related

OpenGL ES 2.0 on iPhone - How many texture units can i use?

In apple's docs:(http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/OpenGLESPlatforms/OpenGLESPlatforms.html)
it says that for "OpenGL ES 1.1 on the PowerVR SGX" "There are 8 texture units available."
it doesn't say how many units are available on OpenGL ES 2.0, does that mean there is no limit?
Rather than asking and getting an answer that may or may not be correct in the future, your app should be checking programmatically at runtime using something like this:
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &MaxTextureUnits);
Note that there are also separate numbers for the number of allowed texture units in a vertex shader and a fragment shader. They would use the constants GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS and GL_MAX_TEXTURE_IMAGE_UNITS. The COMBINED number is the number available to both at the same time.
There is a detailed listing of all the hardware across iPhones and iPads on Apple's iOS Device Compatibility Reference
Based on this, you are safe with using upto 8 Texture units on any iOS device.
Actually the answer is in same page you linked in question:
OpenGL ES 2.0 on the PowerVR SGX
Limits
...
You can use up to 8 textures in a fragment shader. You cannot use texture lookups in a vertex shader.
....

iOS - off-screen rendering using OpenGL ES2

I want to implement image edition using OpenGL shaders. I have found some examples how to implement off-screen rendering using OpenGL ES1.
Do you now any example about off-screen rendering using OpenGL ES2 ans shaders on iPhone?
Thank you in advance
You need to use the framebuffer object extension (FBO), which is part of OpenGL ES2.
This is the same way as with OpenGL ES 1.0, except the functions lose their OES suffix (because FBO was an OES extension to ES1, not a part of the core).
You might like http://programming4.us/multimedia/3288.aspx this tutorial. The code is pretty simple and should be pretty easy to use it with GLES2.

OpenGL-ES 2.0 VS OpenGL-ES 1.1, which is faster?

I've written an app using OpenGL-ES 1.1, but am wondering if there are speed gains to be found by switching to 2.0. Has anyone done any tests with large polygon count models? I only want to render triangles that have different colors, nothing fancy. However, I am wanting to render about 1 million triangles for my comparison test.
OpenGL ES 1.1 and 2.0 provide two very different ways of doing 3-D graphics, so I don't know that direct performance comparisons make much sense. You're probably going to see identical performance using both if you create 2.0 shaders that just simulate OpenGL ES 1.1's fixed function pipeline. This is backed by Apple's documentation on the PowerVR SGX, which says:
The graphics driver for the PowerVR SGX also implements OpenGL ES 1.1
by efficiently implementing the fixed-function pipeline using shaders.
For rendering basic, flat-colored triangles, I'd suggest going with OpenGL ES 1.1 simply because you'll need to write a lot less code. If you are able to get by with the built-in functionality in 1.1, it's usually easier to target that version. You also have a slightly larger market by being able to target the (now) minority of iOS device owners with hardware that doesn't support 2.0.
However, OpenGL ES 2.0 lets you do a whole lot more using its vertex and fragment shaders than 1.1 does, so some of the things that you might do with extensive geometry can instead be handled by shaders. This can make for better-looking, faster effects.
For example, I'm finishing an update to my molecular renderer using 2.0 shaders that will significantly increase resolution of the visualized structures. I'm doing this by using custom shaders that generate raytraced impostors for the spheres and cylinders in these structures. These objects look perfectly round and smooth at any magnification. Doing this in OpenGL ES 1.1 with pure geometry would be all but impossible, because the number of triangles required would be ridiculous (also, billboards wouldn't work well for my cylinders, and the intersection of these shapes wouldn't be handled right in that case).
A million triangles might be a bit much for these devices. In my benchmarks, the old iPhone 3G did around 500,000 triangles per second, and the first-generation iPad about 2,000,000. I haven't fully benchmarked the much faster iPad 2, but my early tests show it at about 8,000,000 - 10,000,000 triangles per second. Even on the fastest device out there, you're only going to get ~10 FPS on a million-triangle scene in the best of the devices. Odds are, you don't need that size of geometry, so I'd do what I could to reduce that first.
The performance gains in ES 2.0 aren't from rendering single VBOs, but through
1) performance tweaks in custom shaders to do only the bare minimum required rather than more general fixed functions
2) rendering lots of objects due to the streamlining of the matrix pipeline and the removal of the matrix stack and the "fixed function", which must figure out new shaders on state changes, and the removal of the need for multipass rendering for some effects.
This allows e.g. the CPU to do all dynamic matrix transformations in a separate thread, whilst ignoring static matrices and avoid unneeded transfer between the CPU->GPU. There's no need to continually redo camera matrices between 2D and 3D state changes in shader versions.

Palette swapping with iPhone and OpenGLES

I am working on an iPhone game, which will have many types of creeps, and each type of creep may have different colors, so I'm looking for the best way to do it, which so far seems to be palette swaping.
Is GL_EXT_paletted_texture available in OpenGLES (it is deprecated in OpenGL)? Since my game must support older devices (iPhone 3G) I can't use shaders, so I'm stuck with fixed pipeline.
How should I do palette swapping with OpenGLES on an iPhone?
OpenGL Color Index for iPhone's OpenGL ES 1.1?
It sounds that you can use glCompressedTexImage2D with GL_PALETTE4_RGB8_OES or GL_PALETTE8_RGBA8_OES. It would be possible to load texel data with various palette data.
Or you can use OpenGL ES 1.1 Texture Environments. Combine texture or constant color with proper environment.
iPhone 3D Programming - Chapter 8. Advanced Lighting and Texturing

What framework should I use to develop a game for the iPhone?

I want to develop this game for the iPhone. Which framework would be best to use (e.g., Cocoa, Cocoa2d, OPENGLES)?
I would look at
http://code.google.com/p/cocos2d-iphone/
You get a whole engine to help with your app and getting some pretty tricky stuff working.
Cocos2d does the following.
Scene management (workflow)
Transitions between scenes Sprites
and Sprite Sheets Effects: Lens,
Ripple, Waves, Liquid, Twirl, etc.
Actions (behaviors): Trasformation
Actions: Move, Rotate, Scale, Jump,
etc. Composable actions: Sequence,
Spawn, Repeat, Reverse Ease Actions:
Exp, Sin, Cubic, etc. Misc actions:
CallFunc, OrbitCamera Basic menus and
buttons Integrated Chipmunk 2d
physics engine Particle system Text
rendering support Texture Atlas
support Tile Map support Parallax
scrolling support High Score server
(Cocos Live) Touch/Accelerometer
support Portrait and Landscape mode
Integrated Pause/Resume Supports
PowerVR Texture Compression (PVRTC)
format Language: objective-c Open
Source: Compatible with open and
closed source projects OpenGL ES 1.1 based
Cocoa2D is using OpenGL ES, and given the game you are looking to do is a simple sprite based game, I think this would be a fine tool kit to use.
On the other hand, for performance you might find that Quartz 2D is significantly faster and provides you for free useful things such as key frame animation. The reason you'll find it's faster is that OpenGL needs to handle at all times the possibility of 3D rendering and all the various possible interactions your polygons could have with the image space: projections, zordering along vertices, etc. Quartz 2D however is fixed in 2D space so provides a good 2D space management tool kit. Additionally all the additional overhead OpenGL can encompass is stripped out.
I've done both, and I've found Quartz 2D to be a simple and fast toolkit to learn and definitely easy to program in. In the future when I do simple 2D sprite based apps I myself will be using Quartz 2D.
I would go with OpenGLEs. It would allow you to have 3d and do some cool stuff later on if you wanted.