OpenGL立方体贴图只能写入一个面。

huangapple go评论70阅读模式
英文:

OpenGL Cubemap Can only write to one face

问题

我有一个类似这样的立方体贴图纹理:

uint32_t skyboxTextureUnfiltered = -1;
glGenTextures(1, &skyboxTextureUnfiltered);
glBindTexture(GL_TEXTURE_CUBE_MAP, skyboxTextureUnfiltered);
glTexStorage2D(GL_TEXTURE_CUBE_MAP, 6, GL_RGBA32F, m_SkyboxSize, m_SkyboxSize);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

然后我在它上面运行一个计算着色器:

glBindImageTexture(0, skyboxTextureUnfiltered, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
glUseProgram(m_EquirectToCubeID);
glDispatchCompute(m_SkyboxSize, m_SkyboxSize, 6);

我的计算着色器如下:

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, rgba32f) uniform imageCube outputTexture;

void main(void)
{
    imageStore(outputTexture, ivec3(gl_GlobalInvocationID), vec4(1.0f));
}

但在所有这些操作之后,当我尝试在RenderDoc中查看其内容时,我只看到+X面是白色的,其余都是黑色的。

为什么会发生这种情况?

英文:

I have a cubemap texture like this:

uint32_t skyboxTextureUnfiltered = -1;
glGenTextures(1, &skyboxTextureUnfiltered);
glBindTexture(GL_TEXTURE_CUBE_MAP, skyboxTextureUnfiltered);
glTexStorage2D(GL_TEXTURE_CUBE_MAP, 6, GL_RGBA32F, m_SkyboxSize, m_SkyboxSize);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

I run a compute shader on it like:

glBindImageTexture(0, skyboxTextureUnfiltered, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
glUseProgram(m_EquirectToCubeID);
glDispatchCompute(m_SkyboxSize, m_SkyboxSize, 6);

And my compute shader looks like :

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, rgba32f) uniform imageCube outputTexture;

void main(void)
{
    imageStore(outputTexture, ivec3(gl_GlobalInvocationID), vec4(1.0f));
}

And after all this when I try to see its contents in RenderDoc, I only see the +X Face is white rest all are black.

Why is this happenning?

答案1

得分: 3

在这里,你将 GL_FALSE 传递给 layered 参数。这意味着只会绑定单个层级(这里是层级 0)。对于立方体贴图纹理,每个面都是一个单独的层级。

你应该传递 GL_TRUE 而不是:

glBindImageTexture(0, skyboxTextureUnfiltered, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32F);
英文:
glBindImageTexture(0, skyboxTextureUnfiltered, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);

Here you pass GL_FALSE to the layered parameter. It means that only a single layer (here layer 0) will be bound. For cube-map textures, every face is a single layer.

You should pass GL_TRUE instead:

glBindImageTexture(0, skyboxTextureUnfiltered, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32F);

huangapple
  • 本文由 发表于 2023年2月27日 02:41:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75574232.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定