static const char* computeSrc = {
"#version 430\n"
"precision highp float;\n"
"precision highp int;\n"
"uniform int radius;\n"
"uniform float width;\n"
"uniform float height;\n"
"const float pi = 3.1415926;\n"
"float sigma = float(radius) * 0.25;\n"
"float s = 2 * sigma * sigma;\n"
"layout (rgba32f, binding =0) highp uniform image2D uImageIn;\n"
"layout (rgba32f, binding =1) highp uniform image2D uImageOut;\n"
"layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;\n"
"void main() {\n"
" ivec2 id = ivec2(gl_GlobalInvocationID.xy); \n"
" ivec2 size = imageSize(uImageOut); >\n"
" if (id.x >= size.x || id.y >= size.y) { >\n"
" return; >\n"
" } >\n"
" vec2 scale = vec2(1.0) / vec2(width,height); \n"
" vec4 pixel = vec4(0.0); \n"
" float weightSum = 0.0; >\n"
" float weight = 0; >\n"
" vec2 offset = vec2(0.0); >\n"
" for (int i = -radius / 2; i < radius / 2; i++) \n"
" { >\n"
" for (int j = -radius / 2; j < radius / 2; j++) \n"
" { >\n"
" offset = vec2(i, j); >\n"
" weight = exp(-(offset.x * offset.x + offset.y * offset.y) / s) / (pi * s); \n"
" pixel += imageLoad(uImageIn, ivec2(x, y) + scale * offset) * weight; \n"
" weightSum += weight; >\n"
" } >\n"
" } >\n"
" pixel /= weightSum; >\n"
" imageStore(uImageOut, id, pixel); >\n"
" >\n"
"}\n"
};
Check the shader for compilation and linking errors, use glGetShaderInfoLog
and glGetProgramInfoLog
to obtain any diagnostic messages (regardless of whether there was an error).
Is the coordinate of imageLoad wrong?
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.