I’ve spent the last couple days trying to figure out why my compute shader isn’t working on Android. I’ve narrowed it down to the tex2dlod
call always returning 0. Here’s a minimal example:
#pragma kernel NotWorking
RWTexture2D<float4> result;
float tex_width;
float tex_height;
sampler2D input;
[numthreads(8,8,1)]
void NotWorking (uint3 id : SV_DispatchThreadID) {
float2 uv = float2(id.x / tex_width, id.y / tex_height);
float4 sample = tex2Dlod(input, float4(uv.x, uv.y, 0, 0));
result[id.xy] = sample;
}
On desktop, the output is the result
texture being a copy of the input
texture. As soon as I build/deploy to Android, result
is just a blank (black) texture. I know the compute shader is getting executed because if I remove the EDIT: Turns out tex2Dlod
and replace it with a constant, I get the expected result on both platforms.tex2Dlod
wasn’t to blame. I had replaced it with float4(1,1,1,1) and that was working but other values were not. Solution below.
What am I doing wrong?!