Source browser
examples/shaders/rgba_uint_image.cpp
Read the complete file below or download its original bytes. Line numbers provide stable links to a declaration or processing step.
File fingerprint
1// Apply unsigned integer image arithmetic directly to stored channel values.
2#ifdef __cplusplus // Expose host declarations only when a C++ compiler reads this shader.
3#include "shdr.h" // Include shdr.h declarations.
4#endif // Finish this conditional compilation branch.
5
6layout(local_size_x = 4, local_size_y = 4, local_size_z = 1) in; // Cover a 4 by 4 group of output coordinates.
7layout(rgba32ui, binding = 0) readonly uniform highp uimage2D input_image; // Read the rgba32ui image at this image binding.
8layout(rgba32ui, binding = 1) writeonly uniform highp uimage2D output_image; // Write the rgba32ui image at this image binding.
9
10void main() { // Add deterministic per-channel offsets to one RGBA image pixel.
11 ivec2 position = ivec2(gl_GlobalInvocationID.xy); // Address the pixel assigned to this two-dimensional invocation.
12 ivec2 dimensions = imageSize(input_image); // Read the bound image extent before accessing its pixels.
13 if (position.x >= dimensions.x || position.y >= dimensions.y) // Guard invocations outside the image in the partial final tile.
14 return; // Stop this invocation before performing another resource access.
15 imageStore(output_image, position, imageLoad(input_image, position) + uvec4(1u, 2u, 3u, 4u)); // Store the transformed RGBA pixel in the separate output image.
16} // End this block.