I have a compute shader that is supposed to take a float3 input, do some calculations, and output a single float value. I haven’t setup the CPU side of things yet. I am getting an error when compiling it, though:
Shader error in 'Method 2.compute': cannot implicitly convert from 'const float' to 'RWStructuredBuffer<float>' at line 23
Here’s the compute shader code:
#pragma kernel DensityFunction
float3 ws;
RWStructuredBuffer<float> density;
[numthreads(1,1,1)]
void DensityFunction(uint3 id : SV_DispatchThreadID)
{
density = -ws.y + 1.0f;
}
I have a few other questions, if anyone can answer them because the documentation on compute shaders in Unity is pretty empty. (If I should post these as different questions, let me know. I’m not sure on this site’s policies compared to Stack Exchange).
- What is causing this error.
- Is it possible to link compute shaders to vertex and pixel shaders directly without having to interface with the CPU?
- What is
[numthreads()]
exactly? I imagine that it’s how many threads the shader should use. But, why are there three values instead of just one? - How can I know how many threads would be most efficient for my shader?