Dynamically demonstrate the addressing mode in 3D array

I get headaches every time I compute an array index, especially with 2-and 3-dimensional arrays, which are particularly error-prone. Today, try using the compute shader and instance of Codea 4 to dynamically demonstrate the various ways in which a 3D array can be expanded (there are six of them) :

    //fill (xoy) plane first
    uint i = uint(gtId.z * gtNum.x * gtNum.y + gtId.y * gtNum.x + gtId.x);
    uint i = uint(gtId.z * gtNum.x * gtNum.y + gtId.x * gtNum.y + gtId.y);
    //fill (xoz) plane first
    uint i = uint(gtId.y * gtNum.x * gtNum.z + gtId.x * gtNum.z + gtId.z);
    uint i = uint(gtId.y * gtNum.x * gtNum.z + gtId.z * gtNum.x + gtId.x);
    //fill (yoz) plane first
    uint i = uint(gtId.x * gtNum.y * gtNum.z + gtId.y * gtNum.z + gtId.z);
    uint i = uint(gtId.x * gtNum.y * gtNum.z + gtId.z * gtNum.y + gtId.y);

GPUComputeModelDemo.zip (9.0 KB)

demo video

1 Like

Nice way of visualising it!