I’m having some trouble getting my compute shader to output to a 3D texture. I managed a 2D texture just fine and as far as I can tell I have made all the nessessary changes for 3D so I’m at a bit of a loss as to how to proceed. The code is pretty simple, am I missing something? Thanks
public static class ComputeTexture
{
public static RenderTexture Create(ComputeShader shader, int width, int height, int depth)
{
var texture = new RenderTexture(width, height, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
texture.isVolume = true;
texture.dimension = UnityEngine.Rendering.TextureDimension.Tex3D;
texture.volumeDepth = depth;
texture.enableRandomWrite = true;
texture.Create();
Fill(shader, texture);
return texture;
}
public static void Fill(ComputeShader shader, RenderTexture texture)
{
int kernelHandle = shader.FindKernel("CSMain");
shader.SetTexture(kernelHandle, "Result", texture);
shader.Dispatch(kernelHandle, texture.width / 8, texture.height / 8, texture.depth / 8);
}
}
#pragma kernel CSMain
RWTexture3D<float4> Result;
[numthreads(8,8,8)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
Result[id.xyz] = float4(1, 0, 0, 1);
}