0

計算シェーダーに 7 つのスライスを持つ image2DArray があります。関数 imageStore を使用して問題なく書き込むことができ、これらのテクスチャも表示できます。

私の問題は初期化に伴います。テクスチャを初期化しようとしましたが、できません。実際、初期化のためにループを作成します。

for(int i=0; i<N; i++){
    imageStore( outputTexture , ivec3(texel, i), vec4(0));
}

N = 7 の場合は何も表示されませんが、N < 7 の場合はすべて正常に機能し、テクスチャが初期化されます。

image2DArray を正しく初期化できない理由を誰かが説明してくれますか?

編集:私がテストして確認したこと:テクスチャのすべてのスライスに書き込んで表示してみてください。正常に動作しますが、テクスチャを初期化しないと、前のフレームのデータが残ります。したがって、スライスのすべてのピクセルを 0 に初期化しますが、N=7 の場合は何も表示されません。

いくつかのコード:

#version 430 compatibility

layout(rgba8) coherent uniform image2DArray outputTexture;
...
void main(){
    ivec2 texel = ivec2(gl_GlobalInvocationID.xy);  
    ivec2 outSize = imageSize( outputTexture ).xy;

    if( texel.x >= outSize.x || texel.y >= outSize.y )
        return;  

    initializeMeshSet( meshSet );

    vec4 pWorld = texelFetch(gBuffer[0],texel,0);
    pWorld /= pWorld.w;
    vec4 nWorld = texelFetch(gBuffer[1],texel,0);
    nWorld /= nWorld.w;

    if( length(nWorld.xyz) < 0.1 ){
         for(int i=0; i<4; i++){
            imageStore( outputTexture , ivec3(texel, i), vec4(0));
         }

        return;
    }
    if(nbFrame == 0){           
         float value = treatment(texel, pWorld, nWorld.xyz, outSize.x);
         imageStore( outputTexture, ivec3(texel, 0), vec4(vec3(value),1.0));
         imageStore( outputTexture, ivec3(texel, 1), vec4(0.0,0.0,0.0, 1.0));   
    }
    else if(nbFrame == 1){
         float value = treatment2(texel, pWorld, nWorld.xyz, outSize.x);

         vec3 previousValue = imageLoad(outputTexture, ivec3(texel, 1)).xyz * (nbFrame - 1);
         value += previousValue;
         value /= nbFrame;
         imageStore( outputTexture, ivec3(texel, 1), vec4(vec3(value), 1.0));
    }
  }
4

0 に答える 0