How to do it...

Perform the following steps:

  1. In the compute shader, as usual, we start by defining the number of shader invocations per work group:
layout (local_size_x = 25, local_size_y = 25) in; 
  1. Next, we declare uniform variables for our input and output images and for the edge detection threshold. The input image is the rendered image from the FBO, and the output image will be the result of the edge detection filter:
uniform float EdgeThreshold = 0.1; 
layout(binding=0, rgba8) uniform image2D InputImg; 
layout(binding=1, rgba8) uniform image2D OutputImg; 
  1. Then, we declare our work group's shared memory, which is an array of size 27 x 27:
shared float 
     localData[gl_WorkGroupSize.x+2][gl_WorkGroupSize.y+2]; 
  1. We also define a function ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.