Friday, June 19, 2009

OpenGL ES 2 Shaders

Looking for a good starting place for creating shaders for the new OpenGL ES 2.0 available on the iPhone 3Gs?

The orange book has an online home that's well worth looking at. The Orange Book (the current version of which actually has more purple than orange) is the official book on the shading language. If you're thinking of writing shaders, this is the first resource you should get. The official site has example shaders and links plus errata, so you might want to bookmark it.

You should also check out this page, which has lots of shader resources, including a zip full of shaders that you can use.

Lastly, in the Developer folder on your hard drive, in /Applications/Graphics Tools, there's a program called OpenGL Shader Builder that you might want to check out.



20 comments:

warmi said...

“including a zip full of shaders that you can use.”

Hehehe …trying to run shaders designed for 2009 GPUs on hardware circa 2001 ( at least in terms of performance) cannot end well.

Jeff LaMarche said...

Well, it's certainly possible that some of the shaders may be too taxing to use on a mobile device, however having looked over the shaders in the zip, several of them appear to be well within the capabilities of the PowerVR SGX (which I wouldn't call "circa 2001 hardware" by any stretch of the imagination - it's more powerful, for example, than the graphics card in the original XBox from 2001).

In fact, several of the shaders seem to be nearly identical to ones that were demoed at WWDC.

But you do have a good point in that anybody who uses a shader (or any code for that matter) and then doesn't test it thoroughly on the device deserves to be hated by their users.

Jeff LaMarche said...

Also, as an addendum, the chip in the iPhone only has to push pixels to a 320x480 frame buffer, which has half the number of pixels that fifth-generation consoles like the Xbox had to deal with, so effectively the iPhone 3Gs is considerably more powerful than "2001 hardware" - it's more like 2003 or 2004 hardware pushing half as many pixels.

warmi said...

it's more powerful, for example, than the graphics card in the original XBox from 2001

In terms of capabilities, that’s for sure, but in terms of performance , not even close.

According to the specs, SGX peaks at about 1/5 fill rate of Xbox 1 and can push only about 1/5 as many triangles as the original Xbox.
And that’s assuming the SGX is running at 200MHz.

Now, what will help a lot is , as you mentioned, the fact that we are dealing here with a relatively tiny framebuffer, but still …

In any case, it certainly will be more fun to play with than PowerVR MBX.

Jeff LaMarche said...

Amen on that last point. :)

Manpreet Singh said...

Thanks for sharing this. Shaders are quite interesting from a game development perspective. It's a pity that developers will have to deal with a fragmented market.

There is a famous "Red book" for OpenGL fundamentals and now there is an "Orange Book" :)

As for the graphics performance of the iPhone, PowerVR SGX is a set of chips from 520 to 543 I believe. Do we know which one the iPhone 3GS really as? Any links to the specs?

Thanks.

Jeff LaMarche said...

Manpreet:

I do not know which chip is in the iPhone 3Gs. Apple is famously tight-lipped about the insides of the iPhones :(

There will be some pain over the fragmented capabilities, but all in all, I think it will be worth it to get access to the more powerful capabilities. This is going to allow us to make stuff that is a LOT better looking, and I think it's only a matter of time before the entire line is supporting OpenGL ES 2.0, a year, two tops.

Jeff

Nicolas Goles said...

I'm very exited about OpenGL ES 2.0 on the iPhone, from what I have read, the development is more painful (at least for a OpenGL ES noob like me), but 2.0 has it's own rewards :)

warmi said...

As for the graphics performance of the iPhone, PowerVR SGX is a set of chips from 520 to 543 I believe. Do we know which one the iPhone 3GS really as?

Hard to say but ...

I was running a debuggin session on the latest iPhone (just got it today) and for what it is worth I saw this line go by:
Unable to read symbols for ..../extensions/IMGSGX535GLDriver

So it could be 535 or perhaps it is a common driver for all SGX versions...

Patrick Alessi said...

Jeff,

Is it possible to determine the hardware platform that you are running on? Then, if it is less that 3GS, degrade to OpenGL ES 1.0, but support 2.0 on 3GS devices?

Would you recommend this approach, or just code to the lowest common denominator 1.0?

Thanks!

Jeff LaMarche said...

Patrick:

It certainly is possible to detect which version you are running and accommodate that. The easiest way to do that is to simply try to create a GLES2 context, and if it fails, fall back to GLES1. I hope to do a blog post on that sometime now that 3.0 is out from under NDA, though not sure how quickly I'll get to it.

As for what I recommend? Depends on the App. If you're really making use of the cutting edge features of ES2.0 and falling back to ES1.1 will make it look bad, it might be worth it to only support 2.0 in terms of long-term reputation. In terms of short-term sales, there are 40 million devices out there that support only 1.1, so you're losing a lot of potential sales at least for the next year or two if you only use 2.0.

I would definitely look at using 2.0, though, there's some really cool stuff that can be done now that we have shaders.

The Elastic Image said...

Jeff and other prospective shader writers,

One thing to be aware of is the limited support for anti-aliasing on this implementation of OpenGL ES 2.0. Specifically, there is no multi-sampling. So what? So any shader you write that creates high frequency detail will alias badly. Really badly.

See my thread on the Apple dev. list here:
https://devforums.apple.com/message/85973#85973

Ping me for details.

-Doug
@dugla
@theelasticimage

warmi said...

Specifically, there is no multi-sampling.

That's because we are really rendering to a texture and rtt targets don't support multisampling.

The Elastic Image said...

Hi warmi. Are you at Apple? I was a 3D graphics researcher in their research labs in the late '90s. Could you please elaborate on your rtt comment? As I understand it OpenGL 1.1 was using an FBO. Has that changed in 2.0? If so how?

I'm coming to iPhone form a RenderMan mindset so the rather cryptic OpenGL language takes a bit of getting used to ;-)

Cheers,
Doug

warmi said...

No, I do not work for Apple :-)

What I mean is that we are not allowed to access the real framebuffer ( for instance use eglSwapBuffers or eglSwapInterval) because for whatever reason Apple has decided that they want to have complete control over what gets shown on the screen and thus a typical OpenGL app on the iPhone is just another client rendering to a texture, which then Apple system code uses to composite the final image ( presumably this was done to allow them to popup notifications and other OS controlled output even on top of full screen OpenGL app)
The downside of this approach is that since the gpu ( both MBX and SGX) doesn’t support antialiasing when rendering to a texture, we are stuck with this, even though both gpus do support multisampling just fine ( and at minimal cost) when rendering to the framebuffer.

BTW… This is just my guess on what is going on and why Apple is insisting that antialiasing is not supported even though hardware supports it.

Jeff LaMarche said...

Warmi -

Thanks for the information. I was aware that anti-aliasing didn't work, but didn't know the reason. I appreciate you passing the information on.

Jeff

iraxef said...

Are there any updates to how to do MSAA now that iOS4 apparently exposes the ability to do so?

bersaelor said...

I'm also very interested to know about Multisampling in iOS4 :)

You're the Guru Jeff, any experience?

Edwin said...

scrub m65 kamagra attorney lawyer body scrub field jacket lovegra marijuana attorney injury lawyer

h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels