I just saw that Apple will support an extension GL_APPLE_shader_framebuffer_fetch in OpenGL ES 2.0 on all iOS 6 devices which allows programmable blending by using a built-in variable gl_LastFragData[0] in a fragment shader.
Is there any chance that this will be accessible any time soon in Unity?
Thinking about it, I’m not sure how much support from Unity is necessary: maybe one doesn’t even have to call any OpenGL function but the variable gl_LastFragData[0] is just available in GLSL fragment shaders on iOS 6.
Well, we learned about this feature at exactly the same time you did, which is to say, “a couple of days ago”
Features take time to expose, but yeah, if you’re writing raw GLSL yourself, then it should (haven’t checked) “just work”, just write GLSL shader that uses the variable.
If you want shaders written in Cg/HLSL to be able to do this, then it’s more complex for us to implement. We’d need to extend our HLSL2GLSL translator and GLSL Optimizer to “understand” this, and produce valid iOS6 GLSL in the end.
Then I think it should work (well I haven’t checked). All the extension requires is adding an extension statement to your shader, and then using gl_LastFragData.
I haven’t read up about this functionality properly yet, so i might be jumping to conclusions.
But it should open up a whole world of possibilities. Looking forward to it being implemented some time in the future. Aras will this be mapped to unitys the grabpass functionality, or will you keep it as a separate feature?
Right now the hoops I’m jumping through to avoid reading from the frame buffer on IOS are quite inconvenient, worth the performance gain though.
This new feature lets you read the color of the curent pixel in your pixel shader. Common use cases are pretty much what is mentioned in the extension specification: implementing custom blending modes (think all of the Photoshop ones) and doing really simple postprocessing effects that only need to read the current pixel (color correction etc.).
Where can I read the extension specification? I didn’t see it at http://www.khronos.org/registry/gles/ and I didn’t find it in Apple’s developer resources (apart from the WWDC presentation).
Correct me if I’m wrong but it seems like a nice speed boost. Shame it does not translate to droid well (unless I’m mistaken and it’s supported there).
UPDATE: I just tried it on an iPod touch 4 with iOS 6 and it works fine except that you have to ask for GL_EXT_shader_framebuffer_fetch instead of GL_APPLE_shader_framebuffer_fetch (I guess Apple used the GL_APPLE_… name in earlier pre-release builds of iOS 6). I also noted that you have to use gl_LastFragData[0] while using gl_LastFragColor results in an error. (GL_NV_shader_framebuffer_fetch allows to use gl_LastFragColor instead of gl_LastFragData[0]).
Shaders: Support for GL_EXT_shader_framebuffer_fetch. If you have a pixel shader with an “inout” color, it gets translated to use shader framebuffer fetch on GLES2/GLES3/Metal. Use UNITY_FRAMEBUFFER_FETCH_AVAILABLE macro in shaders to conditionally enclose that.