Writing to RWTexture2D & RWTexture2DArray in Compute Shader

Hello !
Been trying to use RWTexture2D & RWTexture2DArray with Compute Shader in SDSL, but didn’t manage to understand how am I supposed to write to them.

Test Setup

Made a test setup to try the writing.

SDSL Code of the Compute Shader :

[Summary("")]
shader WriteToTexture2D_ComputeFX : ComputeShaderBase
{
    int TexelTotal;
    int2 TextureDimension;

    [Color]
    float4 Color;

    RWTexture2D<float4> Texture;
    RWTexture2DArray<float> TextureArray;

    int2 CoordFromIndex(int index, int2 textDimension)
    {
        int x = index % textDimension.x;
        int y = index / textDimension.x;

        return int2(x, y);
    }

    override void Compute()
    {
        int texIndex = streams.DispatchThreadId.x;
        int2 texCoord = CoordFromIndex(texIndex, TextureDimension);
        
        if(texIndex >= TexelTotal) return;

        Texture[texCoord] = Color;
        TextureArray[uint3(texCoord, 0)] = Color.x;
        TextureArray[uint3(texCoord, 1)] = Color.y;
    }
};

Node Setup :

You can also download the patch + shader zipped :
(Dependencies are VL.Addons, VL.Stride, VL.Stride.TextureFX)
RWTexture2D.zip (4.9 KB)

Thanks for your help, in the hope this help the next people trying to achieve the same •ᴗ•

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.