Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: Can you pass an array to a geometry shader?

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2017
    Posts
    6

    Can you pass an array to a geometry shader?

    Can you pass an array of vec2's to a geometry shader as inputs? If so what is the syntax?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,726
    Tell us what you're trying to do rather than how you're trying to do it. There may be a better way.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2017
    Posts
    6
    I am trying to render perlin noise to a texture. Currently I have a vertex shader with two inputs: one is the upper left corner vertex and an array of 4 vec2's that are the gradients at each corner of the cell. I need to pass the 4 vec2's through the geometry shader to the fragment shader to calculate the brightness of that fragment.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,517
    Quote Originally Posted by cmcrook View Post
    Can you pass an array of vec2's to a geometry shader as inputs?
    Not directly, but you can have an array of vec2 inside an interface block which is (must be) declared as an array when used as a geometry shader input. E.g.
    Code :
    // Vertex shader
    out corners
    {
      vec2 gradients[4];
    } vs_out;
     
    //Geometry Shader
    in corners
    {
      vec2 gradients[4];
    } gs_in[];

  5. #5
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,932
    Not directly
    I have seen nothing in the GLSL specification to corroborate this. Or at least, not recent ones. This may have been true in 3.2 when GS's came out, but at least since 4.3 (with arrays of arrays) it is very much not true.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,517
    Quote Originally Posted by Alfonse Reinheart View Post
    I have seen nothing in the GLSL specification to corroborate this. Or at least, not recent ones. This may have been true in 3.2 when GS's came out, but at least since 4.3 (with arrays of arrays) it is very much not true.
    Good point. Although unless you need at least 4.3 for other reasons, I wouldn't require it simply to avoid using an interface block.

    My understanding is that prior to 4.3 (or ARB_arrays_of_arrays), the prohibition on multi-dimensional arrays includes the case where the extra dimension is required for geometry or tessellation shaders.

  7. #7
    Junior Member Newbie
    Join Date
    Nov 2017
    Posts
    6
    I am currently using 4.4 and it seems that it is possible with the following syntax. Although I am puzzled that I wasn't able to find this in the documentation anywhere, is it not up to date?

    Code :
    //Vertex Shader
    out vec2 gradients[4];
     
    //Geometry shader
    in vec2 gradients[][4];

  8. #8
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,932
    Quote Originally Posted by cmcrook View Post
    I am currently using 4.4 and it seems that it is possible with the following syntax. Although I am puzzled that I wasn't able to find this in the documentation anywhere, is it not up to date?
    In what documentation? The specification makes it clear that the inputs are arrayed. What more does it need to say? An array of `int` is an `int[]`. An array of `vec2[4]` is a `vec2[][4]`.

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,517
    Quote Originally Posted by cmcrook View Post
    I am currently using 4.4 and it seems that it is possible with the following syntax. Although I am puzzled that I wasn't able to find this in the documentation anywhere, is it not up to date?
    It doesn't appear to give an example of an unsized multi-dimensional array. However, 4.1.9 (Arrays) says:

    An array of arrays can be declared as

    vec4 a[3][2]; // size-3 array of size-2 array of vec4

    which declares a one-dimensional array of size 3 of one-dimensional arrays of size 2 of vec4s.
    and:
    For unsized arrays, only the outermost dimension can be lacking a size.
    It should also be legal to use a sized array, e.g. assuming that the input type is points:
    Code :
    layout(points) in;
    in vec2 gradients[1][4];

    Note that multi-dimensional arrays require GLSL 4.3 or the ARB_arrays_of_arrays extension. An arrayed interface block should work with any version which supports geometry shaders.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •