OpenGL: compute shader - gl_GlobalInvocationID giving static output

So, I have a Compute Shader that needs to take a texture and copy it to another texture with a few changes. I confirmed that the textures are connected and that the data can be recorded using RenderDoc, which is a debugging tool for graphics. The problem is that inside the shader, the variable gl_GlobalInvocationID created by OpenGL does not work properly.

Here is my call to the computational shader: (Texture Height - 480)

glDispatchCompute(1, this->m_texture_height, 1);            //Call upon shader
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

And here I have my computational shader:

#version 440
#extension GL_ARB_compute_shader : enable
#extension GL_ARB_shader_image_load_store : enable

layout (rgba8, binding=0) uniform image2D texture_source0;
layout (rgba8, binding=1) uniform image2D texture_target0;

layout (local_size_x=640 , local_size_y=1 , local_size_z=1) in; //Local work-group size

void main() {
  ivec2 txlPos;     //A variable keeping track of where on the texture current texel is from
  vec4 result;      //A variable to store color

  txlPos = ivec2(gl_GlobalInvocationID.xy);
  //txlPos = ivec2( (gl_WorkGroupID * gl_WorkGroupSize + gl_LocalInvocationID).xy  );

  result = imageLoad(texture_source0, txlPos);          //Get color value

  barrier();

  result = vec4(txlPos, 0.0, 1.0);

  imageStore(texture_target0, txlPos, result);          //Save color in target texture
}

, , 1pxl 1pxl . - - , , txlPos .

- ? gl_GlobalInvokationID , .

+4
1

8- 0 1. gl_GlobalInvocationID 1, 1, .

, , 1. , :

result = vec4(vec2(gl_GlobalInvocationID.xy) / vec2(640, 480), 0, 1);
+4

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


All Articles