簡體   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