PDA

View Full Version : Overlapping Shader Effects in Opengl ES 2.0



sanchiski
02-24-2014, 08:11 AM
Is it possible to overlap shader effects in OpenGL ES 2.0? (not using FBOs)

How to use the result of a shader with another shader without having to do a glReadPixels and push again the processed pixels?

The next pseudo-code is what I'm trying to achieve:


// Push RGBA pixels into the GPU
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Pixels_To_Render);

// Apply first shader effect
glUseProgeam( FIRST_SHADER_HANDLE);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

// Apply the second shader effect by sampling from the result of the first shader effect
glUseProgeam( SECOND_SHADER_HANDLE );
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

// Get the overall result
glReadPixels(......)

tonyo_au
02-24-2014, 08:37 PM
It depends on what you mean by overlapping effects. If your second shader was putting a halo around the mesh it would probably work; if it was rendering something on top of the original mesh it probably would not work because of z-buffer fighting; if you are in 2D it could work by disabling depth tests.


How to use the result of a shader with another shader without having to do a glReadPixels
I believe you can do this in OpenGL ES 2.x but I don't program mobiles so I can't remember whether 2.x is 2.0 or later

sanchiski
02-24-2014, 11:55 PM
Yes is acutally for 2 on a quad.
I need to render a bitmap into a quad, apply a first effect, and then on the new image with the first effect, apply a second effect, producing a new image with 2 effects applied to it.

Is for mobile devices which uses opengl 2.0 ES

tonyo_au
02-25-2014, 02:34 PM
this extension (http://www.khronos.org/registry/gles/extensions/EXT/EXT_shader_framebuffer_fetch.txt)might work for you