hey!
i’m having trouble with image texture of type GL_TEXTURE_CUBE_MAP. i want to generate a random cubemap image using a compute shader. but it doesnt work as i’ve expected.
this is the compute shader:
#version 450 core
layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout (binding = 2) uniform writeonly imageCube img1;
layout (std430, binding = 3) buffer TESTBUFFER { vec4 testvalue[]; };
void main()
{
/* check if i can write to shader storage buffer */
testvalue[0] = vec4(5, 6, 7, 8);
/* OK, that works, i've checked the buffer data offline */
/* check if i can write a texel into a image cubemap */
ivec3 texel = ivec3(0, 0, 0);
vec4 color = vec4(1, 1, 1, 1);
imageStore(img1, texel, color);
/* NOT WORKING */
}
i compiled it and linked it successfully, i’m then running it once:
glBindImageTexture(2, texture_skybox, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
vec4 testvalue(1, 2, 3, 4);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, buffer_test);
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(vec4), value_ptr(testvalue), GL_DYNAMIC_DRAW);
glUseProgram(program_generate);
glDispatchCompute(1, 1, 1);
glUseProgram(0);
vec4 result(0, 0, 0, 0);
glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, sizeof(vec4), value_ptr(result));
cout << "" << result.x << " " << result.y << " " << result.z << " " << result.w << " " << endl;
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
as you can see, i’m checking if the compute shader has been invoked, i’ve added a test SSBO and the compute shader writes a certain value into it, that value (5, 6, 7, 8) is what’s printed out to the console.
i’ve also bound the already made cubemap to image unit 2, but writing to it doesnt work at all
here is the cubemap:
unsigned int resolution = 4;
glBindTexture(GL_TEXTURE_CUBE_MAP, texture_skybox);
glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, GL_RGBA8, resolution, resolution);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
struct Texel { GLubyte R, G, B, A; };
vector<Texel> red(resolution * resolution, { 255, 0, 0, 255 });
vector<Texel> green(resolution * resolution, { 0, 255, 0, 255 });
vector<Texel> blue(resolution * resolution, { 0, 0, 255, 255 });
//vector<Texel> yellow(resolution * resolution, { 255, 255, 0, 255 });
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + 0, 0, 0, 0, resolution, resolution, GL_RGBA, GL_UNSIGNED_BYTE, red.data());
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + 1, 0, 0, 0, resolution, resolution, GL_RGBA, GL_UNSIGNED_BYTE, red.data());
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + 2, 0, 0, 0, resolution, resolution, GL_RGBA, GL_UNSIGNED_BYTE, green.data());
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + 3, 0, 0, 0, resolution, resolution, GL_RGBA, GL_UNSIGNED_BYTE, green.data());
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + 4, 0, 0, 0, resolution, resolution, GL_RGBA, GL_UNSIGNED_BYTE, blue.data());
glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + 5, 0, 0, 0, resolution, resolution, GL_RGBA, GL_UNSIGNED_BYTE, blue.data());
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
glBindTextureUnit(1, texture_skybox);
drawing the cubemap works just fine, the resolution is very low (4 x 4) so that i can see each texel. i’m looking to every corner but i dont see any changed texel :dejection:
i’m also checking for GL errors, i dont get any.
EDIT:
another test to verify that the image sampler has access to the texture: i’m writing:
testvalue[0] = vec4(imageSize(img1), 7, 8);
and it prints me 4, 4, 7, 8, to the console, which means that the computeshader has access to the cubemap texture
what else can i do to check / verify what could be wrong with my code ??
thanks in advance!