Multipass Shaders in OpenGL ES 2.0

First, are GLSL 4.0+ routines needed? So it is not available in GLSL version of OpenGL ES 2.0?

I understand what multipass shaders are.
Well, what is my picture:

  • Draw a group of something (for example, sprites) in the FBO using some shaders.
  • Think of FBO as a large texture for squares the size of a large screen, and use a different shader that, for example, turns the texture colors into shades of gray.
  • Draw a FBO with a textured square on a grayscale screen.

Or is it called differently?

So, multi-pass = use a different shader pin for a different shader input? So, do we make one object twice or more? How does a shader output get to another shader input?

for instance

glUseProgram(shader_prog_1);//Just plain sprite draw glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, /*some texture_id*/); //Setting input for shader_prog_1 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); //Disabling arrays, buffers glUseProgram(shader_prog_1);//Uses same vertex, but different fragment shader program //Setting input for shader_prog_2 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

Can you provide a simple example of this in a basic way?

+4
source share
1 answer

In general, the term "multi-pass rendering" refers to rendering the same object several times with different shaders and accumulating the results in a framebuffer. Accumulation is usually done by mixing, not with shaders. That is, the second shader does not display the result of the first. Each of them performs part of the calculation, and the mixing step combines them into a final value.

Currently, this is primarily done for coverage in direct rendering scenarios. Each time you visualize each object for each light, passing different lighting parameters and, possibly, using different shaders every time you visualize the light. The blending mode used to accumulate the results is additive, since light reflection is an additive property.

Are GLSL 4.0+ routines required? So it is not available in GLSL version of OpenGL ES 2.0?

This is a completely different question from the rest of your post, but the answer is yes and no.

No, in the sense that ARB_shader_subroutine is an extension of OpenGL, and therefore it can be implemented by any implementation of OpenGL. Yes, in a practical sense, that any hardware that really could implement shader_subroutine could also implement the rest of GL 4.x and therefore would already advertise 4.x functionality.

In practice, you will not find shader_subroutine supported by versions of OpenGL other than 4.x.

In GLSL ES 2.0, it is not available because it is GLSL ES . Do not confuse desktop OpenGL with OpenGL ES. These are two different things, with different versions of GLSL and different functions. They don’t even share extensions (with the exception of a few recent ones).

+10
source

Source: https://habr.com/ru/post/1436878/


All Articles