Hi all,
I’m trying to compute a 3D texture in a compute shader, then use it in a pixel shader, hopefully avoiding memory transfer between GPU and CPU. Seems like I’m missing something obvious… My compute shader looks like:
#pragma kernel CSMain
RWTexture3D<float4> Result;
[numthreads(1,1,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
Result[id.xyz] = float4(1, 0, 0, 1);
}
So just setting red in the whole texture, which I’m hoping to use this way:
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 5.0
sampler3D _Density;
struct Input {
};
void surf (Input IN, inout SurfaceOutputStandard o) {
fixed3 c = tex3D(_Density, int3(0, 0, 0));
o.Albedo = c.rgb;
}
ENDCG
So just getting one pixel to color the entire mesh. Finally, at the C# level:
Texture t = new Texture3D(16, 16, 16, TextureFormat.RGBAFloat, false);
int kernel = shader.FindKernel("CSMain");
shader.SetTexture(kernel, "Result", t);
shader.Dispatch(kernel, 16, 16, 16);
GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_Density", t);
No compiler or run-time error, but my mesh stays white instead of red… Probably missing something obvious. Any hints?
Thanks!
ST