繁体   English   中英

使用计算着色器进行Mipmapping

[英]Mipmapping with compute shader

我有纹理的颜色,法线和我的体素场​​景的其他数据,因为有些数据不能只是平均值,我需要自己计算mip级别。 3D纹理大小为(128 + 64)x 128 x 128,额外的64 x 128 x 128用于mip级别。

因此,当我取第一个mip级别(位于(0,0,0),大小为128 x 128 x 128并且只是将体素复制到第二级别,即(128,0,0)时,数据出现但是,只要我将(128,0,0)的第二级复制到(128,0,64)的第三级,数据就不会出现在第3级。

着色器代码:

#version 450 core

layout (local_size_x = 1,
        local_size_y = 1,
        local_size_z = 1) in;

layout (location = 0) uniform unsigned int resolution;
layout (binding = 0, rgba32f) uniform image3D voxel_texture;

void main()
{
    ivec3 index = ivec3(gl_WorkGroupID);
    ivec3 spread_index = index * 2;

    vec4 voxel = imageLoad(voxel_texture, spread_index);
    imageStore(voxel_texture, index + ivec3(resolution, 0, 0), voxel);

    // This isn't working
    voxel = imageLoad(voxel_texture, spread_index + 
                      ivec3(resolution, 0, 0));
    imageStore(voxel_texture, index + ivec3(resolution, 0, 64), voxel);
}

着色器程序随附

glUniform1ui(0, OCTREE_RES);

glBindImageTexture(0, voxel_textures[0], 0, GL_TRUE, 0, GL_READ_WRITE, 
                   GL_RGBA32F);

glDispatchCompute(64, 64, 64);

我不知道我是否错过了一些基本的东西,这是我的第一个计算着色器。 我也尝试使用内存屏障,但它没有改变一件事。

好吧,你不能指望你的第二个imageLoad读取你刚刚在你的第一家商店写的纹素。

并且无法在“本地”工作组之外同步访问。

你需要:

  • 使用内核的多次调用来执行每一层
  • 要重写着色器逻辑,以便始终从“原始”区域获取。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM