- Home /
Issue with Compute Shader
Hey, I'm working on converting some code I have to a compute shader but am getting weird results and am not sure why. the code is supposed to create a sphere with some deformation for height but its like the shader is only running for every nth vertices. image?.
I've attached the compute shader and the script that calls it (as txt files cause that all you can upload here apparently).
I have a feeling the issue is with my lack of understanding of compute shader threads. but who knows
Answer by BastianUrbach · Nov 28, 2021 at 08:14 AM
Your code for filling the triangle buffer is flawed. Try replacing the if (i % 6 == 0)
with i *= 6;
. You want to fill an array of length (lod - 1) * (lod - 1) * 6
but right now you're only creating lod * lod
threads and every sixth thread writes six indices.
As a side note, it's not a good idea to use [numthreads(1, 1, 1)]
. GPUs process compute shaders in groups of 32 threads (Nvidia) or 64 threads (AMD). If you set the group size to (1, 1, 1) you only use one of those threads in each group. The group size should be at least 64 (e.g. (8, 8, 1) or (64, 1, 1)).
Thanks for the help, I don't know why my brain couldn't think of that. taking the logic from a loop to these GPU threads is very interesting.
Thanks for the help!